Class: LangsmithrbRails::RunTree
- Inherits:
-
Object
- Object
- LangsmithrbRails::RunTree
- Defined in:
- lib/langsmithrb_rails/run_trees.rb
Overview
Run trees for hierarchical tracing
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent_run_id ⇒ Object
readonly
Returns the value of attribute parent_run_id.
-
#project_name ⇒ Object
readonly
Returns the value of attribute project_name.
-
#run_id ⇒ Object
readonly
Returns the value of attribute run_id.
-
#run_type ⇒ Object
readonly
Returns the value of attribute run_type.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#tags ⇒ Object
readonly
Returns the value of attribute tags.
Instance Method Summary collapse
-
#create_child(name:, run_type:, inputs:, tags: []) ⇒ RunTree
Create a child run.
-
#end(outputs: {}, error: nil) ⇒ Object
End the run with outputs.
-
#ended? ⇒ Boolean
Check if the run has ended.
-
#initialize(name:, run_type:, inputs:, run_id: nil, parent_run_id: nil, project_name: nil, tags: []) ⇒ RunTree
constructor
Initialize a new run tree.
Constructor Details
#initialize(name:, run_type:, inputs:, run_id: nil, parent_run_id: nil, project_name: nil, tags: []) ⇒ RunTree
Initialize a new run tree
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 18 def initialize(name:, run_type:, inputs:, run_id: nil, parent_run_id: nil, project_name: nil, tags: []) @run_id = run_id || SecureRandom.uuid @name = name @run_type = run_type @inputs = inputs @parent_run_id = parent_run_id @start_time = Time.now.utc @children = [] @project_name = project_name @tags = @client = LangsmithrbRails::Client.new @ended = false # Create the run in LangSmith create_run end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def children @children end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def inputs @inputs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def name @name end |
#parent_run_id ⇒ Object (readonly)
Returns the value of attribute parent_run_id.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def parent_run_id @parent_run_id end |
#project_name ⇒ Object (readonly)
Returns the value of attribute project_name.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def project_name @project_name end |
#run_id ⇒ Object (readonly)
Returns the value of attribute run_id.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def run_id @run_id end |
#run_type ⇒ Object (readonly)
Returns the value of attribute run_type.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def run_type @run_type end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def start_time @start_time end |
#tags ⇒ Object (readonly)
Returns the value of attribute tags.
8 9 10 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 8 def @tags end |
Instance Method Details
#create_child(name:, run_type:, inputs:, tags: []) ⇒ RunTree
Create a child run
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 41 def create_child(name:, run_type:, inputs:, tags: []) child_run_id = SecureRandom.uuid child_run = RunTree.new( run_id: child_run_id, parent_run_id: @run_id, name: name, run_type: run_type, inputs: inputs, project_name: @project_name, tags: ) @children << child_run child_run end |
#end(outputs: {}, error: nil) ⇒ Object
End the run with outputs
61 62 63 64 65 66 67 68 69 70 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 61 def end(outputs: {}, error: nil) return if @ended # End all children first @children.each { |child| child.end unless child.ended? } # Update the run in LangSmith update_run(outputs, error) @ended = true end |
#ended? ⇒ Boolean
Check if the run has ended
74 75 76 |
# File 'lib/langsmithrb_rails/run_trees.rb', line 74 def ended? @ended end |