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

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

Instance Method Summary collapse

Instance Method Details

#callObject

Calls into the stored context.

Returns:

See Also:



160
161
162
# File 'lib/llm/active_record/acts_as_llm.rb', line 160

def call(...)
  ctx.call(...)
end

#context_windowInteger

Returns:

  • (Integer)

See Also:



210
211
212
213
214
# File 'lib/llm/active_record/acts_as_llm.rb', line 210

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

#costLLM::Cost

Returns:

See Also:



203
204
205
# File 'lib/llm/active_record/acts_as_llm.rb', line 203

def cost
  ctx.cost
end

#functionsArray<LLM::Function>

Returns:

See Also:



189
190
191
# File 'lib/llm/active_record/acts_as_llm.rb', line 189

def functions
  ctx.functions
end

#image_urlLLM::Object

Returns:

See Also:



242
243
244
# File 'lib/llm/active_record/acts_as_llm.rb', line 242

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

#interrupt!nil Also known as: cancel!

Returns:

  • (nil)

See Also:



226
227
228
# File 'lib/llm/active_record/acts_as_llm.rb', line 226

def interrupt!
  ctx.interrupt!
end

#llmLLM::Provider

Returns the resolved provider instance for this record.

Returns:



270
271
272
273
274
275
276
# File 'lib/llm/active_record/acts_as_llm.rb', line 270

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

#local_fileLLM::Object

Returns:

See Also:



249
250
251
# File 'lib/llm/active_record/acts_as_llm.rb', line 249

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

#messagesArray<LLM::Message>

Returns:

See Also:



174
175
176
# File 'lib/llm/active_record/acts_as_llm.rb', line 174

def messages
  ctx.messages
end

#modeSymbol

Returns:

  • (Symbol)

See Also:



167
168
169
# File 'lib/llm/active_record/acts_as_llm.rb', line 167

def mode
  ctx.mode
end

#model!String

Note:

The bang keeps the ActiveRecord and Sequel wrappers aligned.

Returns:

  • (String)

See Also:



182
183
184
# File 'lib/llm/active_record/acts_as_llm.rb', line 182

def model!
  ctx.model
end

#promptLLM::Prompt Also known as: build_prompt

Returns:

See Also:



234
235
236
# File 'lib/llm/active_record/acts_as_llm.rb', line 234

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

#remote_fileLLM::Object

Returns:

See Also:



256
257
258
# File 'lib/llm/active_record/acts_as_llm.rb', line 256

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

#respondLLM::Response

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

Returns:

See Also:



143
144
145
146
# File 'lib/llm/active_record/acts_as_llm.rb', line 143

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

#returnsArray<LLM::Function::Return>

Returns:

See Also:



196
197
198
# File 'lib/llm/active_record/acts_as_llm.rb', line 196

def returns
  ctx.returns
end

#talkLLM::Response

Continues the stored context with new input and flushes it.

Returns:

See Also:



134
135
136
137
# File 'lib/llm/active_record/acts_as_llm.rb', line 134

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

#tracerLLM::Tracer

Returns:

See Also:



263
264
265
# File 'lib/llm/active_record/acts_as_llm.rb', line 263

def tracer
  ctx.tracer
end

#usageLLM::Object

Returns usage from the mapped usage columns.

Returns:



219
220
221
# File 'lib/llm/active_record/acts_as_llm.rb', line 219

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:



152
153
154
# File 'lib/llm/active_record/acts_as_llm.rb', line 152

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