Class: TurnKit::Run
- Inherits:
-
Object
- Object
- TurnKit::Run
- Defined in:
- lib/turnkit/run.rb
Instance Attribute Summary collapse
-
#turn ⇒ Object
readonly
Returns the value of attribute turn.
Instance Method Summary collapse
- #child_turn_records ⇒ Object
- #cost ⇒ Object
- #descendant_turn_records ⇒ Object
- #error ⇒ Object
- #failed_turn_records ⇒ Object
- #id ⇒ Object
-
#initialize(turn) ⇒ Run
constructor
A new instance of Run.
- #messages ⇒ Object
- #output ⇒ Object
- #output_audit ⇒ Object
- #output_audit_clean? ⇒ Boolean
- #output_data ⇒ Object
- #output_text ⇒ Object
- #persisted? ⇒ Boolean
- #preview ⇒ Object
- #reload ⇒ Object
- #root_turn_id ⇒ Object
- #run!(&block) ⇒ Object
- #status ⇒ Object
- #steps ⇒ Object
- #tool_calls ⇒ Object
- #tool_executions ⇒ Object
- #turn_records ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(turn) ⇒ Run
Returns a new instance of Run.
7 8 9 |
# File 'lib/turnkit/run.rb', line 7 def initialize(turn) @turn = turn end |
Instance Attribute Details
#turn ⇒ Object (readonly)
Returns the value of attribute turn.
5 6 7 |
# File 'lib/turnkit/run.rb', line 5 def turn @turn end |
Instance Method Details
#child_turn_records ⇒ Object
64 65 66 |
# File 'lib/turnkit/run.rb', line 64 def child_turn_records turn_records.select { |record| record["parent_turn_id"] == id } end |
#cost ⇒ Object
20 |
# File 'lib/turnkit/run.rb', line 20 def cost = Cost.from_records(turn_records) |
#descendant_turn_records ⇒ Object
68 69 70 |
# File 'lib/turnkit/run.rb', line 68 def descendant_turn_records turn_records.reject { |record| record.fetch("id") == id } end |
#error ⇒ Object
25 26 27 |
# File 'lib/turnkit/run.rb', line 25 def error turn.store.load_turn(id)["error"] end |
#failed_turn_records ⇒ Object
72 73 74 |
# File 'lib/turnkit/run.rb', line 72 def failed_turn_records turn_records.select { |record| record["status"] == "failed" } end |
#id ⇒ Object
11 |
# File 'lib/turnkit/run.rb', line 11 def id = turn.id |
#messages ⇒ Object
29 30 31 32 33 34 |
# File 'lib/turnkit/run.rb', line 29 def turn_records.flat_map do |record| conversation = turn.store.load_conversation(record.fetch("conversation_id")) turn.store.(conversation.fetch("id")) end end |
#output ⇒ Object
14 |
# File 'lib/turnkit/run.rb', line 14 def output = output_text |
#output_audit ⇒ Object
17 |
# File 'lib/turnkit/run.rb', line 17 def output_audit = turn.output_audit |
#output_audit_clean? ⇒ Boolean
18 |
# File 'lib/turnkit/run.rb', line 18 def output_audit_clean? = output_audit.nil? || output_audit.fetch("clean", false) |
#output_data ⇒ Object
16 |
# File 'lib/turnkit/run.rb', line 16 def output_data = turn.output_data |
#output_text ⇒ Object
15 |
# File 'lib/turnkit/run.rb', line 15 def output_text = turn.output_text |
#persisted? ⇒ Boolean
23 |
# File 'lib/turnkit/run.rb', line 23 def persisted? = true |
#preview ⇒ Object
50 51 52 |
# File 'lib/turnkit/run.rb', line 50 def preview turn.preview end |
#reload ⇒ Object
45 46 47 48 |
# File 'lib/turnkit/run.rb', line 45 def reload turn.reload self end |
#root_turn_id ⇒ Object
12 |
# File 'lib/turnkit/run.rb', line 12 def root_turn_id = turn.root_turn_id |
#run!(&block) ⇒ Object
40 41 42 43 |
# File 'lib/turnkit/run.rb', line 40 def run!(&block) turn.run!(&block) self end |
#status ⇒ Object
13 |
# File 'lib/turnkit/run.rb', line 13 def status = turn.status |
#steps ⇒ Object
21 |
# File 'lib/turnkit/run.rb', line 21 def steps = turn_records.length |
#tool_calls ⇒ Object
22 |
# File 'lib/turnkit/run.rb', line 22 def tool_calls = tool_executions |
#tool_executions ⇒ Object
54 55 56 57 58 |
# File 'lib/turnkit/run.rb', line 54 def tool_executions turn_records.flat_map do |record| turn.store.list_tool_executions(turn_id: record.fetch("id")).map { |attrs| ToolExecution.new(attrs) } end end |
#turn_records ⇒ Object
60 61 62 |
# File 'lib/turnkit/run.rb', line 60 def turn_records turn.store.list_turns(root_turn_id: root_turn_id) end |
#usage ⇒ Object
19 |
# File 'lib/turnkit/run.rb', line 19 def usage = Usage.from_records(turn_records) |