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
- type Gemini
- func (g *Gemini) BaseURL() string
- func (g *Gemini) Complete(ctx context.Context, r wire.Request) (wire.Response, error)
- func (g *Gemini) Model() string
- func (g *Gemini) SetBaseURL(u string)
- func (g *Gemini) Stream(ctx context.Context, r wire.Request, h wire.StreamHandler) (wire.Response, error)
- func (g *Gemini) WebFetch(ctx context.Context, url string) (string, wire.Response, error)
- func (g *Gemini) WebSearch(ctx context.Context, query string) (string, wire.Response, error)
Constants ¶
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).
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 ¶
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 ¶
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) Complete ¶
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 ¶
Model returns the default (balanced-tier) model id — for display and the StrongProvider surface.
func (*Gemini) SetBaseURL ¶
SetBaseURL points the adapter at a different Gemini host (tests, proxies). "" restores the SDK default.
func (*Gemini) Stream ¶
func (g *Gemini) Stream(ctx context.Context, r wire.Request, h wire.StreamHandler) (wire.Response, error)
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) WebFetch ¶
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.