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_usage ⇒ Rational?
Returns context window usage as a Rational.
-
#context_used ⇒ Integer
Returns how many tokens have been used within the context window.
- #context_window ⇒ Integer
- #cost ⇒ LLM::Cost
- #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
- #pending_functions ⇒ Array<LLM::Function>
- #pending_functions? ⇒ Boolean
- #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.
-
#token_usage ⇒ LLM::Usage
(also: #usage)
Returns usage from the mapped usage columns.
- #tracer ⇒ LLM::Tracer
-
#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_usage ⇒ Rational?
Returns context window usage as a Rational
152 153 154 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 152 def context_usage ctx.context_usage end |
#context_used ⇒ Integer
Returns how many tokens have been used within the context window
145 146 147 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 145 def context_used ctx.context_used end |
#context_window ⇒ Integer
137 138 139 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 137 def context_window ctx.context_window end |
#cost ⇒ LLM::Cost
130 131 132 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 130 def cost ctx.cost end |
#image_url ⇒ LLM::Object
183 184 185 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 183 def image_url(...) ctx.image_url(...) end |
#interrupt! ⇒ nil Also known as: cancel!
167 168 169 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 167 def interrupt! ctx.interrupt! end |
#llm ⇒ LLM::Provider
Returns the resolved provider instance for this record.
211 212 213 214 215 216 217 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 211 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
190 191 192 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 190 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
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 |
#pending_functions ⇒ Array<LLM::Function>
109 110 111 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 109 def pending_functions ctx.pending_functions end |
#pending_functions? ⇒ Boolean
116 117 118 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 116 def pending_functions? ctx.pending_functions? end |
#prompt ⇒ LLM::Prompt Also known as: build_prompt
175 176 177 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 175 def prompt(&) ctx.prompt(&) end |
#remote_file ⇒ LLM::Object
197 198 199 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 197 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 |
#token_usage ⇒ LLM::Usage Also known as: usage
Returns usage from the mapped usage columns.
159 160 161 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 159 def token_usage ctx.token_usage end |
#tracer ⇒ LLM::Tracer
204 205 206 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 204 def tracer ctx.tracer 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 |