Class: Kernai::LlmResponse
- Inherits:
-
Object
- Object
- Kernai::LlmResponse
- Defined in:
- lib/kernai/llm_response.rb
Overview
Structured response returned by every Provider#call. Carries the model’s text output alongside deterministic observability metadata (latency, token usage). Providers that can’t report a field leave it nil — the Kernel and recorder handle that uniformly without any conditional branching at the call sites.
Instance Attribute Summary collapse
-
#completion_tokens ⇒ Object
readonly
Returns the value of attribute completion_tokens.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#latency_ms ⇒ Object
readonly
Returns the value of attribute latency_ms.
-
#prompt_tokens ⇒ Object
readonly
Returns the value of attribute prompt_tokens.
-
#total_tokens ⇒ Object
readonly
Returns the value of attribute total_tokens.
Instance Method Summary collapse
-
#initialize(content:, latency_ms:, prompt_tokens: nil, completion_tokens: nil, total_tokens: nil) ⇒ LlmResponse
constructor
A new instance of LlmResponse.
- #to_h ⇒ Object
Constructor Details
#initialize(content:, latency_ms:, prompt_tokens: nil, completion_tokens: nil, total_tokens: nil) ⇒ LlmResponse
Returns a new instance of LlmResponse.
12 13 14 15 16 17 18 |
# File 'lib/kernai/llm_response.rb', line 12 def initialize(content:, latency_ms:, prompt_tokens: nil, completion_tokens: nil, total_tokens: nil) @content = content.to_s @latency_ms = latency_ms.to_i @prompt_tokens = prompt_tokens @completion_tokens = completion_tokens @total_tokens = total_tokens || derived_total(prompt_tokens, completion_tokens) end |
Instance Attribute Details
#completion_tokens ⇒ Object (readonly)
Returns the value of attribute completion_tokens.
10 11 12 |
# File 'lib/kernai/llm_response.rb', line 10 def completion_tokens @completion_tokens end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
10 11 12 |
# File 'lib/kernai/llm_response.rb', line 10 def content @content end |
#latency_ms ⇒ Object (readonly)
Returns the value of attribute latency_ms.
10 11 12 |
# File 'lib/kernai/llm_response.rb', line 10 def latency_ms @latency_ms end |
#prompt_tokens ⇒ Object (readonly)
Returns the value of attribute prompt_tokens.
10 11 12 |
# File 'lib/kernai/llm_response.rb', line 10 def prompt_tokens @prompt_tokens end |
#total_tokens ⇒ Object (readonly)
Returns the value of attribute total_tokens.
10 11 12 |
# File 'lib/kernai/llm_response.rb', line 10 def total_tokens @total_tokens end |
Instance Method Details
#to_h ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/kernai/llm_response.rb', line 20 def to_h { content: @content, latency_ms: @latency_ms, prompt_tokens: @prompt_tokens, completion_tokens: @completion_tokens, total_tokens: @total_tokens } end |