Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIRejectionError ¶ added in v1.137.0
type APIRejectionError struct {
genai.APIError
Category RequestRejectionCategory
}
APIRejectionError adds a fixed category hint and a bounded, sanitized SDK message. Message may contain a raw response body in SDK fallback paths; Details is not inspected or surfaced. Retaining message context supports phrase-based overflow/retry classification and useful authentication errors.
func (*APIRejectionError) Error ¶ added in v1.137.0
func (e *APIRejectionError) Error() string
func (*APIRejectionError) Unwrap ¶ added in v1.137.0
func (e *APIRejectionError) Unwrap() error
type Client ¶
Client represents a Gemini client wrapper It implements the provider.Provider interface
func NewClient ¶
func NewClient(ctx context.Context, cfg *latest.ModelConfig, env environment.Provider, opts ...options.Opt) (*Client, error)
NewClient creates a new Gemini client from the provided configuration
func (*Client) CreateChatCompletionStream ¶
func (c *Client) CreateChatCompletionStream( ctx context.Context, messages []chat.Message, requestTools []tools.Tool, ) (chat.MessageStream, error)
CreateChatCompletionStream creates a streaming chat completion request
func (*Client) Rerank ¶
func (c *Client) Rerank(ctx context.Context, query string, documents []types.Document, criteria string) ([]float64, error)
Rerank scores documents by relevance to the query using Gemini's structured output feature. It returns relevance scores in the same order as input documents.
type ImageOutputRequestIncompatibleError ¶ added in v1.137.0
type ImageOutputRequestIncompatibleError struct {
// Incompatibilities is always non-empty. Its values are the fixed enum
// above — never provider text, tool names/schemas, or prompt content.
Incompatibilities []imageOutputIncompatibility
ToolCallSupport modelinfo.ToolCallSupport
}
ImageOutputRequestIncompatibleError is returned before any provider dispatch when a request to an image-output-capable model (output_capabilities.image: true) combines custom function tools (with their required ToolConfig) or structured output. Gemini server-side built-in tools remain allowed. Title generation and compaction are always text-only and bypass this guard.
func (*ImageOutputRequestIncompatibleError) Error ¶ added in v1.137.0
func (e *ImageOutputRequestIncompatibleError) Error() string
type RequestRejectionCategory ¶ added in v1.137.0
type RequestRejectionCategory string
RequestRejectionCategory classifies fixed field-name keywords and general unsupported-feature phrases in the SDK message. It does not inspect local request content or structured APIError details.
const ( // RejectionMissingResponseModalities: the request didn't declare a // response modality (e.g. IMAGE) that the model needed for this reply. RejectionMissingResponseModalities RequestRejectionCategory = "missing_response_modalities" // RejectionIncompatibleFunctionOrBuiltinTools: the combination of // custom function tools and/or built-in tools (Search, Maps, Code // Execution) enabled for the request isn't supported together. RejectionIncompatibleFunctionOrBuiltinTools RequestRejectionCategory = "incompatible_function_or_builtin_tools" // RejectionIncompatibleToolConfig: the ToolConfig/function-calling mode // isn't supported for this request or model. RejectionIncompatibleToolConfig RequestRejectionCategory = "incompatible_tool_config" // RejectionStructuredOutputConflict: a structured-output option // (response MIME type/schema) conflicts with another request option. RejectionStructuredOutputConflict RequestRejectionCategory = "structured_output_conflict" // RejectionModelOrAPICapabilityMismatch: the request used a feature // (e.g. thinking configuration) the target model or API surface // doesn't support at all. RejectionModelOrAPICapabilityMismatch RequestRejectionCategory = "model_or_api_capability_mismatch" // RejectionOther covers any other provider rejection, including ones // with no message to classify against (Gemini sometimes returns a 400 // with an empty body). RejectionOther RequestRejectionCategory = "other_provider_rejection" )
type RequestShape ¶ added in v1.137.0
type RequestShape struct {
// ResponseModalitiesSet reports whether the request specified any
// response modalities at all. ResponseModalities holds the normalized
// (trimmed, upper-cased, de-duplicated) values, e.g. ["TEXT", "IMAGE"].
ResponseModalitiesSet bool
ResponseModalities []string
// BuiltInToolKinds lists which fixed-kind built-in tools (google_search,
// google_maps, code_execution) were enabled. BuiltInToolCount is
// len(BuiltInToolKinds).
BuiltInToolKinds []string
BuiltInToolCount int
// FunctionToolCount is the number of caller-supplied (MCP/custom)
// function tools converted for this request. Never their names,
// descriptions, or parameter schemas.
FunctionToolCount int
// HasToolConfig, FunctionCallingMode, and ServerSideToolInvocation
// describe genai.ToolConfig without exposing AllowedFunctionNames.
HasToolConfig bool
FunctionCallingMode string
ServerSideToolInvocation bool
// StructuredOutputPresent reports whether a structured-output response
// (MIME type and/or schema) was requested, never the schema itself.
StructuredOutputPresent bool
// ThinkingConfigSet and NoThinkingRequested describe the thinking
// configuration shape without exposing budgets or levels (already safe
// enums/numbers, but kept out to keep this struct minimal).
ThinkingConfigSet bool
NoThinkingRequested bool
// APISurface classifies the backend/transport: "gemini_api", "vertex_ai",
// or "gateway".
APISurface string
// OutputCapabilityKnown records whether the capability was resolved from an
// explicit configuration override instead of the catalogue.
OutputCapabilityKnown bool
OutputCapabilityEnabled bool
}
RequestShape summarizes configs built by this provider without prompt, schema, payload, or credential fields. Modality, mode, and surface strings come from the request builder; this type does not validate arbitrary caller input.
func (RequestShape) LogAttrs ¶ added in v1.137.0
func (s RequestShape) LogAttrs() []any
LogAttrs renders the shape as a flat slog key/value list.
type StreamAdapter ¶
type StreamAdapter struct {
// contains filtered or unexported fields
}
StreamAdapter adapts the Gemini streaming iterator to chat.MessageStream
func NewStreamAdapter ¶
func NewStreamAdapter(iter func(func(*genai.GenerateContentResponse, error) bool), model string, trackUsage bool) *StreamAdapter
NewStreamAdapter constructs a StreamAdapter from Gemini's iterator
func (*StreamAdapter) Recv ¶
func (g *StreamAdapter) Recv() (chat.MessageStreamResponse, error)
Recv gets the next Gemini content chunk