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.
82 83 84 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 82 def call(...) ctx.call(...) end |
#context_window ⇒ Integer
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 |
#cost ⇒ LLM::Cost
125 126 127 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 125 def cost ctx.cost end |
#functions ⇒ Array<LLM::Function>
111 112 113 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 111 def functions ctx.functions end |
#image_url ⇒ LLM::Object
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!
148 149 150 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 148 def interrupt! ctx.interrupt! end |
#llm ⇒ LLM::Provider
Returns the resolved provider instance for this record.
192 193 194 195 196 197 198 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 192 def llm = self.class. return @llm if @llm @llm = Utils.resolve_provider(self, , EMPTY_HASH) @llm.tracer = Utils.resolve_option(self, [:tracer]) if [:tracer] @llm end |
#local_file ⇒ LLM::Object
171 172 173 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 171 def local_file(...) ctx.local_file(...) end |
#messages ⇒ Array<LLM::Message>
96 97 98 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 96 def ctx. end |
#mode ⇒ Symbol
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.
104 105 106 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 104 def model! ctx.model end |
#prompt ⇒ LLM::Prompt Also known as: build_prompt
156 157 158 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 156 def prompt(&) ctx.prompt(&) end |
#remote_file ⇒ LLM::Object
178 179 180 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 178 def remote_file(...) ctx.remote_file(...) end |
#respond ⇒ LLM::Response
Continues the stored context through the Responses API and flushes it.
65 66 67 68 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 65 def respond(...) = self.class. ctx.respond(...).tap { Utils.save!(self, ctx, ) } end |
#returns ⇒ Array<LLM::Function::Return>
118 119 120 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 118 def returns ctx.returns end |
#talk ⇒ LLM::Response
Continues the stored context with new input and flushes it.
56 57 58 59 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 56 def talk(...) = self.class. ctx.talk(...).tap { Utils.save!(self, ctx, ) } end |
#tracer ⇒ LLM::Tracer
185 186 187 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 185 def tracer ctx.tracer end |
#usage ⇒ LLM::Object
Returns usage from the mapped usage columns.
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 |
#wait ⇒ Array<LLM::Function::Return>
Waits for queued tool work to finish.
74 75 76 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 74 def wait(...) ctx.wait(...) end |