Skip to main content

Crate klieo_llm_gemini

Crate klieo_llm_gemini 

Source
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 (NOT Authorization: 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}:generateContent etc. The model name is part of the URL path — the request body does NOT carry a top-level model field.
  • Roles are user and model (NOT assistant / system). The system prompt is extracted into the top-level systemInstruction request field.
  • Tool input is a JSON object on the wire (functionCall.args is a JSON object, like Anthropic, opposite of OpenAI). No string-parse boundary needed.
  • Content shape: Content { role, parts: [Part] } where each Part is 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 each data: line carries a partial Candidate. 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 on texts.len().

§Example

use klieo_llm_gemini::GeminiClient;
let client = GeminiClient::new("AIza...", "gemini-2.0-flash");

§Limitations

  • Vision input is declared in Capabilities::vision but the wire encoding for inlineData parts 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_url for self-hosted proxies.
  • Built-in Gemini tools (code execution, Google Search grounding) and cachedContents are deferred to Wave 9 follow-ups.

Re-exports§

pub use capabilities::model_capabilities;
pub use client::GeminiClient;

Modules§

capabilities
Static lookup of klieo_core::Capabilities by Gemini model name.
client
GeminiClientLlmClient impl over Google’s Generative Language API.