gemini

package
v0.42.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: Apache-2.0 Imports: 13 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gemini implements agent.LLMProvider for Google Gemini — both the public Gemini API and Vertex AI — plus the Gemini-backed embedder and multimodal media analyzer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embedder

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

Embedder implements tools.Embedder using Google Gemini embeddings.

Default model is text-embedding-004 (768 dims, retrieval-tuned). The SDK batches automatically; large inputs should still be chunked by the caller if they approach the per-request token limit.

func NewEmbedder

func NewEmbedder(apiKey string, model string) (*Embedder, error)

NewEmbedder constructs an embedder. apiKey falls back to GEMINI_API_KEY. model defaults to "text-embedding-004".

func (*Embedder) Embed

func (e *Embedder) Embed(ctx context.Context, texts []string) ([][]float32, error)

Embed returns one vector per input in the same order.

type MediaAnalyzer

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

MediaAnalyzer uses Gemini's multimodal API to analyze images and videos. It accepts data URIs ("data:<mime>;base64,<data>") and passes them as inline blobs, so it works for any MIME type Gemini supports — including video/mp4, video/webm, video/quicktime, image/*, etc.

func NewMediaAnalyzer

func NewMediaAnalyzer(apiKey, model string) (*MediaAnalyzer, error)

NewMediaAnalyzer builds an analyzer. apiKey defaults to GEMINI_API_KEY; model defaults to "gemini-2.5-flash".

func (*MediaAnalyzer) Analyze

func (a *MediaAnalyzer) Analyze(ctx context.Context, media, prompt string) (string, error)

Analyze sends the media data URI and prompt to Gemini and returns the response. media must be a data URI of the form "data:<mime>;base64,<data>".

type Option

type Option func(*Provider)

Option configures a Provider at construction.

func WithSeed

func WithSeed(n int64) Option

WithSeed requests best-effort deterministic sampling. Gemini accepts a 32-bit seed; values outside int32 range are truncated. Determinism is not guaranteed across model versions — pair with a pinned temperature for the strongest reproducibility Gemini offers.

func WithTemperature

func WithTemperature(t float64) Option

WithTemperature pins the sampling temperature (0.0–2.0 for Gemini). Use 0 for maximally reproducible classification/extraction turns; unset keeps the provider default.

func WithTopP

func WithTopP(v float64) Option

WithTopP pins nucleus sampling. Unset keeps the provider default.

type Provider

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

Provider implements agent.LLMProvider using Google Gemini native SDK.

func New

func New(apiKey string, model string, opts ...Option) (*Provider, error)

New creates a wrapper over Google Gemini's API.

func NewVertex

func NewVertex(projectID, location, model string, opts ...Option) (*Provider, error)

NewVertex returns a Provider wired to Vertex AI instead of the public Gemini API. Vertex uses Application Default Credentials (ADC) plus a GCP project/location rather than an API key — run `gcloud auth application-default login` or mount a service-account key via GOOGLE_APPLICATION_CREDENTIALS.

Empty projectID / location fall back to GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_LOCATION respectively. Empty model defaults to "gemini-2.5-flash".

The returned *Provider reuses the same GenerateStream implementation as the public-API backend — only the transport differs.

func (*Provider) Capabilities added in v0.40.0

func (*Provider) Capabilities() agent.LLMCapabilities

Capabilities reports features implemented by the Gemini adapter.

func (*Provider) GenerateStream

func (p *Provider) GenerateStream(ctx context.Context, memory []history.Message, availableTools *tools.Registry, streamChan chan<- agent.StreamEvent) (agent.LLMResult, error)

GenerateStream maps GopherAgent history to Gemini API format and triggers streaming generation.

type Transcriber added in v0.41.0

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

Transcriber implements audio.Transcriber using Gemini's multimodal API.

Gemini has no dedicated transcription endpoint, so this drives the ordinary generation API with an inline audio blob and a constraining instruction. Two consequences follow, and both are visible in the returned Transcript: Segments is always nil because generation emits no timing, and the result is a model sample rather than a decoder output, so it can paraphrase under adversarial audio in a way a dedicated ASR model does not.

It is a good fit when Gemini is already the deployment's provider and timestamps are not needed. Prefer the OpenAI Transcriber when segment timings matter.

func NewTranscriber added in v0.41.0

func NewTranscriber(apiKey, model string) (*Transcriber, error)

NewTranscriber builds a transcriber. apiKey defaults to GEMINI_API_KEY; model defaults to "gemini-2.5-flash".

func (*Transcriber) Transcribe added in v0.41.0

func (t *Transcriber) Transcribe(ctx context.Context, clip audio.Clip, opts audio.Options) (audio.Transcript, error)

Transcribe converts one clip to text. The returned Transcript never carries Segments; see the type doc.

Jump to

Keyboard shortcuts

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