Class: Langsmith::Example

Inherits:
Object
  • Object
show all
Defined in:
lib/langsmith/dataset.rb

Overview

Example class to represent dataset examples

Instance Attribute Summary collapse

Instance Method Summary collapse

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_atObject (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_idObject (readonly)

Returns the value of attribute dataset_id.



135
136
137
# File 'lib/langsmith/dataset.rb', line 135

def dataset_id
  @dataset_id
end

#idObject (readonly)

Returns the value of attribute id.



135
136
137
# File 'lib/langsmith/dataset.rb', line 135

def id
  @id
end

#inputsObject (readonly)

Returns the value of attribute inputs.



135
136
137
# File 'lib/langsmith/dataset.rb', line 135

def inputs
  @inputs
end

#metadataObject (readonly)

Returns the value of attribute metadata.



135
136
137
# File 'lib/langsmith/dataset.rb', line 135

def 
  @metadata
end

#outputsObject (readonly)

Returns the value of attribute outputs.



135
136
137
# File 'lib/langsmith/dataset.rb', line 135

def outputs
  @outputs
end

Instance Method Details

#deleteBoolean

Delete this example

Returns:

  • (Boolean)

    True if successful



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

Parameters:

  • inputs (Hash, nil) (defaults to: nil)

    New input values (optional)

  • outputs (Hash, nil) (defaults to: nil)

    New output values (optional)

  • metadata (Hash, nil) (defaults to: nil)

    New metadata (optional)

Returns:



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