Module: LLM::ActiveRecord::ActsAsLLM::InstanceMethods

Defined in:
lib/llm/active_record/acts_as_llm.rb

Instance Method Summary collapse

Instance Method Details

#context_windowInteger

Returns:

  • (Integer)

See Also:



131
132
133
134
135
# File 'lib/llm/active_record/acts_as_llm.rb', line 131

def context_window
  ctx.context_window
rescue LLM::NoSuchModelError, LLM::NoSuchRegistryError
  0
end

#costLLM::Cost

Returns:

See Also:



124
125
126
# File 'lib/llm/active_record/acts_as_llm.rb', line 124

def cost
  ctx.cost
end

#functionsArray<LLM::Function>

Returns:

See Also:



103
104
105
# File 'lib/llm/active_record/acts_as_llm.rb', line 103

def functions
  ctx.functions
end

#functions?Boolean

Returns:

  • (Boolean)

See Also:



110
111
112
# File 'lib/llm/active_record/acts_as_llm.rb', line 110

def functions?
  ctx.functions?
end

#image_urlLLM::Object

Returns:

See Also:



163
164
165
# File 'lib/llm/active_record/acts_as_llm.rb', line 163

def image_url(...)
  ctx.image_url(...)
end

#interrupt!nil Also known as: cancel!

Returns:

  • (nil)

See Also:



147
148
149
# File 'lib/llm/active_record/acts_as_llm.rb', line 147

def interrupt!
  ctx.interrupt!
end

#llmLLM::Provider

Returns the resolved provider instance for this record.

Returns:



191
192
193
194
195
196
197
# File 'lib/llm/active_record/acts_as_llm.rb', line 191

def llm
  options = self.class.llm_plugin_options
  return @llm if @llm
  @llm = Utils.resolve_provider(self, options, EMPTY_HASH)
  @llm.tracer = Utils.resolve_option(self, options[:tracer]) if options[:tracer]
  @llm
end

#local_fileLLM::Object

Returns:

See Also:



170
171
172
# File 'lib/llm/active_record/acts_as_llm.rb', line 170

def local_file(...)
  ctx.local_file(...)
end

#messagesArray<LLM::Message>

Returns:

See Also:



88
89
90
# File 'lib/llm/active_record/acts_as_llm.rb', line 88

def messages
  ctx.messages
end

#modeSymbol

Returns:

  • (Symbol)

See Also:



81
82
83
# File 'lib/llm/active_record/acts_as_llm.rb', line 81

def mode
  ctx.mode
end

#model!String

Note:

The bang keeps the ActiveRecord and Sequel wrappers aligned.

Returns:

  • (String)

See Also:



96
97
98
# File 'lib/llm/active_record/acts_as_llm.rb', line 96

def model!
  ctx.model
end

#promptLLM::Prompt Also known as: build_prompt

Returns:

See Also:



155
156
157
# File 'lib/llm/active_record/acts_as_llm.rb', line 155

def prompt(&)
  ctx.prompt(&)
end

#remote_fileLLM::Object

Returns:

See Also:



177
178
179
# File 'lib/llm/active_record/acts_as_llm.rb', line 177

def remote_file(...)
  ctx.remote_file(...)
end

#respondLLM::Response

Continues the stored context through the Responses API and flushes it.

Returns:

See Also:



65
66
67
68
# File 'lib/llm/active_record/acts_as_llm.rb', line 65

def respond(...)
  options = self.class.llm_plugin_options
  ctx.respond(...).tap { Utils.save!(self, ctx, options) }
end

#returnsArray<LLM::Function::Return>

Returns:

See Also:



117
118
119
# File 'lib/llm/active_record/acts_as_llm.rb', line 117

def returns
  ctx.returns
end

#talkLLM::Response

Continues the stored context with new input and flushes it.

Returns:

See Also:



56
57
58
59
# File 'lib/llm/active_record/acts_as_llm.rb', line 56

def talk(...)
  options = self.class.llm_plugin_options
  ctx.talk(...).tap { Utils.save!(self, ctx, options) }
end

#tracerLLM::Tracer

Returns:

See Also:



184
185
186
# File 'lib/llm/active_record/acts_as_llm.rb', line 184

def tracer
  ctx.tracer
end

#usageLLM::Object

Returns usage from the mapped usage columns.

Returns:



140
141
142
# File 'lib/llm/active_record/acts_as_llm.rb', line 140

def usage
  ctx.usage || LLM::Object.from(input_tokens: 0, output_tokens: 0, total_tokens: 0)
end

#waitArray<LLM::Function::Return>

Waits for queued tool work to finish.

Returns:

See Also:



74
75
76
# File 'lib/llm/active_record/acts_as_llm.rb', line 74

def wait(...)
  ctx.wait(...)
end