Module: LLM::ActiveRecord::ActsAsLLM::InstanceMethods
- Defined in:
- lib/llm/active_record/acts_as_llm.rb
Instance Method Summary collapse
- #context_window ⇒ Integer
- #cost ⇒ LLM::Cost
- #functions ⇒ Array<LLM::Function>
- #functions? ⇒ Boolean
- #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
#context_window ⇒ Integer
131 132 133 134 135 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 131 def context_window ctx.context_window rescue LLM::NoSuchModelError, LLM::NoSuchRegistryError 0 end |
#cost ⇒ LLM::Cost
124 125 126 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 124 def cost ctx.cost end |
#functions ⇒ Array<LLM::Function>
103 104 105 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 103 def functions ctx.functions end |
#functions? ⇒ Boolean
110 111 112 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 110 def functions? ctx.functions? end |
#image_url ⇒ LLM::Object
163 164 165 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 163 def image_url(...) ctx.image_url(...) end |
#interrupt! ⇒ nil Also known as: cancel!
147 148 149 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 147 def interrupt! ctx.interrupt! end |
#llm ⇒ LLM::Provider
Returns the resolved provider instance for this record.
191 192 193 194 195 196 197 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 191 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
170 171 172 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 170 def local_file(...) ctx.local_file(...) end |
#messages ⇒ Array<LLM::Message>
88 89 90 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 88 def ctx. end |
#mode ⇒ Symbol
81 82 83 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 81 def mode ctx.mode end |
#model! ⇒ String
Note:
The bang keeps the ActiveRecord and Sequel wrappers aligned.
96 97 98 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 96 def model! ctx.model end |
#prompt ⇒ LLM::Prompt Also known as: build_prompt
155 156 157 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 155 def prompt(&) ctx.prompt(&) end |
#remote_file ⇒ LLM::Object
177 178 179 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 177 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>
117 118 119 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 117 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
184 185 186 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 184 def tracer ctx.tracer end |
#usage ⇒ LLM::Object
Returns usage from the mapped usage columns.
140 141 142 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 140 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 |