Class: LLM::Intercept::Multi
- Inherits:
-
LLM::Intercept
- Object
- LLM::Intercept
- LLM::Intercept::Multi
- Defined in:
- lib/llm/intercept/multi.rb
Overview
The LLM::Intercept::Multi class combines multiple intercepts into a single intercept.
The first intercept that returns an instance of
LLM::Function::Return
stops all other intercepts from running, and when
an intercept returns nil the next one in the list
is called. When all intercepts return nil, the tool
is called.
Instance Attribute Summary
Attributes inherited from LLM::Intercept
Instance Method Summary collapse
-
#initialize(llm, *intercepts) ⇒ Multi
constructor
A new instance of Multi.
-
#call(function:, **opts) ⇒ LLM::Function::Return, Object
When this method returns a LLM::Function::Return, object it stops a tool call in its tracks and the Return object is the answer we give to the model for the tool call that was stopped.
Methods inherited from LLM::Intercept
Constructor Details
#initialize(llm, *intercepts) ⇒ Multi
Returns a new instance of Multi.
23 24 25 26 |
# File 'lib/llm/intercept/multi.rb', line 23 def initialize(llm, *intercepts) @llm = llm @intercepts = intercepts end |
Instance Method Details
#call(function:, **opts) ⇒ LLM::Function::Return, Object
Returns When this method returns a LLM::Function::Return, object it stops a tool call in its tracks and the Return object is the answer we give to the model for the tool call that was stopped. Any other return value lets the tool call through.
31 32 33 34 35 36 37 38 |
# File 'lib/llm/intercept/multi.rb', line 31 def call(function:, **opts) @intercepts.each do |intercept| intercept = intercept.new(llm).tap { _1.instance_variable_set(:@context, context) } result = intercept.call(function:, **opts) return result if LLM::Function::Return === result end nil end |