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>
- #messages ⇒ Array<LLM::Message>
- #model! ⇒ String
-
#respond ⇒ LLM::Response
Continues the stored context through the Responses API and flushes it.
-
#talk ⇒ LLM::Response
Continues the stored context with new input and flushes it.
-
#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.
93 94 95 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 93 def call(...) ctx.call(...) end |
#context_window ⇒ Integer
129 130 131 132 133 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 129 def context_window ctx.context_window rescue LLM::NoSuchModelError, LLM::NoSuchRegistryError 0 end |
#cost ⇒ LLM::Cost
122 123 124 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 122 def cost ctx.cost end |
#functions ⇒ Array<LLM::Function>
115 116 117 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 115 def functions ctx.functions end |
#messages ⇒ Array<LLM::Message>
100 101 102 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 100 def ctx. end |
#model! ⇒ String
Note:
The bang keeps the ActiveRecord and Sequel wrappers aligned.
108 109 110 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 108 def model! ctx.model end |
#respond ⇒ LLM::Response
Continues the stored context through the Responses API and flushes it.
77 78 79 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 77 def respond(...) ctx.respond(...).tap { flush } end |
#talk ⇒ LLM::Response
Continues the stored context with new input and flushes it.
69 70 71 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 69 def talk(...) ctx.talk(...).tap { flush } end |
#usage ⇒ LLM::Object
Returns usage from the mapped usage columns.
138 139 140 141 142 143 144 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 138 def usage LLM::Object.from( input_tokens: self[columns[:input_tokens]] || 0, output_tokens: self[columns[:output_tokens]] || 0, total_tokens: self[columns[:total_tokens]] || 0 ) end |
#wait ⇒ Array<LLM::Function::Return>
Waits for queued tool work to finish.
85 86 87 |
# File 'lib/llm/active_record/acts_as_llm.rb', line 85 def wait(...) ctx.wait(...) end |