Class: Langchain::LLM::GoogleGeminiResponse
Instance Attribute Summary
Attributes inherited from BaseResponse
#context, #model, #raw_response
Instance Method Summary
collapse
#chat_completions, #completion, #completions, #created_at
Constructor Details
Returns a new instance of GoogleGeminiResponse.
5
6
7
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 5
def initialize(raw_response, model: nil)
super
end
|
Instance Method Details
#chat_completion ⇒ Object
9
10
11
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 9
def chat_completion
raw_response.dig("candidates", 0, "content", "parts", 0, "text")
end
|
#completion_tokens ⇒ Object
41
42
43
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 41
def completion_tokens
raw_response.dig("usageMetadata", "candidatesTokenCount")
end
|
#embedding ⇒ Object
25
26
27
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 25
def embedding
embeddings.first
end
|
#embeddings ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 29
def embeddings
if raw_response.key?("embedding")
[raw_response.dig("embedding", "values")]
else
[raw_response.dig("predictions", 0, "embeddings", "values")]
end
end
|
#prompt_tokens ⇒ Object
37
38
39
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 37
def prompt_tokens
raw_response.dig("usageMetadata", "promptTokenCount")
end
|
#role ⇒ Object
13
14
15
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 13
def role
raw_response.dig("candidates", 0, "content", "role")
end
|
17
18
19
20
21
22
23
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 17
def tool_calls
if raw_response.dig("candidates", 0, "content") && raw_response.dig("candidates", 0, "content", "parts", 0).has_key?("functionCall")
raw_response.dig("candidates", 0, "content", "parts")
else
[]
end
end
|
#total_tokens ⇒ Object
45
46
47
|
# File 'lib/langchain/llm/response/google_gemini_response.rb', line 45
def total_tokens
raw_response.dig("usageMetadata", "totalTokenCount")
end
|