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.
160 161 162 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 160 def call(...) ctx.call(...) end |
#context_window ⇒ Integer
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 |
#cost ⇒ LLM::Cost
203 204 205 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 203 def cost ctx.cost end |
#functions ⇒ Array<LLM::Function>
189 190 191 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 189 def functions ctx.functions end |
#image_url ⇒ LLM::Object
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!
226 227 228 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 226 def interrupt! ctx.interrupt! end |
#llm ⇒ LLM::Provider
Returns the resolved provider instance for this record.
270 271 272 273 274 275 276 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 270 def llm = self.class. return @llm if @llm @llm = Utils.resolve_provider(self, , ActsAsLLM::EMPTY_HASH) @llm.tracer = Utils.resolve_option(self, [:tracer]) if [:tracer] @llm end |
#local_file ⇒ LLM::Object
249 250 251 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 249 def local_file(...) ctx.local_file(...) end |
#messages ⇒ Array<LLM::Message>
174 175 176 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 174 def ctx. end |
#mode ⇒ Symbol
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.
182 183 184 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 182 def model! ctx.model end |
#prompt ⇒ LLM::Prompt Also known as: build_prompt
234 235 236 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 234 def prompt(&) ctx.prompt(&) end |
#remote_file ⇒ LLM::Object
256 257 258 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 256 def remote_file(...) ctx.remote_file(...) end |
#respond ⇒ LLM::Response
Continues the stored context through the Responses API and flushes it.
143 144 145 146 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 143 def respond(...) = self.class. ctx.respond(...).tap { Utils.save(self, ctx, ) } end |
#returns ⇒ Array<LLM::Function::Return>
196 197 198 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 196 def returns ctx.returns end |
#talk ⇒ LLM::Response
Continues the stored context with new input and flushes it.
134 135 136 137 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 134 def talk(...) = self.class. ctx.talk(...).tap { Utils.save(self, ctx, ) } end |
#tracer ⇒ LLM::Tracer
263 264 265 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 263 def tracer ctx.tracer end |
#usage ⇒ LLM::Object
Returns usage from the mapped usage columns.
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 |
#wait ⇒ Array<LLM::Function::Return>
Waits for queued tool work to finish.
152 153 154 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 152 def wait(...) ctx.wait(...) end |