Documentation
¶
Overview ¶
Package gemini implements chat.Client for Gemini on top of the official google.golang.org/genai SDK.
Index ¶
- Constants
- type APIKeyProvider
- type Client
- func (c *Client) DeleteFile(ctx context.Context, id string) error
- func (c *Client) Info() chat.ModelInfo
- func (c *Client) Stream(ctx context.Context, req chat.Request) iter.Seq[chat.Event]
- func (c *Client) UploadFile(ctx context.Context, name, mimeType string, r io.Reader, ttl time.Duration) (chat.ContentBlock, error)
- type Compat
- type Config
- type Endpoint
- type Model
Constants ¶
const (
// API is the protocol this client speaks, see chat.ModelInfo.API.
API = "gemini"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyProvider ¶
APIKeyProvider resolves the API key dynamically, for short-lived tokens.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the genai SDK.
func (*Client) DeleteFile ¶
DeleteFile deletes an uploaded file; id is the file URI (FileRef.ID) or the file name (files/...).
func (*Client) UploadFile ¶
func (c *Client) UploadFile(ctx context.Context, name, mimeType string, r io.Reader, ttl time.Duration) (chat.ContentBlock, error)
UploadFile uploads a file to the Files API and returns a media block referring to it, ready to put in a message; FileRef.ID is the file URI. It waits until the file has been processed (video can take a while). The Gemini API deletes files after 48 hours and does not take a ttl, so ttl must be 0. The returned block has no fallback: to keep the session usable after that, set its URL or data too.
type Compat ¶ added in v0.3.0
type Compat struct {
// NoThinkingLevel means only a thinking budget is accepted, not thinkingLevel (Gemini 2.x).
NoThinkingLevel bool
// NoLowThinking, NoMediumThinking and NoXHighThinking mean the model rejects that thinking level; a rejected level
// falls to the next lower one the model accepts, MINIMAL at the bottom. XHIGH is accepted only by Gemini 4 Hydrogen
// and Neon; Nano Banana 2.1 rejects LOW, and Nano Banana 2 and 2 Lite reject LOW and MEDIUM.
NoLowThinking bool
NoMediumThinking bool
NoXHighThinking bool
// NoMediaInToolResults means media embedded in function results is not accepted (Gemini 2.x);
// the media is sent as separate parts of the same message instead.
NoMediaInToolResults bool
}
Compat lists what is missing compared with the full Gemini API, as its current models speak it. The zero value lacks nothing. It is set on an Endpoint for what holds for every model of the service and on a Model for what holds for that model only; a Client lacks whatever either of them lacks.
type Config ¶
type Config struct {
// Endpoint is the service the client talks to: the zero value is Google's Gemini API, and Vertex AI or a
// compatible endpoint is described by filling one in.
Endpoint Endpoint
// Model is the model the client talks to; its Name must be set. Another model is another Client.
Model Model
APIKey string
APIKeyProvider APIKeyProvider
Timeout time.Duration
// MaxRetries is how many times a failed request is retried (408, 429 and 5xx); 0 leaves the SDK's default,
// which is not to retry.
MaxRetries int
Headers map[string]string
HTTPClient *http.Client
// ImageGeneration means the model can generate images (such as the gemini-*-image models):
// requests ask for both TEXT and IMAGE output, and generated images in history are replayed as is.
ImageGeneration bool
// FileScope names the Files API store this key reads, see chat.FileRef.Scope. It defaults to "gemini" for the official
// Gemini API endpoint and to none on Vertex (which has no Files API; use gs:// URLs) or a custom BaseURL.
FileScope string
// HTTPHooks are debugging hooks at the raw HTTP layer.
HTTPHooks chat.HTTPHooks
}
Config configures the Gemini Client.
type Endpoint ¶ added in v0.3.0
type Endpoint struct {
// Provider names the vendor in messages, usage and errors; "gemini" by default.
Provider string
// BaseURL is the address of the API; empty for Google's.
BaseURL string
// Vertex means the API key belongs to Vertex AI (express mode) and requests go to the Vertex endpoint;
// by default the Gemini API (generativelanguage.googleapis.com) is used.
// Full Vertex access based on project, region and credentials is not provided yet.
Vertex bool
// Compat says where every model of the endpoint differs from the full protocol; see Compat.
Compat Compat
}
Endpoint is a service that speaks the Gemini API: Google's Gemini API itself (the zero value), Vertex AI or a compatible one. It says where the service is and how to reach it; the model served from it is described by Model.
type Model ¶ added in v0.3.0
type Model struct {
// Name is the model name sent to the API.
Name string
// MaxInputTokens is the context limit of the model; 0 declares none, and the runner then never compacts history.
MaxInputTokens int
// MaxOutputTokens is the output limit of the model; 0 declares none. It is only reported by Info: a request
// that sets no MaxTokens sends no limit.
MaxOutputTokens int
// Compat says where this model differs from the full protocol; see Compat.
Compat Compat
}
Model is the model a Client talks to. Beyond the zero value only Name must be set: a model is taken to support the whole protocol, and one that does not says what it lacks in Compat.