Class: Langsmith::Dataset
- Inherits:
-
Object
- Object
- Langsmith::Dataset
- Defined in:
- lib/langsmith/dataset.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tenant_id ⇒ Object
readonly
Returns the value of attribute tenant_id.
Instance Method Summary collapse
-
#create_evaluation_run(evaluator_name:, run_ids:, metadata: nil) ⇒ Langsmith::Evaluation
Create a new evaluation run on this dataset.
-
#create_example(inputs:, outputs: nil, metadata: nil) ⇒ Langsmith::Example
Create a new example in this dataset.
-
#create_examples_batch(examples:) ⇒ Array<Example>
Create multiple examples in batch.
-
#delete ⇒ Boolean
Delete this dataset.
-
#get_example(example_id:) ⇒ Langsmith::Example
Get a specific example by ID.
-
#initialize(client, data) ⇒ Dataset
constructor
Initialize a new Dataset instance.
-
#list_evaluation_runs(limit: 100, offset: 0) ⇒ Array<Langsmith::Evaluation>
List evaluation runs for this dataset.
-
#list_examples(limit: 100, offset: 0) ⇒ Array<Langsmith::Example>
List examples in this dataset.
-
#update(name: nil, description: nil) ⇒ Langsmith::Dataset
Update this dataset.
Constructor Details
#initialize(client, data) ⇒ Dataset
Initialize a new Dataset instance
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/langsmith/dataset.rb', line 13 def initialize(client, data) @client = client @id = data[:id] || data["id"] @name = data[:name] || data["name"] @description = data[:description] || data["description"] created_at_value = data[:created_at] || data["created_at"] @created_at = created_at_value ? Time.parse(created_at_value) : nil @tenant_id = data[:tenant_id] || data["tenant_id"] @data = data end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/langsmith/dataset.rb', line 7 def created_at @created_at end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/langsmith/dataset.rb', line 7 def data @data end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/langsmith/dataset.rb', line 7 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/langsmith/dataset.rb', line 7 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/langsmith/dataset.rb', line 7 def name @name end |
#tenant_id ⇒ Object (readonly)
Returns the value of attribute tenant_id.
7 8 9 |
# File 'lib/langsmith/dataset.rb', line 7 def tenant_id @tenant_id end |
Instance Method Details
#create_evaluation_run(evaluator_name:, run_ids:, metadata: nil) ⇒ Langsmith::Evaluation
Create a new evaluation run on this dataset
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/langsmith/dataset.rb', line 80 def create_evaluation_run(evaluator_name:, run_ids:, metadata: nil) data = { dataset_id: @id, evaluator_name: evaluator_name, run_ids: run_ids } data[:metadata] = if response = @client.post("/evaluations", data) Evaluation.new(@client, response) end |
#create_example(inputs:, outputs: nil, metadata: nil) ⇒ Langsmith::Example
Create a new example in this dataset
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/langsmith/dataset.rb', line 30 def create_example(inputs:, outputs: nil, metadata: nil) data = { dataset_id: @id, inputs: inputs } data[:outputs] = outputs if outputs data[:metadata] = if response = @client.post("/examples", data) Example.new(@client, response) end |
#create_examples_batch(examples:) ⇒ Array<Example>
Create multiple examples in batch
70 71 72 |
# File 'lib/langsmith/dataset.rb', line 70 def create_examples_batch(examples:) @client.create_examples_batch(dataset_id: @id, examples: examples) end |
#delete ⇒ Boolean
Delete this dataset
127 128 129 130 |
# File 'lib/langsmith/dataset.rb', line 127 def delete @client.delete("/datasets/#{@id}") true end |
#get_example(example_id:) ⇒ Langsmith::Example
Get a specific example by ID
46 47 48 49 |
# File 'lib/langsmith/dataset.rb', line 46 def get_example(example_id:) response = @client.get("/examples/#{example_id}") Example.new(@client, response) end |
#list_evaluation_runs(limit: 100, offset: 0) ⇒ Array<Langsmith::Evaluation>
List evaluation runs for this dataset
97 98 99 100 101 102 103 104 105 |
# File 'lib/langsmith/dataset.rb', line 97 def list_evaluation_runs(limit: 100, offset: 0) params = { dataset_id: @id, limit: limit, offset: offset } response = @client.get("/evaluations", params) response.map { |eval_data| Evaluation.new(@client, eval_data) } end |
#list_examples(limit: 100, offset: 0) ⇒ Array<Langsmith::Example>
List examples in this dataset
56 57 58 59 60 61 62 63 64 |
# File 'lib/langsmith/dataset.rb', line 56 def list_examples(limit: 100, offset: 0) params = { dataset_id: @id, limit: limit, offset: offset } response = @client.get("/examples", params) response.map { |example_data| Example.new(@client, example_data) } end |
#update(name: nil, description: nil) ⇒ Langsmith::Dataset
Update this dataset
112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/langsmith/dataset.rb', line 112 def update(name: nil, description: nil) data = {} data[:name] = name if name data[:description] = description if description response = @client.patch("/datasets/#{@id}", data) @name = response[:name] || response["name"] if name @description = response[:description] || response["description"] if description @data = response self end |