Class: Regent::LLM::Gemini
Constant Summary collapse
- ENV_KEY =
"GEMINI_API_KEY"- SERVICE =
"generative-language-api"
Instance Method Summary collapse
Methods inherited from Base
Methods included from Concerns::Dependable
included, #initialize, #require_dynamic
Constructor Details
This class inherits a constructor from Regent::LLM::Base
Instance Method Details
#invoke(messages, **args) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/regent/llm/gemini.rb', line 11 def invoke(, **args) response = client.generate_content({ contents: (), generation_config: { temperature: args[:temperature] || 0.0, stop_sequences: args[:stop] || [] } }) result( model: model, content: response.dig("candidates", 0, "content", "parts", 0, "text").strip, input_tokens: response.dig("usageMetadata", "promptTokenCount"), output_tokens: response.dig("usageMetadata", "candidatesTokenCount") ) end |
#parse_error(error) ⇒ Object
28 29 30 |
# File 'lib/regent/llm/gemini.rb', line 28 def parse_error(error) JSON.parse(error.response.dig(:body)).dig("error", "message") end |