Module: LLM::ActiveRecord::ActsAsLLM::InstanceMethods
- Defined in:
- lib/llm/active_record/acts_as_llm.rb
Instance Method Summary collapse
-
#ask ⇒ LLM::Response
Continues the stored context with new input and flushes it.
- #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
- #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
#ask ⇒ LLM::Response
Continues the stored context with new input and flushes it.
71 72 73 74 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 71 def ask(...) = self.class. ctx.ask(...).tap { Utils.save!(self, ctx, ) } end |
#context_window ⇒ Integer
137 138 139 140 141 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 137 def context_window ctx.context_window rescue LLM::NoSuchModelError, LLM::NoSuchRegistryError 0 end |
#cost ⇒ LLM::Cost
130 131 132 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 130 def cost ctx.cost end |
#functions ⇒ Array<LLM::Function>
109 110 111 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 109 def functions ctx.functions end |
#functions? ⇒ Boolean
116 117 118 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 116 def functions? ctx.functions? end |
#image_url ⇒ LLM::Object
169 170 171 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 169 def image_url(...) ctx.image_url(...) end |
#interrupt! ⇒ nil Also known as: cancel!
153 154 155 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 153 def interrupt! ctx.interrupt! end |
#llm ⇒ LLM::Provider
Returns the resolved provider instance for this record.
197 198 199 200 201 202 203 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 197 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
176 177 178 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 176 def local_file(...) ctx.local_file(...) end |
#messages ⇒ Array<LLM::Message>
94 95 96 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 94 def ctx. end |
#mode ⇒ Symbol
87 88 89 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 87 def mode ctx.mode end |
#model! ⇒ String
Note:
The bang keeps the ActiveRecord and Sequel wrappers aligned.
102 103 104 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 102 def model! ctx.model end |
#prompt ⇒ LLM::Prompt Also known as: build_prompt
161 162 163 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 161 def prompt(&) ctx.prompt(&) end |
#remote_file ⇒ LLM::Object
183 184 185 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 183 def remote_file(...) ctx.remote_file(...) end |
#returns ⇒ Array<LLM::Function::Return>
123 124 125 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 123 def returns ctx.returns end |
#talk ⇒ LLM::Response
Continues the stored context with new input and flushes it.
62 63 64 65 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 62 def talk(...) = self.class. ctx.talk(...).tap { Utils.save!(self, ctx, ) } end |
#tracer ⇒ LLM::Tracer
190 191 192 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 190 def tracer ctx.tracer end |
#usage ⇒ LLM::Object
Returns usage from the mapped usage columns.
146 147 148 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 146 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.
80 81 82 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 80 def wait(...) ctx.wait(...) end |