Class: TranscriptViewer::ToolExecution
- Inherits:
-
Object
- Object
- TranscriptViewer::ToolExecution
- Defined in:
- lib/transcript_viewer/tool_execution.rb
Instance Attribute Summary collapse
-
#call ⇒ Object
readonly
Returns the value of attribute call.
-
#result_entry ⇒ Object
readonly
Returns the value of attribute result_entry.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #id ⇒ Object
- #images ⇒ Object
-
#initialize(call:, result_entry: nil) ⇒ ToolExecution
constructor
A new instance of ToolExecution.
- #input ⇒ Object (also: #arguments)
- #name ⇒ Object
- #pending? ⇒ Boolean
- #result ⇒ Object
- #result_content ⇒ Object
- #result_json ⇒ Object
- #result_text ⇒ Object
- #status ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(call:, result_entry: nil) ⇒ ToolExecution
Returns a new instance of ToolExecution.
9 10 11 12 |
# File 'lib/transcript_viewer/tool_execution.rb', line 9 def initialize(call:, result_entry: nil) @call = call @result_entry = result_entry end |
Instance Attribute Details
#call ⇒ Object (readonly)
Returns the value of attribute call.
7 8 9 |
# File 'lib/transcript_viewer/tool_execution.rb', line 7 def call @call end |
#result_entry ⇒ Object (readonly)
Returns the value of attribute result_entry.
7 8 9 |
# File 'lib/transcript_viewer/tool_execution.rb', line 7 def result_entry @result_entry end |
Instance Method Details
#error? ⇒ Boolean
53 54 55 |
# File 'lib/transcript_viewer/tool_execution.rb', line 53 def error? !pending? && !!result&.dig(:isError) end |
#id ⇒ Object
14 15 16 |
# File 'lib/transcript_viewer/tool_execution.rb', line 14 def id call[:id] end |
#images ⇒ Object
45 46 47 |
# File 'lib/transcript_viewer/tool_execution.rb', line 45 def images result_content.select { |block| block[:type] == "image" && present_value?(block[:data]) } end |
#input ⇒ Object Also known as: arguments
22 23 24 |
# File 'lib/transcript_viewer/tool_execution.rb', line 22 def input call[:arguments] || {} end |
#name ⇒ Object
18 19 20 |
# File 'lib/transcript_viewer/tool_execution.rb', line 18 def name call[:name].to_s end |
#pending? ⇒ Boolean
49 50 51 |
# File 'lib/transcript_viewer/tool_execution.rb', line 49 def pending? result_entry.nil? end |
#result ⇒ Object
27 28 29 |
# File 'lib/transcript_viewer/tool_execution.rb', line 27 def result result_entry&.dig(:message) end |
#result_content ⇒ Object
31 32 33 |
# File 'lib/transcript_viewer/tool_execution.rb', line 31 def result_content Array(result&.dig(:content)) end |
#result_json ⇒ Object
39 40 41 42 43 |
# File 'lib/transcript_viewer/tool_execution.rb', line 39 def result_json JSON.parse(result_text) rescue JSON::ParserError nil end |
#result_text ⇒ Object
35 36 37 |
# File 'lib/transcript_viewer/tool_execution.rb', line 35 def result_text result_content.filter_map { |block| block[:text] if block[:type] == "text" }.join("\n") end |
#status ⇒ Object
61 62 63 64 65 66 |
# File 'lib/transcript_viewer/tool_execution.rb', line 61 def status return :pending if pending? return :error if error? :success end |
#success? ⇒ Boolean
57 58 59 |
# File 'lib/transcript_viewer/tool_execution.rb', line 57 def success? !pending? && !error? end |