Class: ActiveAgent::Providers::Gemini
- Defined in:
- lib/active_agent/providers/gemini.rb
Constant Summary collapse
- DEFAULT_URL =
'https://generativelanguage.googleapis.com/v1beta/openai/chat/completions'
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
- #chat(messages:, tools: []) ⇒ Object
-
#initialize(model: 'gemini-1.5-flash', api_key: nil, api_url: nil) ⇒ Gemini
constructor
A new instance of Gemini.
Constructor Details
#initialize(model: 'gemini-1.5-flash', api_key: nil, api_url: nil) ⇒ Gemini
Returns a new instance of Gemini.
10 11 12 13 14 15 16 |
# File 'lib/active_agent/providers/gemini.rb', line 10 def initialize(model: 'gemini-1.5-flash', api_key: nil, api_url: nil) key = api_key || ENV.fetch('GEMINI_API_KEY', nil) || ENV.fetch('GOOGLE_API_KEY', nil) url = api_url || DEFAULT_URL super(model: model, api_key: key, api_url: url) raise Error, 'GEMINI_API_KEY or GOOGLE_API_KEY is required for Gemini provider' unless @api_key || ENV['MOCK_AGENT_RESPONSE'] end |
Instance Method Details
#chat(messages:, tools: []) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/active_agent/providers/gemini.rb', line 18 def chat(messages:, tools: []) headers = { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{@api_key}" } payload = { model: @model, messages: , temperature: 0.2 } data = http_post(@api_url, headers, payload) = data.dig('choices', 0, 'message') || {} { content: ['content'], tool_calls: nil } end |