Class: Geminize::Models::StreamResponse
- Inherits:
-
Object
- Object
- Geminize::Models::StreamResponse
- Defined in:
- lib/geminize/models/stream_response.rb
Overview
Represents a streaming response chunk from the Gemini API
Instance Attribute Summary collapse
-
#finish_reason ⇒ String?
readonly
The finish reason if this is the last chunk.
-
#raw_chunk ⇒ Hash
readonly
The raw API response data for this chunk.
-
#text ⇒ String?
readonly
The text content in this chunk.
-
#usage_metrics ⇒ Hash?
readonly
Token usage metrics (only available in final chunk).
Class Method Summary collapse
-
.from_hash(chunk_data) ⇒ StreamResponse
Create a StreamResponse object from a raw API response chunk.
Instance Method Summary collapse
-
#completion_tokens ⇒ Integer?
Get the completion token count if available.
-
#final_chunk? ⇒ Boolean
Check if this is the final chunk in the stream.
-
#has_usage_metrics? ⇒ Boolean
Check if this chunk has usage metrics.
-
#initialize(chunk_data) ⇒ StreamResponse
constructor
Initialize a new streaming response chunk.
-
#prompt_tokens ⇒ Integer?
Get the prompt token count if available.
-
#total_tokens ⇒ Integer?
Get the total token count if available.
Constructor Details
#initialize(chunk_data) ⇒ StreamResponse
Initialize a new streaming response chunk
21 22 23 24 |
# File 'lib/geminize/models/stream_response.rb', line 21 def initialize(chunk_data) @raw_chunk = chunk_data parse_chunk end |
Instance Attribute Details
#finish_reason ⇒ String? (readonly)
Returns The finish reason if this is the last chunk.
14 15 16 |
# File 'lib/geminize/models/stream_response.rb', line 14 def finish_reason @finish_reason end |
#raw_chunk ⇒ Hash (readonly)
Returns The raw API response data for this chunk.
8 9 10 |
# File 'lib/geminize/models/stream_response.rb', line 8 def raw_chunk @raw_chunk end |
#text ⇒ String? (readonly)
Returns The text content in this chunk.
11 12 13 |
# File 'lib/geminize/models/stream_response.rb', line 11 def text @text end |
#usage_metrics ⇒ Hash? (readonly)
Returns Token usage metrics (only available in final chunk).
17 18 19 |
# File 'lib/geminize/models/stream_response.rb', line 17 def usage_metrics @usage_metrics end |
Class Method Details
.from_hash(chunk_data) ⇒ StreamResponse
Create a StreamResponse object from a raw API response chunk
62 63 64 |
# File 'lib/geminize/models/stream_response.rb', line 62 def self.from_hash(chunk_data) new(chunk_data) end |
Instance Method Details
#completion_tokens ⇒ Integer?
Get the completion token count if available
47 48 49 50 |
# File 'lib/geminize/models/stream_response.rb', line 47 def completion_tokens return nil unless @usage_metrics @usage_metrics["candidatesTokenCount"] end |
#final_chunk? ⇒ Boolean
Check if this is the final chunk in the stream
28 29 30 |
# File 'lib/geminize/models/stream_response.rb', line 28 def final_chunk? !@finish_reason.nil? end |
#has_usage_metrics? ⇒ Boolean
Check if this chunk has usage metrics
34 35 36 |
# File 'lib/geminize/models/stream_response.rb', line 34 def has_usage_metrics? !@usage_metrics.nil? end |
#prompt_tokens ⇒ Integer?
Get the prompt token count if available
40 41 42 43 |
# File 'lib/geminize/models/stream_response.rb', line 40 def prompt_tokens return nil unless @usage_metrics @usage_metrics["promptTokenCount"] end |
#total_tokens ⇒ Integer?
Get the total token count if available
54 55 56 57 |
# File 'lib/geminize/models/stream_response.rb', line 54 def total_tokens return nil unless @usage_metrics (prompt_tokens || 0) + (completion_tokens || 0) end |