Class: Langsmith::Run
- Inherits:
-
Object
- Object
- Langsmith::Run
- Defined in:
- lib/langsmith/run.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
-
#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_type ⇒ Object
readonly
Returns the value of attribute run_type.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
Instance Method Summary collapse
-
#add_feedback(key:, score:, comment: nil) ⇒ Langsmith::Feedback
Add feedback to this run.
-
#completed? ⇒ Boolean
Check if the run is completed.
-
#create_child_run(name:, run_type:, inputs: {}, extra: {}) ⇒ Langsmith::Run
Create a child run for this run.
-
#duration ⇒ Float
Get the duration of the run in seconds.
-
#end(outputs: nil, error: nil) ⇒ Langsmith::Run
Update the run with outputs and mark it as completed.
-
#error? ⇒ Boolean
Check if the run has an error.
-
#get_feedback ⇒ Array<Langsmith::Feedback>
Get all feedback for this run.
-
#get_metadata(key) ⇒ Object
Get metadata from the run.
-
#initialize(client, data) ⇒ Run
constructor
Initialize a new Run instance.
Constructor Details
#initialize(client, data) ⇒ Run
Initialize a new Run instance
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/langsmith/run.rb', line 14 def initialize(client, data) @client = client @id = data["id"] @name = data["name"] @run_type = data["run_type"] @start_time = data["start_time"] ? Time.parse(data["start_time"]) : Time.now @end_time = data["end_time"] ? Time.parse(data["end_time"]) : nil @status = data["status"] || "in_progress" @inputs = data["inputs"] || {} @outputs = data["outputs"] || {} @error = data["error"] @project_name = data["project_name"] @trace_id = data["trace_id"] @parent_run_id = data["parent_run_id"] @extra = data["extra"] || {} end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
7 8 9 |
# File 'lib/langsmith/run.rb', line 7 def end_time @end_time end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
8 9 10 |
# File 'lib/langsmith/run.rb', line 8 def error @error end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/langsmith/run.rb', line 7 def id @id end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
8 9 10 |
# File 'lib/langsmith/run.rb', line 8 def inputs @inputs end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/langsmith/run.rb', line 7 def name @name end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
8 9 10 |
# File 'lib/langsmith/run.rb', line 8 def outputs @outputs end |
#parent_run_id ⇒ Object (readonly)
Returns the value of attribute parent_run_id.
8 9 10 |
# File 'lib/langsmith/run.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/langsmith/run.rb', line 8 def project_name @project_name end |
#run_type ⇒ Object (readonly)
Returns the value of attribute run_type.
7 8 9 |
# File 'lib/langsmith/run.rb', line 7 def run_type @run_type end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/langsmith/run.rb', line 7 def start_time @start_time end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
7 8 9 |
# File 'lib/langsmith/run.rb', line 7 def status @status end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
8 9 10 |
# File 'lib/langsmith/run.rb', line 8 def trace_id @trace_id end |
Instance Method Details
#add_feedback(key:, score:, comment: nil) ⇒ Langsmith::Feedback
Add feedback to this run
73 74 75 |
# File 'lib/langsmith/run.rb', line 73 def add_feedback(key:, score:, comment: nil) @client.create_feedback(run_id: @id, key: key, score: score, comment: comment) end |
#completed? ⇒ Boolean
Check if the run is completed
95 96 97 |
# File 'lib/langsmith/run.rb', line 95 def completed? !@end_time.nil? end |
#create_child_run(name:, run_type:, inputs: {}, extra: {}) ⇒ Langsmith::Run
Create a child run for this run
52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/langsmith/run.rb', line 52 def create_child_run(name:, run_type:, inputs: {}, extra: {}) child_extra = extra.merge(parent_run_id: @id, trace_id: @trace_id) data = { name: name, run_type: run_type, inputs: inputs, extra: child_extra } data[:project_name] = @project_name if @project_name response = @client.post("/runs", data) Langsmith::Run.new(@client, response) end |
#duration ⇒ Float
Get the duration of the run in seconds
109 110 111 112 |
# File 'lib/langsmith/run.rb', line 109 def duration return nil unless @end_time @end_time - @start_time end |
#end(outputs: nil, error: nil) ⇒ Langsmith::Run
Update the run with outputs and mark it as completed
35 36 37 38 39 40 41 42 43 |
# File 'lib/langsmith/run.rb', line 35 def end(outputs: nil, error: nil) end_time = Time.now if error @client.update_run(run_id: @id, end_time: end_time, error: error) else @client.update_run(run_id: @id, outputs: outputs, end_time: end_time) end end |
#error? ⇒ Boolean
Check if the run has an error
102 103 104 |
# File 'lib/langsmith/run.rb', line 102 def error? !@error.nil? end |
#get_feedback ⇒ Array<Langsmith::Feedback>
Get all feedback for this run
80 81 82 |
# File 'lib/langsmith/run.rb', line 80 def get_feedback @client.get_feedback(run_id: @id) end |
#get_metadata(key) ⇒ Object
Get metadata from the run
88 89 90 |
# File 'lib/langsmith/run.rb', line 88 def (key) @extra[key] end |