Documentation
¶
Index ¶
- func GetGroundMetadata(m *schema.Message) *genai.GroundingMetadata
- func GetInputVideoMetaData(part *schema.MessageInputVideo) *genai.VideoMetadata
- func GetThoughtSignatureFromExtra(extra map[string]any) ([]byte, bool)
- func GetVideoMetaData(part *schema.ChatMessageVideoURL) *genai.VideoMetadatadeprecated
- func SetInputVideoMetaData(part *schema.MessageInputVideo, metaData *genai.VideoMetadata)
- func SetMultiModalToolResultDisplayName(input schema.MessageInputPart, displayName string) schema.MessageInputPart
- func SetVideoMetaData(part *schema.ChatMessageVideoURL, metaData *genai.VideoMetadata)deprecated
- func WithCachedContentName(name string) model.Option
- func WithImageConfig(cfg *genai.ImageConfig) model.Option
- func WithLogprobs(k int32) model.Option
- func WithResponseJSONSchema(s *jsonschema.Schema) model.Option
- func WithResponseLogprobs(enable bool) model.Option
- func WithResponseModalities(m []GeminiResponseModality) model.Option
- func WithThinkingConfig(t *genai.ThinkingConfig) model.Option
- func WithTopK(k int32) model.Option
- type CacheConfig
- type ChatModel
- func (cm *ChatModel) BindForcedTools(tools []*schema.ToolInfo) error
- func (cm *ChatModel) BindTools(tools []*schema.ToolInfo) error
- func (cm *ChatModel) CreatePrefixCache(ctx context.Context, prefixMsgs []*schema.Message, opts ...model.Option) (*genai.CachedContent, error)
- func (cm *ChatModel) Generate(ctx context.Context, input []*schema.Message, opts ...model.Option) (message *schema.Message, err error)
- func (cm *ChatModel) GetType() string
- func (cm *ChatModel) IsCallbacksEnabled() bool
- func (cm *ChatModel) Stream(ctx context.Context, input []*schema.Message, opts ...model.Option) (result *schema.StreamReader[*schema.Message], err error)
- func (cm *ChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
- type Config
- type GeminiResponseModality
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetGroundMetadata ¶
func GetGroundMetadata(m *schema.Message) *genai.GroundingMetadata
func GetInputVideoMetaData ¶
func GetInputVideoMetaData(part *schema.MessageInputVideo) *genai.VideoMetadata
func GetThoughtSignatureFromExtra ¶
GetThoughtSignatureFromExtra tries to read thought_signature from an Extra map.
thought_signature should be read from:
- message.AssistantGenMultiContent[i].Extra: thought_signature on each generated output part
- toolCall.Extra: thought_signature on toolCall
- message.Extra: thought_signature on generated content (legacy, only used when message.AssistantGenMultiContent are absent)
The returned bool indicates whether thought_signature key exists in Extra. The returned []byte is the thought signature if available
func GetVideoMetaData
deprecated
func GetVideoMetaData(part *schema.ChatMessageVideoURL) *genai.VideoMetadata
Deprecated: use GetInputVideoMetaData instead.
func SetInputVideoMetaData ¶
func SetInputVideoMetaData(part *schema.MessageInputVideo, metaData *genai.VideoMetadata)
func SetMultiModalToolResultDisplayName ¶
func SetMultiModalToolResultDisplayName(input schema.MessageInputPart, displayName string) schema.MessageInputPart
func SetVideoMetaData
deprecated
func SetVideoMetaData(part *schema.ChatMessageVideoURL, metaData *genai.VideoMetadata)
Deprecated: use SetInputVideoMetaData instead.
func WithCachedContentName ¶
WithCachedContentName the name of the content cached to use as context to serve the prediction. Format: cachedContents/{cachedContent}
func WithImageConfig ¶
func WithImageConfig(cfg *genai.ImageConfig) model.Option
WithImageConfig sets the image generation configuration. Note: an error will be returned for a model that does not support the configuration options. Optional.
func WithLogprobs ¶
WithLogprobs sets the number of top candidate tokens to return the log probabilities for at each generation step. Only takes effect when ResponseLogprobs is enabled.
func WithResponseJSONSchema ¶
func WithResponseJSONSchema(s *jsonschema.Schema) model.Option
func WithResponseLogprobs ¶
WithResponseLogprobs sets whether to return the log probabilities of the tokens chosen by the model at each step. This overrides Config.ResponseLogprobs.
func WithResponseModalities ¶
func WithResponseModalities(m []GeminiResponseModality) model.Option
func WithThinkingConfig ¶
func WithThinkingConfig(t *genai.ThinkingConfig) model.Option
Types ¶
type CacheConfig ¶
type CacheConfig struct {
// TTL specifies how long cached resources remain valid (now + TTL).
TTL time.Duration `json:"ttl,omitempty"`
// ExpireTime sets the absolute expiration timestamp for cached resources.
ExpireTime time.Time `json:"expireTime,omitempty"`
}
CacheConfig controls prefix cache settings for the model.
type ChatModel ¶
type ChatModel struct {
// contains filtered or unexported fields
}
func NewChatModel ¶
NewChatModel creates a new Gemini chat model instance
Parameters:
- ctx: The context for the operation
- cfg: Configuration for the Gemini model
Returns:
- model.ChatModel: A chat model interface implementation
- error: Any error that occurred during creation
Example:
model, err := gemini.NewChatModel(ctx, &gemini.Config{
Client: client,
Model: "gemini-pro",
})
func (*ChatModel) BindForcedTools ¶
func (*ChatModel) CreatePrefixCache ¶
func (cm *ChatModel) CreatePrefixCache(ctx context.Context, prefixMsgs []*schema.Message, opts ...model.Option) ( *genai.CachedContent, error)
CreatePrefixCache assembles inputs the same as Generate/Stream and writes the final system instruction, tools, and messages into a reusable prefix cache.
func (*ChatModel) IsCallbacksEnabled ¶
type Config ¶
type Config struct {
// Client is the Gemini API client instance
// Required for making API calls to Gemini
Client *genai.Client
// Model specifies which Gemini model to use
// Examples: "gemini-pro", "gemini-pro-vision", "gemini-1.5-flash"
Model string
// MaxTokens limits the maximum number of tokens in the response
// Optional. Example: maxTokens := 100
MaxTokens *int
// Temperature controls randomness in responses
// Range: [0.0, 1.0], where 0.0 is more focused and 1.0 is more creative
// Optional. Example: temperature := float32(0.7)
Temperature *float32
// TopP controls diversity via nucleus sampling
// Range: [0.0, 1.0], where 1.0 disables nucleus sampling
// Optional. Example: topP := float32(0.95)
TopP *float32
// TopK controls diversity by limiting the top K tokens to sample from
// Optional. Example: topK := int32(40)
TopK *int32
// ResponseJSONSchema defines the structure for JSON responses
// Optional. Used when you want structured output in JSON format
ResponseJSONSchema *jsonschema.Schema
// EnableCodeExecution allows the model to execute code
// Warning: Be cautious with code execution in production
// Optional. Default: false
EnableCodeExecution bool
EnableGoogleSearch *genai.GoogleSearch
EnableGoogleSearchRetrieval *genai.GoogleSearchRetrieval
EnableComputerUse *genai.ComputerUse
EnableURLContext *genai.URLContext
EnableFileSearch *genai.FileSearch
EnableGoogleMaps *genai.GoogleMaps
// SafetySettings configures content filtering for different harm categories
// Controls the model's filtering behavior for potentially harmful content
// Optional.
SafetySettings []*genai.SafetySetting
ThinkingConfig *genai.ThinkingConfig
// ImageConfig is the image generation configuration.
// Note: an error will be returned if this field is set for a model that does not support the configuration options.
// Optional.
ImageConfig *genai.ImageConfig
// ResponseModalities specifies the modalities the model can return.
// Optional.
ResponseModalities []GeminiResponseModality
MediaResolution genai.MediaResolution
// Cache controls prefix cache settings for the model.
// Optional. used to CreatePrefixCache for reused inputs.
Cache *CacheConfig
// ResponseLogprobs controls whether to return the log probabilities of the
// tokens that were chosen by the model at each step.
// When enabled, response logprobs are populated in Message.ResponseMeta.LogProbs.
// Optional. Default: false. Configure top-K candidates via Logprobs.
ResponseLogprobs bool
// Logprobs specifies the number of top candidate tokens to return the
// log probabilities for at each generation step.
// Optional. Only takes effect when ResponseLogprobs is true.
Logprobs *int32
}
Config contains the configuration options for the Gemini model
type GeminiResponseModality ¶
type GeminiResponseModality string
const ( GeminiResponseModalityText GeminiResponseModality = "TEXT" GeminiResponseModalityImage GeminiResponseModality = "IMAGE" GeminiResponseModalityAudio GeminiResponseModality = "AUDIO" )
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
generate
command
|
|
|
generate_with_image
command
|
|
|
generate_with_prefix_cache
command
|
|
|
image_generate
command
|
|
|
intent_tool
command
|
|
|
react
command
|
|
|
stream
command
|