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_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
62 63 64 |
# File 'lib/turnkit/run.rb', line 62 def child_turn_records turn_records.select { |record| record["parent_turn_id"] == id } end |
#cost ⇒ Object
18 |
# File 'lib/turnkit/run.rb', line 18 def cost = Cost.from_records(turn_records) |
#descendant_turn_records ⇒ Object
66 67 68 |
# File 'lib/turnkit/run.rb', line 66 def descendant_turn_records turn_records.reject { |record| record.fetch("id") == id } end |
#error ⇒ Object
23 24 25 |
# File 'lib/turnkit/run.rb', line 23 def error turn.store.load_turn(id)["error"] end |
#failed_turn_records ⇒ Object
70 71 72 |
# File 'lib/turnkit/run.rb', line 70 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
27 28 29 30 31 32 |
# File 'lib/turnkit/run.rb', line 27 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_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
21 |
# File 'lib/turnkit/run.rb', line 21 def persisted? = true |
#preview ⇒ Object
48 49 50 |
# File 'lib/turnkit/run.rb', line 48 def preview turn.preview end |
#reload ⇒ Object
43 44 45 46 |
# File 'lib/turnkit/run.rb', line 43 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
38 39 40 41 |
# File 'lib/turnkit/run.rb', line 38 def run!(&block) turn.run!(&block) self end |
#status ⇒ Object
13 |
# File 'lib/turnkit/run.rb', line 13 def status = turn.status |
#steps ⇒ Object
19 |
# File 'lib/turnkit/run.rb', line 19 def steps = turn_records.length |
#tool_calls ⇒ Object
20 |
# File 'lib/turnkit/run.rb', line 20 def tool_calls = tool_executions |
#tool_executions ⇒ Object
52 53 54 55 56 |
# File 'lib/turnkit/run.rb', line 52 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
58 59 60 |
# File 'lib/turnkit/run.rb', line 58 def turn_records turn.store.list_turns(root_turn_id: root_turn_id) end |
#usage ⇒ Object
17 |
# File 'lib/turnkit/run.rb', line 17 def usage = Usage.from_records(turn_records) |