5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/qaxpert/gemini_client.rb', line 5
def self.call(prompt)
api_key = ENV['GEMINI_API_KEY']
return "❌ Chave da API não encontrada." unless api_key
uri = URI("#{GEMINI_API_URL}?key=#{api_key}")
= { 'Content-Type' => 'application/json' }
body = {
contents: [
{
parts: [{ text: prompt }],
role: 'user'
}
]
}.to_json
response = Net::HTTP.post(uri, body, )
json = JSON.parse(response.body)
candidate = json.dig('candidates', 0, 'content', 'parts', 0, 'text')
candidate || "❌ Resposta inválida da API Gemini."
rescue => e
"❌ Erro ao chamar Gemini: #{e.message}"
end
|