gemini

package
v0.22.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package geminiwire is the Gemini adapter (google.golang.org/genai) — the ONE implementation of the Gemini dialect for BOTH backends: the Developer API (API key) and Vertex AI (service-account JSON, passed in — credential RESOLUTION stays with the caller). Transport encoding only — no routing policy, no metering.

Index

Constants

View Source
const EnvGCPSAKey = "GCP_SERVICE_ACCOUNT_KEY"

EnvGCPSAKey names the GCP service-account JSON env var referenced in credential guidance (resolution itself stays with the caller).

View Source
const EnvGeminiKey = "GEMINI_API_KEY"

Gemini is the strong-tier ModelProvider backed by Google's Gemini API via the native genai SDK. It implements ModelProvider + Streamer + WebSearcher + WebFetcher + Model() — the StrongProvider surface — so the Hybrid router can swap it in as the strong tier per-turn via Intent.Vendor.

Gemini's wire shape (Content/Parts/FunctionDeclaration, iter.Seq2 streaming) differs from both OpenAI and Anthropic, so this is a native mapping rather than an oaClient wrapper. wire.Request → []*genai.Content (Role + Parts: Text / FunctionCall / FunctionResponse / InlineData for images). Effort maps onto ThinkingConfig.ThinkingBudget (high=max budget, medium=medium, low=low, off=0). WebSearch/WebFetch use Gemini's GoogleSearch tool. Gemini has no cross-turn reasoning round-trip (no encrypted_content / signature), so thinking blocks are per-call only and dropped on resend (same as the oaClient treatment of Anthropic thinking blocks).

Two backends: when serviceAccountJSON is set, the client runs on Vertex AI with the GCP service account (paid quota). Otherwise it falls back to the Gemini Developer API with an API key (free-tier quota). EnvGeminiKey is the environment variable holding the Google AI API key.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gemini

type Gemini struct {
	// contains filtered or unexported fields
}

func NewGemini

func NewGemini(apiKey string) *Gemini

NewGemini returns a client using the given Google AI API key. baseURL is left empty so the SDK defaults; tests override it via g.baseURL before use (same pattern as Anthropic/OpenAI).

func NewGeminiVertex

func NewGeminiVertex(serviceAccountJSON []byte, project, location string) *Gemini

NewGeminiVertex returns a client that runs on Vertex AI using a GCP service account JSON key. project is the GCP project ID; location is the Vertex AI region (e.g. "global" or "us-central1").

func (*Gemini) BaseURL

func (g *Gemini) BaseURL() string

BaseURL reports the configured override ("" = the SDK default).

func (*Gemini) Complete

func (g *Gemini) Complete(ctx context.Context, r wire.Request) (wire.Response, error)

Complete satisfies the non-streamed contract by streaming under the hood and assembling the full Response (same rationale as Anthropic/OpenAI.Complete).

func (*Gemini) Model

func (g *Gemini) Model() string

Model returns the default (balanced-tier) model id — for display and the StrongProvider surface.

func (*Gemini) SetBaseURL

func (g *Gemini) SetBaseURL(u string)

SetBaseURL points the adapter at a different Gemini host (tests, proxies). "" restores the SDK default.

func (*Gemini) Stream

Stream sends a streaming GenerateContentStream request, forwarding text/usage to h as they arrive, and returns the fully assembled Response (so the agent loop is identical to the non-streaming path).

func (*Gemini) Transcribe added in v0.15.0

func (g *Gemini) Transcribe(ctx context.Context, path, mime string) (string, error)

Transcribe converts an audio file to text by sending it inline to a multimodal generate call. Exported from the provider home so the genai SDK stays contained here; the gateway calls it for inbound voice notes when a Gemini key is the available credential.

func (*Gemini) WebFetch

func (g *Gemini) WebFetch(ctx context.Context, url string) (string, wire.Response, error)

WebFetch retrieves a URL using Gemini's GoogleSearch tool with the URL in the prompt (Gemini has no dedicated url_fetch tool; the model retrieves and summarizes the URL content). Returns the readable content as text.

func (*Gemini) WebSearch

func (g *Gemini) WebSearch(ctx context.Context, query string) (string, wire.Response, error)

WebSearch answers a query using Gemini's GoogleSearch tool, returning the synthesized text. The model runs the searches within the single turn; we return the assistant's text parts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL