gemini

package
v0.35.4 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoAPIKey      = errors.New("gemini: API key is required")
	ErrInvalidModel  = errors.New("gemini: invalid model specified")
	ErrNoContent     = errors.New("gemini: no content generated")
	ErrSystemMessage = errors.New("gemini: system message must be the first message in the conversation")
	ErrEmbeddings    = errors.New("gemini: failed to generate embeddings")
)

Functions

This section is empty.

Types

type LLM

type LLM struct {
	// contains filtered or unexported fields
}

LLM implements both the Model and Embedder interfaces for Gemini.

func New

func New(ctx context.Context, opts ...Option) (*LLM, error)

New creates a new Gemini LLM client.

func (*LLM) Call

func (g *LLM) Call(ctx context.Context, prompt string, options ...llms.CallOption) (string, error)

Call is a convenience method for a single-turn conversation.

func (*LLM) EmbedDocuments added in v0.9.0

func (g *LLM) EmbedDocuments(ctx context.Context, texts []string) ([][]float32, error)

EmbedDocuments generates embeddings for a slice of texts.

func (*LLM) EmbedQueries added in v0.9.0

func (g *LLM) EmbedQueries(ctx context.Context, texts []string) ([][]float32, error)

EmbedQueries generates embeddings for multiple queries.

func (*LLM) EmbedQuery added in v0.9.0

func (g *LLM) EmbedQuery(ctx context.Context, text string) ([]float32, error)

EmbedQuery generates an embedding for a single text query.

func (*LLM) GenerateContent

func (g *LLM) GenerateContent(
	ctx context.Context,
	messages []schema.MessageContent,
	options ...llms.CallOption,
) (*schema.ContentResponse, error)

GenerateContent handles multi-turn conversations and streaming.

func (*LLM) GetDimension added in v0.9.0

func (g *LLM) GetDimension(ctx context.Context) (int, error)

GetDimension returns the embedding dimension of the model. It caches the result after the first successful call. If the first call fails, subsequent calls will retry until a successful result is obtained.

type Option

type Option func(*options)

Option is a function type for configuring the client.

func WithAPIKey

func WithAPIKey(apiKey string) Option

WithAPIKey sets the Gemini API key.

func WithEmbeddingModel added in v0.9.0

func WithEmbeddingModel(model string) Option

WithEmbeddingModel sets the embedding model name.

func WithLogger

func WithLogger(logger *slog.Logger) Option

WithLogger sets a custom logger for the client.

func WithModel

func WithModel(model string) Option

WithModel sets the generation model name.

Jump to

Keyboard shortcuts

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