Class: Langsmith::Trace
- Inherits:
-
Object
- Object
- Langsmith::Trace
- Defined in:
- lib/langsmith/trace.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#runs ⇒ Object
readonly
Returns the value of attribute runs.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#child_runs(parent_run_id) ⇒ Array<Langsmith::Run>
Get child runs of a specific run.
-
#completed? ⇒ Boolean
Check if the trace is completed.
-
#duration ⇒ Float
Get the duration of the trace in seconds.
-
#initialize(client, trace_id) ⇒ Trace
constructor
Initialize a new Trace instance.
-
#refresh ⇒ Langsmith::Trace
Refresh the trace data from the API.
-
#root_run ⇒ Langsmith::Run
Get the root run of this trace.
-
#to_hierarchy ⇒ Hash
Get a hierarchical representation of the trace.
Constructor Details
#initialize(client, trace_id) ⇒ Trace
Initialize a new Trace instance
11 12 13 14 15 16 |
# File 'lib/langsmith/trace.rb', line 11 def initialize(client, trace_id) @client = client @id = trace_id @runs = [] refresh end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
5 6 7 |
# File 'lib/langsmith/trace.rb', line 5 def end_time @end_time end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/langsmith/trace.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/langsmith/trace.rb', line 5 def name @name end |
#runs ⇒ Object (readonly)
Returns the value of attribute runs.
5 6 7 |
# File 'lib/langsmith/trace.rb', line 5 def runs @runs end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
5 6 7 |
# File 'lib/langsmith/trace.rb', line 5 def start_time @start_time end |
Instance Method Details
#child_runs(parent_run_id) ⇒ Array<Langsmith::Run>
Get child runs of a specific run
45 46 47 |
# File 'lib/langsmith/trace.rb', line 45 def child_runs(parent_run_id) @runs.select { |run| run.parent_run_id == parent_run_id } end |
#completed? ⇒ Boolean
Check if the trace is completed
52 53 54 |
# File 'lib/langsmith/trace.rb', line 52 def completed? !@end_time.nil? end |
#duration ⇒ Float
Get the duration of the trace in seconds
59 60 61 62 |
# File 'lib/langsmith/trace.rb', line 59 def duration return nil unless @end_time && @start_time @end_time - @start_time end |
#refresh ⇒ Langsmith::Trace
Refresh the trace data from the API
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/langsmith/trace.rb', line 21 def refresh response = @client.get("/traces/#{@id}") @name = response["name"] @start_time = response["start_time"] ? Time.parse(response["start_time"]) : nil @end_time = response["end_time"] ? Time.parse(response["end_time"]) : nil # Get all runs associated with this trace runs_response = @client.get("/runs", { trace_id: @id }) @runs = runs_response.map { |run_data| Langsmith::Run.new(@client, run_data) } self end |
#root_run ⇒ Langsmith::Run
Get the root run of this trace
37 38 39 |
# File 'lib/langsmith/trace.rb', line 37 def root_run @runs.find { |run| run.parent_run_id.nil? } end |