google

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package google provides a Google AI (Gemini) provider implementation.

Index

Constants

View Source
const (
	ToolIDGoogleSearch        = "google.google_search"
	ToolIDGoogleMaps          = "google.google_maps"
	ToolIDEnterpriseWebSearch = "google.enterprise_web_search"
	ToolIDURLContext          = "google.url_context"
	ToolIDCodeExecution       = "google.code_execution"
	ToolIDFileSearch          = "google.file_search"
)

Provider-defined tool IDs for Google's built-in grounding tools. Mirrors ai-sdk's createProviderToolFactory ids in packages/google/src/tool/.

Variables

This section is empty.

Functions

func CodeExecution

func CodeExecution() tool.Tool

CodeExecution returns the code_execution tool. Requires Gemini 2+.

func EnterpriseWebSearch

func EnterpriseWebSearch() tool.Tool

EnterpriseWebSearch returns the enterprise_web_search grounding tool. Requires Gemini 2+.

func FileSearch added in v0.1.7

func FileSearch(options FileSearchOptions) tool.Tool

FileSearch grounds responses in managed file stores on Gemini 2.5 and newer.

func GoogleMaps

func GoogleMaps() tool.Tool

GoogleMaps returns the google_maps grounding tool. Requires Gemini 2+.

func GoogleSearch

func GoogleSearch() tool.Tool

GoogleSearch returns the google_search grounding tool with no options. Suitable for Gemini 2+ where {googleSearch:{}} is the canonical form.

func GoogleSearchWith

func GoogleSearchWith(opts GoogleSearchOptions) tool.Tool

GoogleSearchWith returns the google_search grounding tool with explicit options. The options are only sent on older Gemini models that still support googleSearchRetrieval; Gemini 2+ silently ignores them.

func PrepareTools added in v0.1.7

func PrepareTools(tools []tool.Tool, modelID string) any

PrepareTools returns Gemini wire tools for Google and Vertex endpoints.

func ResponseSchema added in v0.1.7

func ResponseSchema(schema json.RawMessage) json.RawMessage

ResponseSchema converts JSON Schema to Gemini's supported OpenAPI schema.

func ThinkingConfiguration added in v0.1.7

func ThinkingConfiguration(modelID, effort string, explicit any) (map[string]any, error)

ThinkingConfiguration resolves uniform effort and explicit Gemini thinking options.

func ThinkingConfigurationWarnings added in v0.1.8

func ThinkingConfigurationWarnings(effort string, explicit any, config map[string]any) []stream.Warning

ThinkingConfigurationWarnings reports lossy level mappings unless an explicit thinking level or budget overrides the shared setting.

func ThoughtSignature added in v0.1.7

func ThoughtSignature(options map[string]any) string

ThoughtSignature reads the Google-family metadata attached to a message part.

func ToolConfig added in v0.1.7

func ToolConfig(choice any) map[string]any

ToolConfig returns the common Gemini function-calling configuration.

func URLContext

func URLContext() tool.Tool

URLContext returns the url_context tool. Requires Gemini 2+.

Types

type FileSearchOptions added in v0.1.7

type FileSearchOptions struct {
	FileSearchStoreNames []string `json:"fileSearchStoreNames"`
	MetadataFilter       string   `json:"metadataFilter,omitempty"`
	TopK                 *int     `json:"topK,omitempty"`
}

FileSearchOptions selects the managed stores used for file grounding.

type FilesOptions added in v0.1.7

type FilesOptions struct {
	DisplayName    string `json:"displayName"`
	PollIntervalMS *int64 `json:"pollIntervalMs"`
	PollTimeoutMS  *int64 `json:"pollTimeoutMs"`
}

type GenerativeAIOptions

type GenerativeAIOptions struct {
	// ResponseModalities controls the response format.
	// Values: "TEXT", "IMAGE"
	ResponseModalities []string `json:"responseModalities,omitempty"`

	// ThinkingConfig configures the thinking/reasoning behavior.
	ThinkingConfig *ThinkingConfig `json:"thinkingConfig,omitempty"`

	// CachedContent is the name of cached content used as context.
	// Format: cachedContents/{cachedContent}
	CachedContent string `json:"cachedContent,omitempty"`

	// StructuredOutputs enables structured output. Default is true.
	// Useful when JSON Schema contains unsupported elements.
	StructuredOutputs *bool `json:"structuredOutputs,omitempty"`

	// SafetySettings is a list of unique safety settings for blocking unsafe content.
	SafetySettings []SafetySetting `json:"safetySettings,omitempty"`

	// Threshold is a global safety threshold setting.
	// Values: "HARM_BLOCK_THRESHOLD_UNSPECIFIED", "BLOCK_LOW_AND_ABOVE", "BLOCK_MEDIUM_AND_ABOVE", "BLOCK_ONLY_HIGH", "BLOCK_NONE", "OFF"
	Threshold string `json:"threshold,omitempty"`

	// AudioTimestamp enables timestamp understanding for audio-only files.
	AudioTimestamp *bool `json:"audioTimestamp,omitempty"`

	// Labels defines labels used in billing reports. Available on Vertex AI only.
	Labels map[string]string `json:"labels,omitempty"`

	// MediaResolution specifies the media resolution.
	// Values: "MEDIA_RESOLUTION_UNSPECIFIED", "MEDIA_RESOLUTION_LOW", "MEDIA_RESOLUTION_MEDIUM", "MEDIA_RESOLUTION_HIGH"
	MediaResolution string `json:"mediaResolution,omitempty"`

	// ImageConfig configures the image generation aspect ratio for Gemini models.
	ImageConfig *ImageConfig `json:"imageConfig,omitempty"`

	// RetrievalConfig provides location context for Google Maps and Google Search grounding.
	RetrievalConfig *RetrievalConfig `json:"retrievalConfig,omitempty"`

	// StreamFunctionCallArguments enables streaming of function call
	// arguments as they're produced. Vertex AI only, Gemini 3+ only.
	// Default is false (ai-sdk #46a3584 flipped the default).
	StreamFunctionCallArguments *bool `json:"streamFunctionCallArguments,omitempty"`

	// ServiceTier selects the Gemini API service tier: standard, flex, or priority.
	ServiceTier       string `json:"serviceTier,omitempty"`
	SharedRequestType string `json:"sharedRequestType,omitempty"`
	RequestType       string `json:"requestType,omitempty"`
}

GenerativeAIOptions contains provider-specific options for the Google Generative AI API. These options match ai-sdk's GoogleGenerativeAIProviderOptions schema. See: ai-sdk/packages/google/src/google-generative-ai-options.ts

type GoogleEmbeddingModel

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

GoogleEmbeddingModel implements the EmbeddingModel interface for Google AI.

func (*GoogleEmbeddingModel) Dimensions

func (m *GoogleEmbeddingModel) Dimensions() int

Dimensions returns the default embedding dimensions.

func (*GoogleEmbeddingModel) Embed

Embed generates embeddings for the provided texts.

func (*GoogleEmbeddingModel) ID

func (m *GoogleEmbeddingModel) ID() string

ID returns the model identifier.

func (*GoogleEmbeddingModel) MaxEmbeddingsPerCall

func (m *GoogleEmbeddingModel) MaxEmbeddingsPerCall() int

MaxEmbeddingsPerCall returns the maximum number of texts that can be embedded in a single call.

func (*GoogleEmbeddingModel) Provider

func (m *GoogleEmbeddingModel) Provider() string

Provider returns "google".

type GoogleImageModel

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

func (*GoogleImageModel) Generate

func (*GoogleImageModel) ID

func (m *GoogleImageModel) ID() string

func (*GoogleImageModel) MaxImagesPerCall

func (m *GoogleImageModel) MaxImagesPerCall() int

func (*GoogleImageModel) Provider

func (m *GoogleImageModel) Provider() string

type GoogleModel

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

GoogleModel represents a Google Gemini model.

func (*GoogleModel) ID

func (m *GoogleModel) ID() string

ID returns the model ID.

func (*GoogleModel) Provider

func (m *GoogleModel) Provider() string

Provider returns "google".

func (*GoogleModel) Stream

func (m *GoogleModel) Stream(ctx context.Context, options *stream.CallOptions) (<-chan stream.Event, error)

Stream sends a streaming request to Google AI.

type GoogleSearchOptions

type GoogleSearchOptions struct {
	// Mode is "MODE_DYNAMIC" or "MODE_UNSPECIFIED".
	Mode string `json:"mode,omitempty"`
	// DynamicThreshold is the similarity threshold for dynamic retrieval.
	DynamicThreshold float64 `json:"dynamicThreshold,omitempty"`

	// SearchTypes opts into specific grounding sub-queries (web, image).
	// Gemini 2+ only.
	SearchTypes *GoogleSearchTypes `json:"searchTypes,omitempty"`

	// TimeRangeFilter narrows results to a window. Both start and end
	// are RFC3339 timestamps.
	TimeRangeFilter *GoogleSearchTimeRange `json:"timeRangeFilter,omitempty"`
}

GoogleSearchOptions configures the google_search grounding tool.

Mode and DynamicThreshold are only honored on older Gemini versions that use the googleSearchRetrieval API (gemini-1.5-flash). Gemini 2+ ignores them — the request becomes {googleSearch:{}} (possibly with searchTypes / timeRangeFilter) regardless.

SearchTypes and TimeRangeFilter mirror ai-sdk #2565e70, which added explicit sub-selectors on the Gemini 2+ payload (letting callers opt into image search, web search, or narrow the time window).

type GoogleSearchTimeRange

type GoogleSearchTimeRange struct {
	StartTime string `json:"startTime"`
	EndTime   string `json:"endTime"`
}

GoogleSearchTimeRange narrows grounding results to a date range.

type GoogleSearchTypes

type GoogleSearchTypes struct {
	WebSearch   *struct{} `json:"webSearch,omitempty"`
	ImageSearch *struct{} `json:"imageSearch,omitempty"`
}

GoogleSearchTypes selects which Google Search sub-queries to run. Fields are marker objects — presence enables the type.

type GoogleSpeechModel added in v0.1.7

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

func (*GoogleSpeechModel) Generate added in v0.1.7

func (*GoogleSpeechModel) ID added in v0.1.7

func (m *GoogleSpeechModel) ID() string

func (*GoogleSpeechModel) Provider added in v0.1.7

func (m *GoogleSpeechModel) Provider() string

type GoogleTranscriptionModel added in v0.1.7

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

func (*GoogleTranscriptionModel) ID added in v0.1.7

func (*GoogleTranscriptionModel) Provider added in v0.1.7

func (m *GoogleTranscriptionModel) Provider() string

func (*GoogleTranscriptionModel) Transcribe added in v0.1.7

type ImageConfig

type ImageConfig struct {
	// AspectRatio for generated images.
	// Values: "1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"
	AspectRatio string `json:"aspectRatio,omitempty"`

	// ImageSize for generated images.
	// Values: "1K", "2K", "4K"
	ImageSize string `json:"imageSize,omitempty"`
}

ImageConfig configures image generation.

type LatLng

type LatLng struct {
	// Latitude of the location.
	Latitude float64 `json:"latitude"`

	// Longitude of the location.
	Longitude float64 `json:"longitude"`
}

LatLng represents a geographic coordinate.

type Options

type Options struct {
	// APIKey is the Google AI API key.
	APIKey string

	// BaseURL overrides the default API endpoint.
	BaseURL string

	// Headers are additional HTTP headers to send.
	Headers map[string]string

	// HTTPClient sends language-model requests. Nil uses http.DefaultClient.
	HTTPClient *http.Client
}

Options contains configuration for the Google provider.

type Provider

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

Provider implements the Google AI provider.

func New

func New(opts Options) *Provider

New creates a new Google AI provider.

func (*Provider) EmbeddingModel

func (p *Provider) EmbeddingModel(modelID string) model.EmbeddingModel

EmbeddingModel returns an embedding model instance.

func (*Provider) Files added in v0.1.7

func (p *Provider) Files() model.Files

func (*Provider) ID

func (p *Provider) ID() string

ID returns "google".

func (*Provider) ImageModel

func (p *Provider) ImageModel(modelID string) model.ImageModel

ImageModel returns an image model instance.

func (*Provider) LanguageModel

func (p *Provider) LanguageModel(modelID string) model.LanguageModel

LanguageModel returns a language model instance.

func (*Provider) Model

func (p *Provider) Model(modelID string) stream.Model

Model returns a language model instance.

func (*Provider) RerankingModel

func (p *Provider) RerankingModel(modelID string) model.RerankingModel

RerankingModel returns nil as Google AI doesn't support reranking.

func (*Provider) SpeechModel

func (p *Provider) SpeechModel(modelID string) model.SpeechModel

SpeechModel returns a Gemini text-to-speech model.

func (*Provider) TranscriptionModel

func (p *Provider) TranscriptionModel(modelID string) model.TranscriptionModel

TranscriptionModel returns a unary Gemini transcription model.

type RetrievalConfig

type RetrievalConfig struct {
	// LatLng is the latitude/longitude for location context.
	LatLng *LatLng `json:"latLng,omitempty"`
}

RetrievalConfig provides location context for grounding.

type SafetySetting

type SafetySetting struct {
	// Category of harm to block.
	// Values: "HARM_CATEGORY_UNSPECIFIED", "HARM_CATEGORY_HATE_SPEECH", "HARM_CATEGORY_DANGEROUS_CONTENT",
	//         "HARM_CATEGORY_HARASSMENT", "HARM_CATEGORY_SEXUALLY_EXPLICIT", "HARM_CATEGORY_CIVIC_INTEGRITY"
	Category string `json:"category"`

	// Threshold for blocking.
	// Values: "HARM_BLOCK_THRESHOLD_UNSPECIFIED", "BLOCK_LOW_AND_ABOVE", "BLOCK_MEDIUM_AND_ABOVE",
	//         "BLOCK_ONLY_HIGH", "BLOCK_NONE", "OFF"
	Threshold string `json:"threshold"`
}

SafetySetting represents a safety setting for content blocking.

type ThinkingConfig

type ThinkingConfig struct {
	// ThinkingBudget is the token budget for thinking.
	ThinkingBudget int `json:"thinkingBudget,omitempty"`

	// IncludeThoughts controls whether to include thoughts in output.
	IncludeThoughts *bool `json:"includeThoughts,omitempty"`

	// ThinkingLevel controls the thinking level.
	// Values: "minimal", "low", "medium", "high"
	ThinkingLevel string `json:"thinkingLevel,omitempty"`
}

ThinkingConfig configures Google's thinking/reasoning behavior.

Jump to

Keyboard shortcuts

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