Class: PromptObjects::LLM::GeminiAdapter
- Inherits:
-
Object
- Object
- PromptObjects::LLM::GeminiAdapter
- Defined in:
- lib/prompt_objects/llm/gemini_adapter.rb
Overview
Google Gemini API adapter for LLM calls. Uses direct HTTP calls to the Gemini REST API.
Constant Summary collapse
- DEFAULT_MODEL =
"gemini-3.5-flash"- API_BASE_URL =
"https://generativelanguage.googleapis.com/v1beta"
Instance Method Summary collapse
-
#chat(system:, messages:, tools: []) ⇒ Response
Make a chat completion request.
-
#initialize(api_key: nil, model: nil) ⇒ GeminiAdapter
constructor
A new instance of GeminiAdapter.
Constructor Details
#initialize(api_key: nil, model: nil) ⇒ GeminiAdapter
Returns a new instance of GeminiAdapter.
16 17 18 19 20 21 |
# File 'lib/prompt_objects/llm/gemini_adapter.rb', line 16 def initialize(api_key: nil, model: nil) @api_key = api_key || ENV.fetch("GEMINI_API_KEY") do raise Error, "GEMINI_API_KEY environment variable not set" end @model = model || DEFAULT_MODEL end |
Instance Method Details
#chat(system:, messages:, tools: []) ⇒ Response
Make a chat completion request.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/prompt_objects/llm/gemini_adapter.rb', line 28 def chat(system:, messages:, tools: []) body = { system_instruction: build_system_instruction(system), contents: build_contents() } # Only include tools if we have any if tools.any? body[:tools] = build_tools(tools) body[:tool_config] = { function_calling_config: { mode: "AUTO" } } end raw_response = make_request(body) parse_response(raw_response) end |