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 Config
Constants ¶
const ( ModelGemini3_5Flash = "gemini-3.5-flash" ModelGemini3_1ProPreview = "gemini-3.1-pro-preview" ModelGemini2_5Flash = "gemini-2.5-flash" // 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 ¶ added in v0.2.1
DeleteFile deletes an uploaded file; id is the file URI (FileRef.ID) or the file name (files/...).
func (*Client) UploadFile ¶ added in v0.2.1
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 Config ¶
type Config struct {
APIKey string
APIKeyProvider APIKeyProvider
// 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
BaseURL string
Model string
MaxInputTokens int
MaxOutputTokens int
Timeout time.Duration
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.