google

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package google provides a Google Gemini language model implementation for GoAI.

It uses the Gemini REST API with SSE streaming and a unique wire format.

Usage:

model := google.Chat("gemini-2.5-flash", google.WithAPIKey("..."))
result, err := goai.GenerateText(ctx, model, goai.WithPrompt("Hello"))

Index

Constants

This section is empty.

Variables

View Source
var Tools = struct {
	// GoogleSearch enables grounding with Google Search.
	// The model decides when to search based on the prompt.
	// Returns sources via groundingMetadata in response.
	GoogleSearch func(opts ...GoogleSearchOption) provider.ToolDefinition

	// URLContext enables URL context tool that gives Gemini access to web content.
	// The model uses URLs from the prompt to fetch and process content.
	// Requires Gemini 2.0+.
	URLContext func() provider.ToolDefinition

	// CodeExecution enables the model to generate and run Python code.
	// The model can write code, execute it in a sandboxed environment, and
	// use the output to formulate its response.
	// Requires Gemini 2.0+.
	CodeExecution func() provider.ToolDefinition
}{
	GoogleSearch:  googleSearchTool,
	URLContext:    urlContextTool,
	CodeExecution: codeExecutionTool,
}

Tools provides factory functions for Google provider-defined tools. These tools use Gemini's built-in capabilities (Google Search grounding, URL context, code execution). Requires Gemini 2.0+. Matches Vercel AI SDK's google.tools.

Functions

func Chat

func Chat(modelID string, opts ...Option) provider.LanguageModel

Chat creates a Google Gemini language model for the given model ID.

func Embedding

func Embedding(modelID string, opts ...Option) provider.EmbeddingModel

Embedding creates a Google Gemini embedding model for the given model ID. Supports text-embedding-004, embedding-001, etc.

func Image

func Image(modelID string, opts ...Option) provider.ImageModel

Image creates a Google Generative AI image model.

For Imagen models (imagen-4.0-generate-001, etc.), uses the :predict endpoint with instances/parameters format -- same wire format as Vertex AI but with Gemini API auth (x-goog-api-key).

For Gemini image models (gemini-2.5-flash-image, etc.), uses the generateContent endpoint with responseModalities: ["IMAGE"] -- Nano Banana pattern.

Provider options (under "google" key in ImageParams.ProviderOptions):

Imagen models:

  • personGeneration (string): "dont_allow", "allow_adult", "allow_all"
  • aspectRatio (string): overrides params.AspectRatio

Gemini image models:

  • imageConfig (map): {"aspectRatio": "1:1", "imageSize": "1K"}

Types

type GoogleSearchOption

type GoogleSearchOption func(*googleSearchConfig)

GoogleSearchOption configures the Google Search grounding tool.

func WithImageSearch

func WithImageSearch() GoogleSearchOption

WithImageSearch enables image search results.

func WithTimeRange

func WithTimeRange(startTime, endTime string) GoogleSearchOption

WithTimeRange restricts search results to a specific time range (RFC3339 format).

func WithWebSearch

func WithWebSearch() GoogleSearchOption

WithWebSearch enables web search results.

type Option

type Option func(*options)

Option configures the Google provider.

func WithAPIKey

func WithAPIKey(key string) Option

WithAPIKey sets a static API key for authentication.

func WithBaseURL

func WithBaseURL(url string) Option

WithBaseURL overrides the default Gemini API base URL.

func WithHTTPClient

func WithHTTPClient(c *http.Client) Option

WithHTTPClient sets a custom HTTP client for all requests.

func WithHeaders

func WithHeaders(h map[string]string) Option

WithHeaders sets additional HTTP headers sent with every request.

func WithTokenSource

func WithTokenSource(ts provider.TokenSource) Option

WithTokenSource sets a dynamic token source for authentication.

Jump to

Keyboard shortcuts

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