Documentation
¶
Index ¶
- Constants
- func NewHistory(contents []*genai.Content) (*gollem.History, error)
- func ToContents(h *gollem.History) ([]*genai.Content, error)
- type Client
- type Option
- func WithContentType(contentType gollem.ContentType) Option
- func WithEmbeddingModel(model string) Option
- func WithGoogleCloudOptions(opts ...option.ClientOption) Option
- func WithMaxTokens(maxTokens int32) Option
- func WithModel(model string) Option
- func WithStopSequences(stopSequences []string) Option
- func WithSystemPrompt(prompt string) Option
- func WithTemperature(temp float32) Option
- func WithThinkingBudget(budget int32) Option
- func WithThinkingLevel(level genai.ThinkingLevel) Option
- func WithTopK(topK float32) Option
- func WithTopP(topP float32) Option
- type Session
- func (s *Session) AppendHistory(h *gollem.History) error
- func (s *Session) CountToken(ctx context.Context, input ...gollem.Input) (int, error)
- func (s *Session) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
- func (s *Session) GenerateContent(ctx context.Context, input ...gollem.Input) (*gollem.Response, error)deprecated
- func (s *Session) GenerateStream(ctx context.Context, input ...gollem.Input) (<-chan *gollem.Response, error)deprecated
- func (s *Session) History() (*gollem.History, error)
- func (s *Session) Stream(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (<-chan *gollem.Response, error)
- type StreamResponse
Constants ¶
const ( // DefaultModel is the Gemini model used when no WithModel option is given. // gemini-3.5-flash is chosen so the default ThinkingLevelLow configuration // is accepted; Gemini 2.x callers should pass WithModel + WithThinkingBudget. DefaultModel = "gemini-3.5-flash" DefaultEmbeddingModel = "text-embedding-004" )
Variables ¶
This section is empty.
Functions ¶
func NewHistory ¶
NewHistory creates gollem.History from Gemini contents
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the Gemini API. It provides methods to interact with Google's Gemini models.
func New ¶
New creates a new client for the Gemini API. It requires a project ID and location, and can be configured with additional options.
The default thinking configuration is ThinkingLevelLow, which works with Gemini 3.x models. Callers using Gemini 2.x models that do not support thinking_level should override this via WithThinkingBudget.
func (*Client) GenerateEmbedding ¶
func (c *Client) GenerateEmbedding(ctx context.Context, dimension int, input []string) ([][]float64, error)
GenerateEmbedding generates embeddings for the given input texts.
func (*Client) NewSession ¶
func (c *Client) NewSession(ctx context.Context, options ...gollem.SessionOption) (gollem.Session, error)
NewSession creates a new session for the Gemini API. It converts the provided tools to Gemini's tool format and initializes a new chat session.
type Option ¶
type Option func(*Client)
Option is a configuration option for the Gemini client.
func WithContentType ¶
func WithContentType(contentType gollem.ContentType) Option
WithContentType sets the content type for text generation. This determines the format of the generated content.
func WithEmbeddingModel ¶
WithEmbeddingModel sets the model to use for embeddings. Default: "text-embedding-004"
func WithGoogleCloudOptions ¶
func WithGoogleCloudOptions(opts ...option.ClientOption) Option
WithGoogleCloudOptions sets additional Google Cloud options. These can include authentication credentials, endpoint overrides, etc.
func WithMaxTokens ¶
WithMaxTokens sets the maximum number of tokens to generate.
func WithStopSequences ¶
WithStopSequences sets the stop sequences for text generation.
func WithSystemPrompt ¶
WithSystemPrompt sets the system prompt to use for chat completions.
func WithTemperature ¶
WithTemperature sets the temperature parameter for text generation. Controls randomness in output generation. Range: 0.0 to 2.0 Default: 1.0
func WithThinkingBudget ¶
WithThinkingBudget sets the thinking budget for text generation. A value of -1 enables automatic thinking budget allocation.
Gemini 3.x deprecates thinking_budget in favor of thinking_level; prefer WithThinkingLevel for those models. The two options are mutually exclusive at the API layer, so calling this clears any thinking level previously set.
func WithThinkingLevel ¶
func WithThinkingLevel(level genai.ThinkingLevel) Option
WithThinkingLevel sets the thinking level for text generation. Introduced in Gemini 3.x as the replacement for WithThinkingBudget.
Valid values: genai.ThinkingLevelMinimal, ThinkingLevelLow, ThinkingLevelMedium, ThinkingLevelHigh.
Vertex AI rejects requests that carry both thinking_budget and thinking_level (HTTP 400), so calling this clears any thinking budget previously set, including the zero-value default established by gemini.New.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is a session for the Gemini chat. It maintains the conversation state and handles message generation.
func (*Session) CountToken ¶
CountToken calculates the total number of tokens for the given inputs, including system prompt, history messages, and new inputs. This is useful for estimating API costs and checking token limits before making actual API calls.
func (*Session) Generate ¶
func (s *Session) Generate(ctx context.Context, input []gollem.Input, opts ...gollem.GenerateOption) (*gollem.Response, error)
Generate generates content based on the input with optional per-call overrides.
type StreamResponse ¶
type StreamResponse struct {
Resp *genai.GenerateContentResponse
Err error
}
StreamResponse wraps the response and error from streaming