Class: Geminize::Models::ContentResponse
- Inherits:
-
Object
- Object
- Geminize::Models::ContentResponse
- Defined in:
- lib/geminize/models/content_response.rb,
lib/geminize/models/content_response_extensions.rb
Overview
Extends ContentResponse with function calling capabilities
Instance Attribute Summary collapse
-
#code_execution_result ⇒ Geminize::Models::CodeExecution::CodeExecutionResult?
readonly
The code execution result in the response, if any.
-
#executable_code ⇒ Geminize::Models::CodeExecution::ExecutableCode?
readonly
The executable code in the response, if any.
-
#finish_reason ⇒ String?
readonly
The reason why generation stopped (if applicable).
-
#function_call ⇒ Geminize::Models::FunctionResponse?
readonly
The function call in the response, if any.
-
#json_response ⇒ String?
readonly
The raw JSON response content, if this is a JSON response.
-
#raw_response ⇒ Hash
readonly
The raw API response data.
-
#usage ⇒ Hash?
readonly
Token counts for the request and response.
Class Method Summary collapse
-
.from_hash(response_data) ⇒ ContentResponse
Create a ContentResponse object from a raw API response.
Instance Method Summary collapse
-
#completion_tokens ⇒ Integer?
Get the completion token count.
-
#has_code_execution_result? ⇒ Boolean
Determine if the response contains a code execution result.
-
#has_executable_code? ⇒ Boolean
Determine if the response contains executable code.
-
#has_function_call? ⇒ Boolean
Determine if the response contains a function call.
-
#has_json_response? ⇒ Boolean
Determine if the response contains a JSON response.
-
#has_text? ⇒ Boolean
Check if the response has generated text.
-
#initialize(response_data) ⇒ ContentResponse
constructor
Initialize a new content generation response.
-
#original_initialize ⇒ ContentResponse
Initialize a new content generation response Store the response data for extensions.
-
#prompt_tokens ⇒ Integer?
Get the prompt token count.
-
#text ⇒ String?
Get the generated text from the response.
-
#total_tokens ⇒ Integer?
Get the total token count.
Constructor Details
#initialize(response_data) ⇒ ContentResponse
Initialize a new content generation response
18 19 20 21 |
# File 'lib/geminize/models/content_response.rb', line 18 def initialize(response_data) @raw_response = response_data parse_response end |
Instance Attribute Details
#code_execution_result ⇒ Geminize::Models::CodeExecution::CodeExecutionResult? (readonly)
17 18 19 |
# File 'lib/geminize/models/content_response_extensions.rb', line 17 def code_execution_result @code_execution_result end |
#executable_code ⇒ Geminize::Models::CodeExecution::ExecutableCode? (readonly)
14 15 16 |
# File 'lib/geminize/models/content_response_extensions.rb', line 14 def executable_code @executable_code end |
#finish_reason ⇒ String? (readonly)
11 12 13 |
# File 'lib/geminize/models/content_response.rb', line 11 def finish_reason @finish_reason end |
#function_call ⇒ Geminize::Models::FunctionResponse? (readonly)
8 9 10 |
# File 'lib/geminize/models/content_response_extensions.rb', line 8 def function_call @function_call end |
#json_response ⇒ String? (readonly)
11 12 13 |
# File 'lib/geminize/models/content_response_extensions.rb', line 11 def json_response @json_response end |
#raw_response ⇒ Hash (readonly)
8 9 10 |
# File 'lib/geminize/models/content_response.rb', line 8 def raw_response @raw_response end |
#usage ⇒ Hash? (readonly)
14 15 16 |
# File 'lib/geminize/models/content_response.rb', line 14 def usage @usage end |
Class Method Details
.from_hash(response_data) ⇒ ContentResponse
Create a ContentResponse object from a raw API response
73 74 75 |
# File 'lib/geminize/models/content_response.rb', line 73 def self.from_hash(response_data) new(response_data) end |
Instance Method Details
#completion_tokens ⇒ Integer?
Get the completion token count
64 65 66 67 68 |
# File 'lib/geminize/models/content_response.rb', line 64 def completion_tokens return nil unless @usage @usage["candidatesTokenCount"] end |
#has_code_execution_result? ⇒ Boolean
Determine if the response contains a code execution result
49 50 51 |
# File 'lib/geminize/models/content_response_extensions.rb', line 49 def has_code_execution_result? !@code_execution_result.nil? end |
#has_executable_code? ⇒ Boolean
Determine if the response contains executable code
43 44 45 |
# File 'lib/geminize/models/content_response_extensions.rb', line 43 def has_executable_code? !@executable_code.nil? end |
#has_function_call? ⇒ Boolean
Determine if the response contains a function call
31 32 33 |
# File 'lib/geminize/models/content_response_extensions.rb', line 31 def has_function_call? !@function_call.nil? end |
#has_json_response? ⇒ Boolean
Determine if the response contains a JSON response
37 38 39 |
# File 'lib/geminize/models/content_response_extensions.rb', line 37 def has_json_response? !@json_response.nil? end |
#has_text? ⇒ Boolean
Check if the response has generated text
42 43 44 |
# File 'lib/geminize/models/content_response.rb', line 42 def has_text? !text.nil? && !text.empty? end |
#original_initialize ⇒ ContentResponse
Initialize a new content generation response Store the response data for extensions
20 21 22 23 |
# File 'lib/geminize/models/content_response_extensions.rb', line 20 def initialize(response_data) @raw_response = response_data parse_response end |
#prompt_tokens ⇒ Integer?
Get the prompt token count
56 57 58 59 60 |
# File 'lib/geminize/models/content_response.rb', line 56 def prompt_tokens return nil unless @usage @usage["promptTokenCount"] end |
#text ⇒ String?
Get the generated text from the response
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/geminize/models/content_response.rb', line 25 def text return @text if defined?(@text) @text = nil candidates = @raw_response["candidates"] if candidates && !candidates.empty? content = candidates.first["content"] if content && content["parts"] && !content["parts"].empty? parts_text = content["parts"].map { |part| part["text"] }.compact @text = parts_text.join(" ") unless parts_text.empty? end end @text end |
#total_tokens ⇒ Integer?
Get the total token count
48 49 50 51 52 |
# File 'lib/geminize/models/content_response.rb', line 48 def total_tokens return nil unless @usage (@usage["promptTokenCount"] || 0) + (@usage["candidatesTokenCount"] || 0) end |