Class: Langsmith::Feedback

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, data) ⇒ Feedback

Initialize a new Feedback instance

Parameters:

  • client (Langsmith::Client)

    The LangSmith client

  • data (Hash)

    Feedback data from the API



11
12
13
14
15
16
17
18
19
# File 'lib/langsmith/feedback.rb', line 11

def initialize(client, data)
  @client = client
  @id = data["id"]
  @run_id = data["run_id"]
  @key = data["key"]
  @score = data["score"]
  @comment = data["comment"]
  @created_at = data["created_at"] ? Time.parse(data["created_at"]) : nil
end

Instance Attribute Details

#commentObject (readonly)

Returns the value of attribute comment.



5
6
7
# File 'lib/langsmith/feedback.rb', line 5

def comment
  @comment
end

#created_atObject (readonly)

Returns the value of attribute created_at.



5
6
7
# File 'lib/langsmith/feedback.rb', line 5

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/langsmith/feedback.rb', line 5

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/langsmith/feedback.rb', line 5

def key
  @key
end

#run_idObject (readonly)

Returns the value of attribute run_id.



5
6
7
# File 'lib/langsmith/feedback.rb', line 5

def run_id
  @run_id
end

#scoreObject (readonly)

Returns the value of attribute score.



5
6
7
# File 'lib/langsmith/feedback.rb', line 5

def score
  @score
end

Instance Method Details

#deleteBoolean

Delete this feedback

Returns:

  • (Boolean)

    True if the feedback was deleted successfully



38
39
40
41
# File 'lib/langsmith/feedback.rb', line 38

def delete
  response = @client.delete("/feedback/#{@id}")
  response["success"] == true
end

#update(score: nil, comment: nil) ⇒ Langsmith::Feedback

Update this feedback

Parameters:

  • score (Float) (defaults to: nil)

    New feedback score

  • comment (String) (defaults to: nil)

    New feedback comment

Returns:



26
27
28
29
30
31
32
33
# File 'lib/langsmith/feedback.rb', line 26

def update(score: nil, comment: nil)
  data = {}
  data[:score] = score if score
  data[:comment] = comment if comment

  response = @client.patch("/feedback/#{@id}", data)
  Langsmith::Feedback.new(@client, response)
end