Class: LLM::Function::Return
- Inherits:
-
Struct
- Object
- Struct
- LLM::Function::Return
- Defined in:
- lib/llm/function.rb
Overview
LLM::Function::Return represents the result of a tool call.
In llm.rb, tool execution is not complete until the requested function is answered with a return object and that return is sent back through the context. This is the object that closes that loop.
The return carries:
- the tool call ID
- the tool name
- the tool's return value
That value is usually a Hash, but it can be any JSON-like structure your
tool returns. LLM::Function#call produces one automatically, and
LLM::Function#cancel produces one that represents a cancelled tool call.
You can also construct one directly when you need to intercept, scrub, or synthesize a tool return before sending it back to the model.
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns true when the return value represents an error.
-
#to_h ⇒ Hash
Returns a Hash representation of Return.
- #to_json ⇒ String
- #interrupt! ⇒ nil (also: #cancel!)
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id
76 77 78 |
# File 'lib/llm/function.rb', line 76 def id @id end |
#name ⇒ Object
Returns the value of attribute name
76 77 78 |
# File 'lib/llm/function.rb', line 76 def name @name end |
#value ⇒ Object
Returns the value of attribute value
76 77 78 |
# File 'lib/llm/function.rb', line 76 def value @value end |
Instance Method Details
#error? ⇒ Boolean
Returns true when the return value represents an error.
80 81 82 |
# File 'lib/llm/function.rb', line 80 def error? Hash === value && value[:error] == true end |
#to_h ⇒ Hash
Returns a Hash representation of LLM::Function::Return
87 88 89 |
# File 'lib/llm/function.rb', line 87 def to_h {id:, name:, value:} end |
#to_json ⇒ String
93 94 95 |
# File 'lib/llm/function.rb', line 93 def to_json(...) LLM.json.dump(to_h, ...) end |
#interrupt! ⇒ nil Also known as: cancel!
99 100 101 |
# File 'lib/llm/function.rb', line 99 def interrupt! nil end |