Class: InstLLM::Response::ChatResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/inst_llm/response/chat_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, message:, stop_reason:, usage:) ⇒ ChatResponse

Returns a new instance of ChatResponse.



10
11
12
13
14
15
16
17
# File 'lib/inst_llm/response/chat_response.rb', line 10

def initialize(model:, message:, stop_reason:, usage:)
  @created = Time.now.to_i
  @fingerprint = SecureRandom.uuid
  @message = message
  @model = model
  @stop_reason = stop_reason
  @usage = usage
end

Instance Attribute Details

#createdObject (readonly)

Returns the value of attribute created.



8
9
10
# File 'lib/inst_llm/response/chat_response.rb', line 8

def created
  @created
end

#fingerprintObject (readonly)

Returns the value of attribute fingerprint.



8
9
10
# File 'lib/inst_llm/response/chat_response.rb', line 8

def fingerprint
  @fingerprint
end

#messageObject (readonly)

Returns the value of attribute message.



8
9
10
# File 'lib/inst_llm/response/chat_response.rb', line 8

def message
  @message
end

#modelObject (readonly)

Returns the value of attribute model.



8
9
10
# File 'lib/inst_llm/response/chat_response.rb', line 8

def model
  @model
end

#stop_reasonObject (readonly)

Returns the value of attribute stop_reason.



8
9
10
# File 'lib/inst_llm/response/chat_response.rb', line 8

def stop_reason
  @stop_reason
end

#usageObject (readonly)

Returns the value of attribute usage.



8
9
10
# File 'lib/inst_llm/response/chat_response.rb', line 8

def usage
  @usage
end

Class Method Details

.from_claude(model:, response:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/inst_llm/response/chat_response.rb', line 20

def from_claude(model:, response:)
  new(
    model: model,
    message: { role: :assistant, content: response["content"][0]["text"] },
    stop_reason: response["stop_reason"],
    usage: {
      input_tokens: response["usage"]["input_tokens"],
      output_tokens: response["usage"]["output_tokens"]
    }
  )
end

.from_llama3(model:, response:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/inst_llm/response/chat_response.rb', line 32

def from_llama3(model:, response:)
  new(
    model: model,
    message: { role: :assistant, content: response["generation"] },
    stop_reason: response["stop_reason"],
    usage: {
      input_tokens: response["prompt_token_count"],
      output_tokens: response["generation_token_count"]
    }
  )
end

.from_mistral(model:, response:) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/inst_llm/response/chat_response.rb', line 44

def from_mistral(model:, response:)
  new(
    model: model,
    message: { role: :assistant, content: response["outputs"][0]["text"] },
    stop_reason: response["outputs"][0]["stop_reason"],
    usage: {
      input_tokens: -1,
      output_tokens: -1
    }
  )
end