Class: Langsmith::Example
- Inherits:
-
Object
- Object
- Langsmith::Example
- Defined in:
- lib/langsmith/dataset.rb
Overview
Example class to represent dataset examples
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#dataset_id ⇒ Object
readonly
Returns the value of attribute dataset_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#inputs ⇒ Object
readonly
Returns the value of attribute inputs.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#outputs ⇒ Object
readonly
Returns the value of attribute outputs.
Instance Method Summary collapse
-
#delete ⇒ Boolean
Delete this example.
-
#initialize(client, data) ⇒ Example
constructor
A new instance of Example.
-
#update(inputs: nil, outputs: nil, metadata: nil) ⇒ Langsmith::Example
Update this example.
Constructor Details
#initialize(client, data) ⇒ Example
Returns a new instance of Example.
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/langsmith/dataset.rb', line 137 def initialize(client, data) @client = client @id = data[:id] || data["id"] @dataset_id = data[:dataset_id] || data["dataset_id"] @inputs = data[:inputs] || data["inputs"] @outputs = data[:outputs] || data["outputs"] @metadata = data[:metadata] || data["metadata"] created_at_value = data[:created_at] || data["created_at"] @created_at = created_at_value ? Time.parse(created_at_value) : nil @data = data end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
135 136 137 |
# File 'lib/langsmith/dataset.rb', line 135 def created_at @created_at end |
#dataset_id ⇒ Object (readonly)
Returns the value of attribute dataset_id.
135 136 137 |
# File 'lib/langsmith/dataset.rb', line 135 def dataset_id @dataset_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
135 136 137 |
# File 'lib/langsmith/dataset.rb', line 135 def id @id end |
#inputs ⇒ Object (readonly)
Returns the value of attribute inputs.
135 136 137 |
# File 'lib/langsmith/dataset.rb', line 135 def inputs @inputs end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
135 136 137 |
# File 'lib/langsmith/dataset.rb', line 135 def @metadata end |
#outputs ⇒ Object (readonly)
Returns the value of attribute outputs.
135 136 137 |
# File 'lib/langsmith/dataset.rb', line 135 def outputs @outputs end |
Instance Method Details
#delete ⇒ Boolean
Delete this example
172 173 174 175 |
# File 'lib/langsmith/dataset.rb', line 172 def delete @client.delete("/examples/#{@id}") true end |
#update(inputs: nil, outputs: nil, metadata: nil) ⇒ Langsmith::Example
Update this example
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/langsmith/dataset.rb', line 155 def update(inputs: nil, outputs: nil, metadata: nil) data = {} data[:inputs] = inputs if inputs data[:outputs] = outputs if outputs data[:metadata] = if response = @client.patch("/examples/#{@id}", data) @inputs = response[:inputs] || response["inputs"] if inputs @outputs = response[:outputs] || response["outputs"] if outputs @metadata = response[:metadata] || response["metadata"] if @data = response self end |