Documentation
¶
Overview ¶
Package google exposes native Gemini chat, embedding, image, speech, transcription, and token-estimation adapters. NewChatCompletions targets Gemini's OpenAI-compatible chat endpoint. Native chat maps a natural stop with function calls to Core tool_calls while preserving interrupted and invalid-call outcomes and the native finish reason. Core ToolCall.ID is replayed unchanged on the call and its matching result, including IDs synthesized when the provider omitted one. ToolResult.IsError alone selects the native error or output envelope. The complete result stays inside it so business fields cannot change its status. Native chat request extensions use the SDK's camelCase JSON fields only. Chat, speech, and transcription each produce a single candidate. An explicit count of one is supported; larger or negative counts fail before provider I/O. GenerateContent has one native decoder shared by unary and streaming calls. The official SDK owns full backend request admission and projection. Local request preparation performs no provider I/O; the adapter sends the prepared request once and keeps strict unary/SSE decoding outside the SDK's response converters. Opaque JSON retains its original number representation. Automatic continuation is rejected. HTTP extensions allow headers and timeout only; timeout uses the SDK Go JSON representation, integer nanoseconds. Omission or zero adds no per-request timeout, while the host HTTP policy still applies. Local admission failures prove NotExecuted; errors after external execution are Unknown and retain their cause without inheriting nested call evidence. Only ordinary content FileData may omit MIME because Gemini can resolve its type remotely. Inline and function-response media require explicit MIME. Core Citation owns validation of native citations with a URI. Invalid citations fail Call and Stream rather than disappearing from a successful response. Citation-only chunks reach Core's accumulator, which owns text attachment. Sampling, output format, reasoning effort, system messages, function tools, and tool choice belong to Core; attempts to set them again in native config are rejected even when the Core value is absent. Native safety, grounding, modalities, and thinking-budget settings remain available. Thinking budget and Core reasoning effort are mutually exclusive after resolving defaults. Code execution is rejected before I/O because Core cannot represent its output and replay losslessly. Execution parts in responses fail validation. Each stream binds the first reported response ID and model version; later omissions preserve them, while conflicting values fail validation. Thought signatures retain their original Part positions across streaming, history serialization, and replay. Signature-only Parts carry opaque Core reasoning state without visible reasoning text. Core Part.Kind owns the thought classification of visible text. Native part_state retains the independent flag on signature-only, tool, and media Parts. Stored visible-text state containing a competing thought flag is rejected. Google-managed ToolCall/ToolResponse Parts are native replay state, never host tool calls. Runs attach before the next Core part or at the message's end, so history replay uses current Core content without losing native tool ordering. A server-tool-only turn uses an assistant message with native metadata and no portable parts. Native Part data payloads are exclusive; conflicts are errors. Embedding extensions admit only taskType, title, mimeType, autoTruncate, documentOcr, and audioTrackExtraction. HTTP envelopes are excluded because SDK extra-body merging could overwrite Core's texts, model, or dimensions. autoTruncate requires Vertex AI; Gemini rejects either explicit boolean value. Positive dimensions must fit the SDK's int32 representation; the service determines the selected model's supported dimensions. Embedding responses retain the exact native JSON. Optional token, truncation, and billing metadata is projected only when reported, including zero and false.
Constructors take a context because construction reaches the network. On the Vertex AI backend with application default credentials, building the client resolves them and then asks the resolved credential for its quota project, which is a metadata-server call the context governs — so a caller can bound or cancel its own wiring instead of a background context deciding for it. NewChatCompletions and NewImageModel borrow HTTP policy directly rather than constructing a Gen AI client.
NewImageModel owns the Gemini Interactions image capability. Native controls are ImageGenerationOptions under ImageRequestExtensionKey; their typed vocabulary and admission live with those public values. Input image MIME declarations remain required; URLs do not establish their content type. Only completed interactions produce Core image responses. Interactions uses an independent HTTP transport because GenerateContent and Vertex AI use different protocols and authentication contracts.
Interactions targets the current steps schema. Hosts that pin API revisions through their HTTPClient must choose one with that schema; legacy outputs responses cannot establish a completed image result.
NewSpeechModel performs unary-only Gemini 2.5 speech synthesis. Unary speech and transcription require a STOP finish reason. Truncated, blocked, or unterminated generation returns the modality's ErrInvalidResponse without presenting partial content as a completed response. Gemini 3.1 uses NewStreamingSpeechModel: Call aggregates Stream, and both require successful stream completion. Call discards partial audio on error. SpeechModelConfig.MaxResponseBytes bounds decoded audio returned by either Call capability; Stream retains the native per-event budget and incremental delivery. Token-count and embedding JSON responses use Core's httpclient.DefaultMaxJSONResponseBytes before native validation or SDK decoding. Native speech_response metadata describes the latest stream event, not a fabricated unary response. Request model overrides must stay in that capability.
Index ¶
- Constants
- func NewChatCompletions(ctx context.Context, config ChatCompletionsConfig) (*corechat.StreamModel, error)
- type Chat
- type ChatCompletionsConfig
- type ChatConfig
- type EmbeddingModel
- type EmbeddingModelConfig
- type ImageAspectRatio
- type ImageDelivery
- type ImageGenerationOptions
- type ImageGoogleSearchOptions
- type ImageModel
- type ImageModelConfig
- type ImageSafetyCategory
- type ImageSafetyMethod
- type ImageSafetySetting
- type ImageSafetyThreshold
- type ImageSearchType
- type ImageServiceTier
- type ImageSize
- type ImageThinkingLevel
- type ImageThinkingSummaryMode
- type SpeechModel
- type SpeechModelConfig
- type StreamingSpeechModel
- type TextCounter
- type TextCounterConfig
- type TranscriptionModel
- type TranscriptionModelConfig
Constants ¶
const ( ImageRequestExtensionKey = Provider + protocol.ImageRequestExtensionSuffix ImageResponseExtensionKey = Provider + protocol.ImageResponseExtensionSuffix )
const ( Provider = protocol.GoogleProviderID DefaultBaseURL = protocol.DefaultBaseURL BaseURLOpenAI = "https://generativelanguage.googleapis.com/v1beta/openai" RequestExtensionKey = protocol.RequestExtensionKey ResponseExtensionKey = protocol.ResponseExtensionKey SpeechRequestExtensionKey = protocol.SpeechRequestExtensionKey SpeechResponseExtensionKey = protocol.SpeechResponseExtensionKey TranscriptionRequestExtensionKey = protocol.TranscriptionRequestExtensionKey TranscriptionResponseExtensionKey = protocol.TranscriptionResponseExtensionKey EmbeddingRequestExtensionKey = protocol.EmbeddingRequestExtensionKey EmbeddingResponseExtensionKey = protocol.EmbeddingResponseExtensionKey OpenAIRequestExtensionKey = Provider + openaiprotocol.CompatibleRequestExtensionSuffix OpenAIStreamChunkExtensionKey = Provider + openaiprotocol.CompatibleStreamExtensionSuffix ModelGemini36Flash = protocol.ModelGemini36Flash ModelGemini35Flash = protocol.ModelGemini35Flash ModelGemini35FlashLite = protocol.ModelGemini35FlashLite ModelGemini31ProPreview = protocol.ModelGemini31ProPreview ModelGemini25FlashPreviewTTS = protocol.ModelGemini25FlashPreviewTTS ModelGemini25ProPreviewTTS = protocol.ModelGemini25ProPreviewTTS ModelGemini31FlashTTSPreview = protocol.ModelGemini31FlashTTSPreview ModelGemini25FlashImage = protocol.ModelGemini25FlashImage ModelGemini3ProImage = protocol.ModelGemini3ProImage ModelGemini31FlashImage = protocol.ModelGemini31FlashImage ModelGemini31FlashLiteImage = protocol.ModelGemini31FlashLiteImage ModelGeminiEmbedding2 = protocol.ModelGeminiEmbedding2 )
Variables ¶
This section is empty.
Functions ¶
func NewChatCompletions ¶ added in v0.13.0
func NewChatCompletions(ctx context.Context, config ChatCompletionsConfig) (*corechat.StreamModel, error)
Types ¶
type Chat ¶
type Chat struct {
// contains filtered or unexported fields
}
Chat wraps this provider's protocol implementation so the wire type stays unexported. Callers depend on the Core modality contract, which lets the protocol change without breaking this module's public surface.
type ChatCompletionsConfig ¶ added in v0.13.0
type ChatCompletionsConfig struct {
APIKey string
DefaultOptions corechat.Options
BaseURL string
HTTPClient *http.Client
}
func (ChatCompletionsConfig) Validate ¶ added in v0.13.0
func (c ChatCompletionsConfig) Validate() error
type ChatConfig ¶
type ChatConfig struct {
APIKey string
DefaultOptions corechat.Options
BaseURL string
HTTPClient *http.Client
}
func (ChatConfig) Validate ¶
func (c ChatConfig) Validate() error
type EmbeddingModel ¶
type EmbeddingModel struct {
// contains filtered or unexported fields
}
EmbeddingModel wraps this provider's protocol implementation so the wire type stays unexported. Callers depend on the Core modality contract, which lets the protocol change without breaking this module's public surface.
func NewEmbeddingModel ¶
func NewEmbeddingModel(ctx context.Context, config EmbeddingModelConfig) (*EmbeddingModel, error)
type EmbeddingModelConfig ¶
type EmbeddingModelConfig struct {
APIKey string
DefaultOptions embedding.Options
BaseURL string
HTTPClient *http.Client
}
func (EmbeddingModelConfig) Validate ¶
func (e EmbeddingModelConfig) Validate() error
type ImageAspectRatio ¶ added in v0.60.0
type ImageAspectRatio string
const ( ImageAspectRatio1x1 ImageAspectRatio = "1:1" ImageAspectRatio2x3 ImageAspectRatio = "2:3" ImageAspectRatio3x2 ImageAspectRatio = "3:2" ImageAspectRatio3x4 ImageAspectRatio = "3:4" ImageAspectRatio4x3 ImageAspectRatio = "4:3" ImageAspectRatio4x5 ImageAspectRatio = "4:5" ImageAspectRatio5x4 ImageAspectRatio = "5:4" ImageAspectRatio9x16 ImageAspectRatio = "9:16" ImageAspectRatio16x9 ImageAspectRatio = "16:9" ImageAspectRatio21x9 ImageAspectRatio = "21:9" ImageAspectRatio1x8 ImageAspectRatio = "1:8" ImageAspectRatio8x1 ImageAspectRatio = "8:1" ImageAspectRatio1x4 ImageAspectRatio = "1:4" ImageAspectRatio4x1 ImageAspectRatio = "4:1" )
type ImageDelivery ¶ added in v0.60.0
type ImageDelivery string
const ( ImageDeliveryInline ImageDelivery = "inline" ImageDeliveryURI ImageDelivery = "uri" )
type ImageGenerationOptions ¶
type ImageGenerationOptions struct {
AspectRatio ImageAspectRatio `json:"aspect_ratio,omitempty"`
ImageSize ImageSize `json:"image_size,omitempty"`
Delivery ImageDelivery `json:"delivery,omitempty"`
PreviousInteractionID string `json:"previous_interaction_id,omitempty"`
Store *bool `json:"store,omitzero"`
ThinkingLevel ImageThinkingLevel `json:"thinking_level,omitempty"`
ThinkingSummaries ImageThinkingSummaryMode `json:"thinking_summaries,omitempty"`
ServiceTier ImageServiceTier `json:"service_tier,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
InputImages []*media.Media `json:"input_images,omitempty"`
GoogleSearch *ImageGoogleSearchOptions `json:"google_search,omitzero"`
SafetySettings []ImageSafetySetting `json:"safety_settings,omitempty"`
}
ImageGenerationOptions carries the current Interactions API controls that do not have provider-neutral equivalents in image.Options. Store it under ImageRequestExtensionKey.
func (*ImageGenerationOptions) UnmarshalJSON ¶ added in v0.60.0
func (i *ImageGenerationOptions) UnmarshalJSON(data []byte) error
type ImageGoogleSearchOptions ¶
type ImageGoogleSearchOptions struct {
SearchTypes []ImageSearchType `json:"search_types,omitempty"`
}
type ImageModel ¶
type ImageModel struct {
// contains filtered or unexported fields
}
func NewImageModel ¶
func NewImageModel(ctx context.Context, config ImageModelConfig) (*ImageModel, error)
type ImageModelConfig ¶
type ImageModelConfig struct {
APIKey string
BaseURL string
HTTPClient *http.Client
DefaultOptions image.Options
}
func (ImageModelConfig) Validate ¶
func (i ImageModelConfig) Validate() error
type ImageSafetyCategory ¶ added in v0.60.0
type ImageSafetyCategory string
const ( ImageSafetyCategoryHateSpeech ImageSafetyCategory = "hate_speech" ImageSafetyCategoryDangerousContent ImageSafetyCategory = "dangerous_content" ImageSafetyCategoryHarassment ImageSafetyCategory = "harassment" ImageSafetyCategorySexuallyExplicit ImageSafetyCategory = "sexually_explicit" ImageSafetyCategoryImageHate ImageSafetyCategory = "image_hate" ImageSafetyCategoryImageDangerousContent ImageSafetyCategory = "image_dangerous_content" ImageSafetyCategoryImageHarassment ImageSafetyCategory = "image_harassment" ImageSafetyCategoryImageSexuallyExplicit ImageSafetyCategory = "image_sexually_explicit" ImageSafetyCategoryJailbreak ImageSafetyCategory = "jailbreak" )
type ImageSafetyMethod ¶ added in v0.60.0
type ImageSafetyMethod string
const ( ImageSafetyMethodSeverity ImageSafetyMethod = "severity" ImageSafetyMethodProbability ImageSafetyMethod = "probability" )
type ImageSafetySetting ¶
type ImageSafetySetting struct {
Type ImageSafetyCategory `json:"type"`
Threshold ImageSafetyThreshold `json:"threshold"`
Method ImageSafetyMethod `json:"method,omitempty"`
}
type ImageSafetyThreshold ¶ added in v0.60.0
type ImageSafetyThreshold string
const ( ImageSafetyThresholdBlockLowAndAbove ImageSafetyThreshold = "block_low_and_above" ImageSafetyThresholdBlockMediumAndAbove ImageSafetyThreshold = "block_medium_and_above" ImageSafetyThresholdBlockOnlyHigh ImageSafetyThreshold = "block_only_high" ImageSafetyThresholdBlockNone ImageSafetyThreshold = "block_none" ImageSafetyThresholdOff ImageSafetyThreshold = "off" )
type ImageSearchType ¶ added in v0.60.0
type ImageSearchType string
const ( ImageSearchTypeWeb ImageSearchType = "web_search" ImageSearchTypeImage ImageSearchType = "image_search" )
type ImageServiceTier ¶ added in v0.60.0
type ImageServiceTier string
const ( ImageServiceTierFlex ImageServiceTier = "flex" ImageServiceTierStandard ImageServiceTier = "standard" ImageServiceTierPriority ImageServiceTier = "priority" )
type ImageThinkingLevel ¶ added in v0.60.0
type ImageThinkingLevel string
const ( ImageThinkingLevelMinimal ImageThinkingLevel = "minimal" ImageThinkingLevelLow ImageThinkingLevel = "low" ImageThinkingLevelMedium ImageThinkingLevel = "medium" ImageThinkingLevelHigh ImageThinkingLevel = "high" )
type ImageThinkingSummaryMode ¶ added in v0.60.0
type ImageThinkingSummaryMode string
const ( ImageThinkingSummaryModeAuto ImageThinkingSummaryMode = "auto" ImageThinkingSummaryModeNone ImageThinkingSummaryMode = "none" )
type SpeechModel ¶ added in v0.41.0
type SpeechModel struct {
// contains filtered or unexported fields
}
SpeechModel wraps this provider's protocol implementation so the wire type stays unexported. Callers depend on the Core modality contract, which lets the protocol change without breaking this module's public surface.
func NewSpeechModel ¶ added in v0.41.0
func NewSpeechModel(ctx context.Context, config SpeechModelConfig) (*SpeechModel, error)
type SpeechModelConfig ¶ added in v0.41.0
type SpeechModelConfig struct {
APIKey string
DefaultOptions speech.Options
BaseURL string
HTTPClient *http.Client
// Call must fit in memory; Stream retains incremental delivery. Zero uses
// speech.DefaultMaxAudioBytes, and a negative limit is invalid.
MaxResponseBytes int64
}
func (SpeechModelConfig) Validate ¶ added in v0.41.0
func (s SpeechModelConfig) Validate() error
type StreamingSpeechModel ¶ added in v0.41.0
type StreamingSpeechModel struct {
// contains filtered or unexported fields
}
func NewStreamingSpeechModel ¶ added in v0.41.0
func NewStreamingSpeechModel(ctx context.Context, config SpeechModelConfig) (*StreamingSpeechModel, error)
type TextCounter ¶ added in v0.21.0
type TextCounter struct {
// contains filtered or unexported fields
}
TextCounter wraps this provider's protocol implementation so the wire type stays unexported. Callers depend on the Core modality contract, which lets the protocol change without breaking this module's public surface.
func NewTextCounter ¶ added in v0.21.0
func NewTextCounter(ctx context.Context, config TextCounterConfig) (*TextCounter, error)
type TextCounterConfig ¶ added in v0.21.0
func (TextCounterConfig) Validate ¶ added in v0.21.0
func (t TextCounterConfig) Validate() error
type TranscriptionModel ¶ added in v0.41.0
type TranscriptionModel struct {
// contains filtered or unexported fields
}
TranscriptionModel wraps this provider's protocol implementation so the wire type stays unexported. Callers depend on the Core modality contract, which lets the protocol change without breaking this module's public surface.
func NewTranscriptionModel ¶ added in v0.41.0
func NewTranscriptionModel(ctx context.Context, config TranscriptionModelConfig) (*TranscriptionModel, error)
func (*TranscriptionModel) Call ¶ added in v0.41.0
func (t *TranscriptionModel) Call(ctx context.Context, req *transcription.Request) (*transcription.Response, error)
type TranscriptionModelConfig ¶ added in v0.41.0
type TranscriptionModelConfig struct {
APIKey string
DefaultOptions transcription.Options
BaseURL string
HTTPClient *http.Client
}
func (TranscriptionModelConfig) Validate ¶ added in v0.41.0
func (t TranscriptionModelConfig) Validate() error
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
protocol
Package protocol implements the Google Gen AI wire protocol reused by Gemini and Vertex AI provider endpoints inside the models module.
|
Package protocol implements the Google Gen AI wire protocol reused by Gemini and Vertex AI provider endpoints inside the models module. |
|
Package vertexai exposes Google Gen AI capabilities through Vertex AI's GCP backend and Application Default Credentials.
|
Package vertexai exposes Google Gen AI capabilities through Vertex AI's GCP backend and Application Default Credentials. |