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:



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

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

#context_windowInteger

Returns:

  • (Integer)

See Also:



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

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

#costLLM::Cost

Returns:

See Also:



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

def cost
  ctx.cost
end

#functionsArray<LLM::Function>

Returns:

See Also:



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

def functions
  ctx.functions
end

#image_urlLLM::Object

Returns:

See Also:



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

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

#interrupt!nil Also known as: cancel!

Returns:

  • (nil)

See Also:



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

def interrupt!
  ctx.interrupt!
end

#llmLLM::Provider

Returns the resolved provider instance for this record.

Returns:



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

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:



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

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

#messagesArray<LLM::Message>

Returns:

See Also:



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

def messages
  ctx.messages
end

#modeSymbol

Returns:

  • (Symbol)

See Also:



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

def mode
  ctx.mode
end

#model!String

Note:

The bang keeps the ActiveRecord and Sequel wrappers aligned.

Returns:

  • (String)

See Also:



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

def model!
  ctx.model
end

#promptLLM::Prompt Also known as: build_prompt

Returns:

See Also:



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

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

#remote_fileLLM::Object

Returns:

See Also:



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

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:



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

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:



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

def tracer
  ctx.tracer
end

#usageLLM::Object

Returns usage from the mapped usage columns.

Returns:



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

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