Help us shape the future of Go! Take the 2026 Go Developer Survey

gemini

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package gemini adapts Google's Gemini generateContent API to agent.Model. It translates the provider-neutral []agent.Message/Part model to Gemini "contents" (text, inlineData/fileData images, functionCall, functionResponse), declares tools as functionDeclarations, opens the SSE stream (streamGenerateContent?alt=sse), and normalizes Gemini's response chunks into agent's Event taxonomy. Zero external deps: net/http + stdlib, exactly like the anthropic and openai adapters (the repo enforces a lean core via architecture_test.go, so google.golang.org/genai is deliberately not imported).

Gemini sends COMPLETE functionCall objects (name + args object), not the streamed argument fragments Anthropic/OpenAI send. So one functionCall part becomes a single ToolCallDelta carrying the whole args object as ArgsFragment; the agent core's finalize() json.Valid gate still holds because a complete args object is valid JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Model

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

Model is a Google Gemini generateContent API adapter implementing agent.Model.

func New

func New(apiKey string, opts ...Option) *Model

New constructs a Gemini model adapter. apiKey is your Google AI Studio API key. For Vertex AI or a proxy, override the host with WithBaseURL (the request path /v1beta/models/{model}:streamGenerateContent is appended to it).

func (*Model) Stream

func (m *Model) Stream(ctx context.Context, req agent.Request) (*agent.Stream, error)

Stream implements agent.Model.

type Option

type Option func(*Model)

func WithBaseURL

func WithBaseURL(u string) Option

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

func WithMaxTokens

func WithMaxTokens(n int) Option

func WithModel

func WithModel(id string) Option

Jump to

Keyboard shortcuts

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