Documentation
¶
Overview ¶
Package google provides a Google AI (Gemini) provider implementation.
Index ¶
- Constants
- func CodeExecution() tool.Tool
- func EnterpriseWebSearch() tool.Tool
- func GoogleMaps() tool.Tool
- func GoogleSearch() tool.Tool
- func GoogleSearchWith(opts GoogleSearchOptions) tool.Tool
- func URLContext() tool.Tool
- type GenerativeAIOptions
- type GoogleEmbeddingModel
- func (m *GoogleEmbeddingModel) Dimensions() int
- func (m *GoogleEmbeddingModel) Embed(ctx context.Context, opts model.EmbedCallOptions) (*model.EmbedResult, error)
- func (m *GoogleEmbeddingModel) ID() string
- func (m *GoogleEmbeddingModel) MaxEmbeddingsPerCall() int
- func (m *GoogleEmbeddingModel) Provider() string
- type GoogleImageModel
- type GoogleModel
- type GoogleSearchOptions
- type GoogleSearchTimeRange
- type GoogleSearchTypes
- type ImageConfig
- type LatLng
- type Options
- type Provider
- func (p *Provider) EmbeddingModel(modelID string) model.EmbeddingModel
- func (p *Provider) EmbeddingModels() []string
- func (p *Provider) ID() string
- func (p *Provider) ImageModel(modelID string) model.ImageModel
- func (p *Provider) LanguageModel(modelID string) model.LanguageModel
- func (p *Provider) Model(modelID string) stream.Model
- func (p *Provider) Models() []string
- func (p *Provider) RerankingModel(modelID string) model.RerankingModel
- func (p *Provider) SpeechModel(modelID string) model.SpeechModel
- func (p *Provider) TranscriptionModel(modelID string) model.TranscriptionModel
- type RetrievalConfig
- type SafetySetting
- type ThinkingConfig
Constants ¶
const ( ToolIDGoogleSearch = "google.google_search" ToolIDGoogleMaps = "google.google_maps" ToolIDEnterpriseWebSearch = "google.enterprise_web_search" ToolIDURLContext = "google.url_context" ToolIDCodeExecution = "google.code_execution" )
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 ¶
CodeExecution returns the code_execution tool. Requires Gemini 2+.
func EnterpriseWebSearch ¶
EnterpriseWebSearch returns the enterprise_web_search grounding tool. Requires Gemini 2+.
func GoogleMaps ¶
GoogleMaps returns the google_maps grounding tool. Requires Gemini 2+.
func GoogleSearch ¶
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 URLContext ¶
URLContext returns the url_context tool. Requires Gemini 2+.
Types ¶
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 service tier. Values: "standard", "flex",
// "priority" (ai-sdk #4e22c2c). On Vertex, goai maps these to the
// SERVICE_TIER_* wire values.
ServiceTier string `json:"serviceTier,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 ¶
func (m *GoogleEmbeddingModel) Embed(ctx context.Context, opts model.EmbedCallOptions) (*model.EmbedResult, error)
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
}
GoogleImageModel implements the ImageModel interface for Google AI.
func (*GoogleImageModel) Generate ¶
func (m *GoogleImageModel) Generate(ctx context.Context, opts model.ImageCallOptions) (*model.ImageResult, error)
Generate generates images based on the provided options.
func (*GoogleImageModel) ID ¶
func (m *GoogleImageModel) ID() string
ID returns the model identifier.
func (*GoogleImageModel) MaxImagesPerCall ¶
func (m *GoogleImageModel) MaxImagesPerCall() int
MaxImagesPerCall returns the maximum number of images that can be generated in a single call.
func (*GoogleImageModel) Provider ¶
func (m *GoogleImageModel) Provider() string
Provider returns "google".
type GoogleModel ¶
type GoogleModel struct {
// contains filtered or unexported fields
}
GoogleModel represents a Google Gemini model.
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 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
}
Options contains configuration for the Google provider.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the Google AI provider.
func (*Provider) EmbeddingModel ¶
func (p *Provider) EmbeddingModel(modelID string) model.EmbeddingModel
EmbeddingModel returns an embedding model instance.
func (*Provider) EmbeddingModels ¶
EmbeddingModels returns available embedding model IDs.
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) Models ¶
Models returns available model IDs. Mirrors ai-sdk's GoogleGenerativeAIModelId union in packages/google/src/google-generative-ai-options.ts.
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 nil as Google AI doesn't support speech generation.
func (*Provider) TranscriptionModel ¶
func (p *Provider) TranscriptionModel(modelID string) model.TranscriptionModel
TranscriptionModel returns nil as Google AI doesn't support transcription.
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.