gemini

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gemini implements chat.Client for Gemini on top of the official google.golang.org/genai SDK.

Index

Constants

View Source
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

type APIKeyProvider func(ctx context.Context) (string, error)

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 New

func New(cfg Config) *Client

New creates a Gemini chat.Client. It panics when cfg.Model is empty.

func (*Client) DeleteFile added in v0.2.1

func (c *Client) DeleteFile(ctx context.Context, id string) error

DeleteFile deletes an uploaded file; id is the file URI (FileRef.ID) or the file name (files/...).

func (*Client) Info

func (c *Client) Info() chat.ModelInfo

Info returns the model info.

func (*Client) Stream

func (c *Client) Stream(ctx context.Context, req chat.Request) iter.Seq[chat.Event]

Stream sends a streaming request.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL