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. Native chat request extensions use the SDK's camelCase JSON fields only. GenerateContent has one native decoder shared by unary and streaming calls. SDK DTOs and authentication are reused; SDK response converters and automatic continuation are not executed. HTTP extensions allow headers and timeout only. 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. 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. Native embedding extensions also use SDK camelCase fields and reject outputDimensionality; embedding.Options.Dimensions owns that value. 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 is the exception: it builds an OpenAI-compatible client and performs no I/O.
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. 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 ImageGenerationOptions
- type ImageGoogleSearchOptions
- type ImageModel
- type ImageModelConfig
- type ImageSafetySetting
- type SpeechModel
- type SpeechModelConfig
- type StreamingSpeechModel
- type TextCounter
- type TextCounterConfig
- type TranscriptionModel
- type TranscriptionModelConfig
Constants ¶
const ( Provider = "Google" DefaultBaseURL = protocol.DefaultBaseURL BaseURLOpenAI = "https://generativelanguage.googleapis.com/v1beta/openai" RequestExtensionKey = "google/request" ResponseExtensionKey = "google/response" SpeechRequestExtensionKey = "google/speech_request" SpeechResponseExtensionKey = "google/speech_response" TranscriptionRequestExtensionKey = "google/transcription_request" TranscriptionResponseExtensionKey = "google/transcription_response" EmbeddingRequestExtensionKey = "google/embedding_request" EmbeddingResponseExtensionKey = "google/embedding_response" ImageRequestExtensionKey = "google/image_request" ImageResponseExtensionKey = "google/image_response" OpenAIRequestExtensionKey = "google/openai_request" OpenAIStreamChunkExtensionKey = "google/openai_stream_chunk" 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 ImageGenerationOptions ¶
type ImageGenerationOptions struct {
AspectRatio string `json:"aspect_ratio,omitempty"`
ImageSize string `json:"image_size,omitempty"`
Delivery string `json:"delivery,omitempty"`
PreviousInteractionID string `json:"previous_interaction_id,omitempty"`
Store *bool `json:"store,omitzero"`
ThinkingLevel string `json:"thinking_level,omitempty"`
ThinkingSummaries string `json:"thinking_summaries,omitempty"`
ServiceTier string `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 Gemini Interactions controls that have no provider-neutral image option.
type ImageGoogleSearchOptions ¶
type ImageGoogleSearchOptions struct {
SearchTypes []string `json:"search_types,omitempty"`
}
type ImageModel ¶
type ImageModel struct {
// contains filtered or unexported fields
}
ImageModel 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 NewImageModel ¶
func NewImageModel(ctx context.Context, config ImageModelConfig) (*ImageModel, error)
type ImageModelConfig ¶
type ImageModelConfig struct {
APIKey string
DefaultOptions image.Options
BaseURL string
HTTPClient *http.Client
}
func (ImageModelConfig) Validate ¶
func (i ImageModelConfig) Validate() error
type ImageSafetySetting ¶
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
}
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
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. |