Class: TurnKit::Result
- Inherits:
-
Object
- Object
- TurnKit::Result
- Defined in:
- lib/turnkit/result.rb
Instance Attribute Summary collapse
-
#finish_reason ⇒ Object
readonly
Returns the value of attribute finish_reason.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#output_data ⇒ Object
readonly
Returns the value of attribute output_data.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Instance Method Summary collapse
-
#initialize(text: "", tool_calls: [], parts: nil, usage: Usage.new, model: nil, finish_reason: nil, output_data: nil) ⇒ Result
constructor
A new instance of Result.
- #text ⇒ Object
- #tool_calls ⇒ Object
- #tool_calls? ⇒ Boolean
Constructor Details
#initialize(text: "", tool_calls: [], parts: nil, usage: Usage.new, model: nil, finish_reason: nil, output_data: nil) ⇒ Result
Returns a new instance of Result.
7 8 9 10 11 12 13 |
# File 'lib/turnkit/result.rb', line 7 def initialize(text: "", tool_calls: [], parts: nil, usage: Usage.new, model: nil, finish_reason: nil, output_data: nil) @parts = parts ? normalize_parts(parts) : synthesize_parts(text: text, tool_calls: tool_calls) @usage = usage || Usage.new @model = model @finish_reason = finish_reason @output_data = output_data end |
Instance Attribute Details
#finish_reason ⇒ Object (readonly)
Returns the value of attribute finish_reason.
5 6 7 |
# File 'lib/turnkit/result.rb', line 5 def finish_reason @finish_reason end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/turnkit/result.rb', line 5 def model @model end |
#output_data ⇒ Object (readonly)
Returns the value of attribute output_data.
5 6 7 |
# File 'lib/turnkit/result.rb', line 5 def output_data @output_data end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
5 6 7 |
# File 'lib/turnkit/result.rb', line 5 def parts @parts end |
#usage ⇒ Object (readonly)
Returns the value of attribute usage.
5 6 7 |
# File 'lib/turnkit/result.rb', line 5 def usage @usage end |
Instance Method Details
#text ⇒ Object
15 16 17 |
# File 'lib/turnkit/result.rb', line 15 def text parts.filter_map { |part| part["text"] if part["type"] == "text" }.join("\n") end |
#tool_calls ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/turnkit/result.rb', line 19 def tool_calls parts.filter_map do |part| next unless part["type"] == "tool_call" ToolCall.new(id: part.fetch("id"), name: part.fetch("name"), arguments: part["arguments"] || {}, arguments_error: part["arguments_error"]) end end |
#tool_calls? ⇒ Boolean
27 28 29 |
# File 'lib/turnkit/result.rb', line 27 def tool_calls? tool_calls.any? end |