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_data ⇒ Object
- #output_text ⇒ Object
- #policy_audit ⇒ Object
- #policy_clean? ⇒ Boolean
- #preview ⇒ Object
- #reload ⇒ Object
- #root_turn_id ⇒ Object
- #run!(&block) ⇒ Object
- #status ⇒ 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
59 60 61 |
# File 'lib/turnkit/run.rb', line 59 def child_turn_records turn_records.select { |record| record["parent_turn_id"] == id } end |
#cost ⇒ Object
19 |
# File 'lib/turnkit/run.rb', line 19 def cost = Cost.from_records(turn_records) |
#descendant_turn_records ⇒ Object
63 64 65 |
# File 'lib/turnkit/run.rb', line 63 def descendant_turn_records turn_records.reject { |record| record.fetch("id") == id } end |
#error ⇒ Object
21 22 23 |
# File 'lib/turnkit/run.rb', line 21 def error turn.store.load_turn(id)["error"] end |
#failed_turn_records ⇒ Object
67 68 69 |
# File 'lib/turnkit/run.rb', line 67 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
25 26 27 28 29 |
# File 'lib/turnkit/run.rb', line 25 def turn_records.map { |record| record.fetch("conversation_id") }.uniq.flat_map do |conversation_id| turn.store.(conversation_id).map { |attrs| Message.new(attrs) } end end |
#output_data ⇒ Object
15 |
# File 'lib/turnkit/run.rb', line 15 def output_data = turn.output_data |
#output_text ⇒ Object
14 |
# File 'lib/turnkit/run.rb', line 14 def output_text = turn.output_text |
#policy_audit ⇒ Object
16 |
# File 'lib/turnkit/run.rb', line 16 def policy_audit = turn.policy_audit |
#policy_clean? ⇒ Boolean
17 |
# File 'lib/turnkit/run.rb', line 17 def policy_clean? = policy_audit.nil? || policy_audit.fetch("clean", false) |
#preview ⇒ Object
45 46 47 |
# File 'lib/turnkit/run.rb', line 45 def preview turn.preview end |
#reload ⇒ Object
40 41 42 43 |
# File 'lib/turnkit/run.rb', line 40 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
35 36 37 38 |
# File 'lib/turnkit/run.rb', line 35 def run!(&block) turn.run!(&block) self end |
#status ⇒ Object
13 |
# File 'lib/turnkit/run.rb', line 13 def status = turn.status |
#tool_executions ⇒ Object
49 50 51 52 53 |
# File 'lib/turnkit/run.rb', line 49 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
55 56 57 |
# File 'lib/turnkit/run.rb', line 55 def turn_records turn.store.list_turns(root_turn_id: root_turn_id) end |
#usage ⇒ Object
18 |
# File 'lib/turnkit/run.rb', line 18 def usage = Usage.from_records(turn_records) |