Expand description
Google Gemini (Generative Language API) client implementing
klieo_core::LlmClient.
Wraps Google’s :generateContent / :streamGenerateContent /
:embedContent / :batchEmbedContents endpoints. Capability
declaration (tool_calling, streaming, structured_output,
embeddings, max_context_tokens, vision) is computed at
construction time from the configured chat-model name; see
capabilities::model_capabilities.
Sibling to klieo-llm-ollama, klieo-llm-openai, and
klieo-llm-anthropic — the four crates implement the same
LlmClient trait so a Box<dyn LlmClient> consumer can swap
between them without other code changes.
§Differences from OpenAI / Anthropic
- Auth:
x-goog-api-key: <key>header (NOTAuthorization: Bearer, NOT?key=query parameter). Vertex AI’s OAuth bearer variant is out of scope for v0.1.0. - Endpoints are model-scoped:
/v1beta/models/{model}:generateContentetc. The model name is part of the URL path — the request body does NOT carry a top-levelmodelfield. - Roles are
userandmodel(NOTassistant/system). The system prompt is extracted into the top-levelsystemInstructionrequest field. - Tool input is a JSON object on the wire (
functionCall.argsis a JSON object, like Anthropic, opposite of OpenAI). No string-parse boundary needed. - Content shape:
Content { role, parts: [Part] }where eachPartis one of{text},{functionCall},{functionResponse}, or{inlineData}(vision). - Tool definitions are wrapped in a protobuf-style group:
tools: [{functionDeclarations: [...]}]. - Streaming is SSE (
?alt=sse) where eachdata:line carries a partialCandidate. Function-calls arrive complete in a single chunk (not fragment-by-fragment like OpenAI / Anthropic), so the parser does NOT need a per-call accumulator. - Embeddings ARE supported via
:embedContent(single input) and:batchEmbedContents(multi-input). Single vs batch is chosen internally based ontexts.len().
§Example
use klieo_llm_gemini::GeminiClient;
let client = GeminiClient::new("AIza...", "gemini-2.0-flash");§Limitations
- Vision input is declared in
Capabilities::visionbut the wire encoding forinlineDataparts is not implemented in v0.1.0; see the carryovers section of the implementation plan. - Vertex AI deployment (different endpoint + OAuth bearer auth) is
not yet a first-class target; override the base URL via
GeminiClient::with_base_urlfor self-hosted proxies. - Built-in Gemini tools (code execution, Google Search grounding)
and
cachedContentsare deferred to Wave 9 follow-ups.
Re-exports§
pub use capabilities::model_capabilities;pub use client::GeminiClient;
Modules§
- capabilities
- Static lookup of
klieo_core::Capabilitiesby Gemini model name. - client
GeminiClient—LlmClientimpl over Google’s Generative Language API.