Class: LlmHub::Completion::Providers::Google
- Inherits:
-
Base
- Object
- Base
- LlmHub::Completion::Providers::Google
show all
- Defined in:
- lib/llm_hub/completion/providers/google.rb
Overview
Google Gemini completion provider
Constant Summary
collapse
- COMPLETIONS_URI =
'https://generativelanguage.googleapis.com/v1beta/models'
Instance Attribute Summary
Attributes inherited from Base
#api_key
Instance Method Summary
collapse
Methods inherited from Base
#initialize
included
Instance Method Details
30
31
32
|
# File 'lib/llm_hub/completion/providers/google.rb', line 30
def (response_body)
response_body&.dig('candidates', 0, 'content', 'parts', 0, 'text')
end
|
34
35
36
37
38
39
40
41
|
# File 'lib/llm_hub/completion/providers/google.rb', line 34
def (response_body)
usage_metadata = response_body&.dig('usageMetadata')
{
total_tokens: usage_metadata&.dig('totalTokenCount'),
prompt_tokens: usage_metadata&.dig('promptTokenCount'),
completion_tokens: usage_metadata&.dig('candidatesTokenCount')
}
end
|
15
16
17
18
19
20
|
# File 'lib/llm_hub/completion/providers/google.rb', line 15
def
{
'Content-Type' => 'application/json',
'x-goog-api-key' => @api_key
}
end
|
#request_body(system_prompt, content, _model_name, option_params) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/llm_hub/completion/providers/google.rb', line 22
def request_body(system_prompt, content, _model_name, option_params)
{
system_instruction: build_system_instruction(system_prompt),
contents: build_contents(content),
generationConfig: build_generation_config(option_params)
}
end
|
#url(model_name) ⇒ Object
10
11
12
13
|
# File 'lib/llm_hub/completion/providers/google.rb', line 10
def url(model_name)
"#{COMPLETIONS_URI}/#{model_name}:generateContent"
end
|