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:



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

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

#context_windowInteger

Returns:

  • (Integer)

See Also:



221
222
223
224
225
# File 'lib/llm/active_record/acts_as_llm.rb', line 221

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

#costLLM::Cost

Returns:

See Also:



214
215
216
# File 'lib/llm/active_record/acts_as_llm.rb', line 214

def cost
  ctx.cost
end

#functionsArray<LLM::Function>

Returns:

See Also:



200
201
202
# File 'lib/llm/active_record/acts_as_llm.rb', line 200

def functions
  ctx.functions
end

#image_urlLLM::Object

Returns:

See Also:



258
259
260
# File 'lib/llm/active_record/acts_as_llm.rb', line 258

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

#interrupt!nil Also known as: cancel!

Returns:

  • (nil)

See Also:



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

def interrupt!
  ctx.interrupt!
end

#llmLLM::Provider

Returns the resolved provider instance for this record.

Returns:



286
287
288
289
290
291
292
293
294
295
# File 'lib/llm/active_record/acts_as_llm.rb', line 286

def llm
  options = self.class.llm_plugin_options
  columns = Utils.columns(options)
  provider = self[columns[:provider_column]]
  kwargs = Utils.resolve_options(self, options[:provider], ActsAsLLM::EMPTY_HASH)
  return @llm if @llm
  @llm = LLM.method(provider).call(**kwargs)
  @llm.tracer = Utils.resolve_option(self, options[:tracer]) if options[:tracer]
  @llm
end

#local_fileLLM::Object

Returns:

See Also:



265
266
267
# File 'lib/llm/active_record/acts_as_llm.rb', line 265

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

#messagesArray<LLM::Message>

Returns:

See Also:



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

def messages
  ctx.messages
end

#modeSymbol

Returns:

  • (Symbol)

See Also:



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

def mode
  ctx.mode
end

#model!String

Note:

The bang keeps the ActiveRecord and Sequel wrappers aligned.

Returns:

  • (String)

See Also:



193
194
195
# File 'lib/llm/active_record/acts_as_llm.rb', line 193

def model!
  ctx.model
end

#promptLLM::Prompt Also known as: build_prompt

Returns:

See Also:



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

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

#remote_fileLLM::Object

Returns:

See Also:



272
273
274
# File 'lib/llm/active_record/acts_as_llm.rb', line 272

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

#respondLLM::Response

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

Returns:

See Also:



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

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

#returnsArray<LLM::Function::Return>

Returns:

See Also:



207
208
209
# File 'lib/llm/active_record/acts_as_llm.rb', line 207

def returns
  ctx.returns
end

#talkLLM::Response

Continues the stored context with new input and flushes it.

Returns:

See Also:



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

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

#tracerLLM::Tracer

Returns:

See Also:



279
280
281
# File 'lib/llm/active_record/acts_as_llm.rb', line 279

def tracer
  ctx.tracer
end

#usageLLM::Object

Returns usage from the mapped usage columns.

Returns:



230
231
232
233
234
235
236
237
# File 'lib/llm/active_record/acts_as_llm.rb', line 230

def usage
  columns = Utils.columns(self.class.llm_plugin_options)
  LLM::Object.from(
    input_tokens: self[columns[:input_tokens]] || 0,
    output_tokens: self[columns[:output_tokens]] || 0,
    total_tokens: self[columns[:total_tokens]] || 0
  )
end

#waitArray<LLM::Function::Return>

Waits for queued tool work to finish.

Returns:

See Also:



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

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