Class: InstLLM::Response::ChatResponse
- Inherits:
-
Object
- Object
- InstLLM::Response::ChatResponse
- Defined in:
- lib/inst_llm/response/chat_response.rb
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#stop_reason ⇒ Object
readonly
Returns the value of attribute stop_reason.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Class Method Summary collapse
- .from_claude(model:, response:) ⇒ Object
- .from_llama3(model:, response:) ⇒ Object
- .from_mistral(model:, response:) ⇒ Object
Instance Method Summary collapse
-
#initialize(model:, message:, stop_reason:, usage:) ⇒ ChatResponse
constructor
A new instance of ChatResponse.
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 = @model = model @stop_reason = stop_reason @usage = usage end |
Instance Attribute Details
#created ⇒ Object (readonly)
Returns the value of attribute created.
8 9 10 |
# File 'lib/inst_llm/response/chat_response.rb', line 8 def created @created end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
8 9 10 |
# File 'lib/inst_llm/response/chat_response.rb', line 8 def fingerprint @fingerprint end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/inst_llm/response/chat_response.rb', line 8 def @message end |
#model ⇒ Object (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_reason ⇒ Object (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 |
#usage ⇒ Object (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 |