Module: LLM::ActiveRecord::ActsAsLLM::InstanceMethods
- Defined in:
- lib/llm/active_record/acts_as_llm.rb
Instance Method Summary collapse
-
#call ⇒ Object
Calls into the stored context.
- #context_window ⇒ Integer
- #cost ⇒ LLM::Cost
- #functions ⇒ Array<LLM::Function>
- #image_url ⇒ LLM::Object
- #interrupt! ⇒ nil (also: #cancel!)
-
#llm ⇒ LLM::Provider
Returns the resolved provider instance for this record.
- #local_file ⇒ LLM::Object
- #messages ⇒ Array<LLM::Message>
- #mode ⇒ Symbol
- #model! ⇒ String
- #prompt ⇒ LLM::Prompt (also: #build_prompt)
- #remote_file ⇒ LLM::Object
-
#respond ⇒ LLM::Response
Continues the stored context through the Responses API and flushes it.
- #returns ⇒ Array<LLM::Function::Return>
-
#talk ⇒ LLM::Response
Continues the stored context with new input and flushes it.
- #tracer ⇒ LLM::Tracer
-
#usage ⇒ LLM::Object
Returns usage from the mapped usage columns.
-
#wait ⇒ Array<LLM::Function::Return>
Waits for queued tool work to finish.
Instance Method Details
#call ⇒ Object
Calls into the stored context.
171 172 173 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 171 def call(...) ctx.call(...) end |
#context_window ⇒ Integer
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 |
#cost ⇒ LLM::Cost
214 215 216 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 214 def cost ctx.cost end |
#functions ⇒ Array<LLM::Function>
200 201 202 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 200 def functions ctx.functions end |
#image_url ⇒ LLM::Object
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!
242 243 244 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 242 def interrupt! ctx.interrupt! end |
#llm ⇒ LLM::Provider
Returns the resolved provider instance for this record.
286 287 288 289 290 291 292 293 294 295 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 286 def llm = self.class. columns = Utils.columns() provider = self[columns[:provider_column]] kwargs = Utils.(self, [:provider], ActsAsLLM::EMPTY_HASH) return @llm if @llm @llm = LLM.method(provider).call(**kwargs) @llm.tracer = Utils.resolve_option(self, [:tracer]) if [:tracer] @llm end |
#local_file ⇒ LLM::Object
265 266 267 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 265 def local_file(...) ctx.local_file(...) end |
#messages ⇒ Array<LLM::Message>
185 186 187 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 185 def ctx. end |
#mode ⇒ Symbol
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.
193 194 195 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 193 def model! ctx.model end |
#prompt ⇒ LLM::Prompt Also known as: build_prompt
250 251 252 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 250 def prompt(&) ctx.prompt(&) end |
#remote_file ⇒ LLM::Object
272 273 274 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 272 def remote_file(...) ctx.remote_file(...) end |
#respond ⇒ LLM::Response
Continues the stored context through the Responses API and flushes it.
154 155 156 157 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 154 def respond(...) = self.class. ctx.respond(...).tap { Utils.save(self, ctx, ) } end |
#returns ⇒ Array<LLM::Function::Return>
207 208 209 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 207 def returns ctx.returns end |
#talk ⇒ LLM::Response
Continues the stored context with new input and flushes it.
145 146 147 148 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 145 def talk(...) = self.class. ctx.talk(...).tap { Utils.save(self, ctx, ) } end |
#tracer ⇒ LLM::Tracer
279 280 281 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 279 def tracer ctx.tracer end |
#usage ⇒ LLM::Object
Returns usage from the mapped usage columns.
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::Object.from( input_tokens: self[columns[:input_tokens]] || 0, output_tokens: self[columns[:output_tokens]] || 0, total_tokens: self[columns[:total_tokens]] || 0 ) end |
#wait ⇒ Array<LLM::Function::Return>
Waits for queued tool work to finish.
163 164 165 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 163 def wait(...) ctx.wait(...) end |