Class: PromptObjects::LLM::GeminiAdapter

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • system (String)

    System prompt

  • messages (Array<Hash>)

    Conversation history

  • tools (Array<Hash>) (defaults to: [])

    Tool descriptors (optional)

Returns:



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(messages)
  }

  # 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