Documentation
¶
Index ¶
- Constants
- func New(ctx context.Context, settings chat.Settings, opts ...Option) (chat.ChatClient, error)
- type Gemini
- func (g *Gemini) Add(_ context.Context, prompt string, media ...chat.Media) error
- func (g *Gemini) AddCached(ctx context.Context, prompt string, media ...chat.Media) error
- func (g *Gemini) ApplyPolicyNow(ctx context.Context, policy chat.HistoryPolicy) (int, error)
- func (g *Gemini) Ask(ctx context.Context, question string, target any, media ...chat.Media) error
- func (g *Gemini) Chat(ctx context.Context, prompt string, media ...chat.Media) (string, error)
- func (g *Gemini) History() chat.History
- func (g *Gemini) Model() string
- func (g *Gemini) Provider() chat.Provider
- func (g *Gemini) Restore(snapshot *chat.Snapshot) error
- func (g *Gemini) Save() (*chat.Snapshot, error)
- func (g *Gemini) SetTools(tools []chat.Tool) error
- func (g *Gemini) StreamChat(ctx context.Context, prompt string, callback chat.StreamCallback, ...) (string, error)
- func (g *Gemini) SupportsEffort()
- func (g *Gemini) SupportsSampling()
- func (g *Gemini) SupportsStateless()
- type Option
Constants ¶
const ( EnvCloudProject = "GOOGLE_CLOUD_PROJECT" EnvCloudLocation = "GOOGLE_CLOUD_LOCATION" )
EnvCloudProject and EnvCloudLocation are the standard Google Cloud variables this module falls back to when Config.Project or Config.Location is empty. Explicit configuration wins; these exist so a developer with a working gcloud environment does not have to restate it. See spec 0017 D7.
const EnvGeminiKey = "GEMINI_API_KEY"
EnvGeminiKey is the well-known unprefixed environment variable used as the ecosystem fallback when no explicit credential is configured.
const EnvUseVertex = "GOOGLE_GENAI_USE_VERTEXAI"
EnvUseVertex is the SDK's own backend switch. This module does not honour it, and refuses to construct when it is set without Vertex having been asked for. See spec 0017 D1 and D6.
Variables ¶
This section is empty.
Functions ¶
func New ¶ added in v0.9.0
New builds a Gemini client, accepting options this provider owns. Reach for it when you need one; otherwise chat.New with the provider name does the same job through the registry.
It goes through chat.NewWithFactory rather than calling build directly, so it gets every guard chat.New applies: the endpoint is validated before credentials reach it, the logger this package logs through is resolved, provider defaults are applied, unapplicable settings are dropped and reported, and the built client is asserted able to carry what survived.
Calling build directly is what this used to do, which accepted an insecure endpoint that chat.New refuses and panicked when no Logger was set. See https://gitlab.com/phpboyscout/go/chat-openai/-/issues/2, which reports the same defect in the sibling module, and spec 0015.
Types ¶
type Gemini ¶
type Gemini struct {
chat.UsageTracker
// contains filtered or unexported fields
}
Gemini implements the chat.ChatClient interface using Google's Generative AI SDK.
func (*Gemini) AddCached ¶ added in v0.5.0
AddCached appends a user turn and arranges for it to be served from a provider-side cache on this and subsequent calls.
The cache is created lazily on first use, keyed by a hash of the content, and left to expire rather than deleted — so there is no lifecycle for a caller to manage and no cleanup path to get wrong.
func (*Gemini) ApplyPolicyNow ¶ added in v0.11.0
ApplyPolicyNow bounds the retained conversation immediately, rather than waiting for the next request to do it.
It is the sequence this client runs before every request — describe the turns, ask the policy, rewrite from the result — without the pending turn, because nothing is about to be answered. Unlike the other providers there is no system turn to hold out: Gemini keeps the system instruction in its generation config rather than in the conversation, so the transcript is conversation throughout.
A nil policy means the configured one. With none configured there is nothing to apply and it returns zero rather than an error.
func (*Gemini) Chat ¶
Chat sends a message and returns the response content, handling tool calls internally.
func (*Gemini) History ¶ added in v0.9.0
History reports the conversation this client will re-send, counting the retained turns and anything buffered by Add and not yet sent.
Known is true — this provider owns its transcript. A Gemini session is created per call from this history, so what is counted here is exactly what the next call will carry.
func (*Gemini) Model ¶ added in v0.6.0
Model implements chat.ModelIdentifier, reporting the model this client will actually use — the configured one, or the default it fell back to.
func (*Gemini) Restore ¶
Restore replaces the current conversation state with a previously saved snapshot.
func (*Gemini) StreamChat ¶
func (g *Gemini) StreamChat(ctx context.Context, prompt string, callback chat.StreamCallback, media ...chat.Media) (string, error)
StreamChat implements StreamingChatClient.
func (*Gemini) SupportsEffort ¶ added in v0.3.0
func (g *Gemini) SupportsEffort()
SupportsEffort marks Gemini as able to carry Config.Effort, via thinkingConfig.thinkingLevel.
Gemini's ladder has four rungs against the neutral five, so EffortXHigh and EffortMax clamp to its highest. The clamp is documented rather than silent: asking for more effort than a provider offers should give you its most, not an error.
func (*Gemini) SupportsSampling ¶ added in v0.3.0
func (g *Gemini) SupportsSampling()
SupportsSampling marks Gemini as able to carry Config.Temperature and TopP. Measured accepted across 0-2 and 0-1 respectively, with server-side range validation.
func (*Gemini) SupportsStateless ¶ added in v0.2.0
func (g *Gemini) SupportsStateless()
SupportsStateless marks Gemini as honouring chat.Config.Stateless.
type Option ¶ added in v0.9.0
type Option func(*options)
newGemini initializes a new Gemini chat client. Option configures a Gemini client at construction.
These are knobs only this provider understands. The core's Config carries what every provider means the same way; anything one provider owns belongs to that provider's own constructor, where the compiler can see it. See https://gitlab.com/phpboyscout/go/chat/-/wikis/specs/0011-chat-provider-conformance D10.
func WithClientConstructor ¶ added in v0.9.0
func WithClientConstructor( newClient func(context.Context, *genai.ClientConfig) (*genai.Client, error), ) Option
WithClientConstructor replaces genai.NewClient, so a test can substitute the SDK client without reaching a real endpoint.
It replaces chat.Config.GenaiNewClient, removed from the core in v0.10.0. That field was an `any` this module type-asserted at runtime, so a caller who passed the wrong shape learned about it from an error at construction. This signature is checked by the compiler, and the error path it needed is gone.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
detectmodels
command
Command detectmodels reports when Google has shipped something the module's default model does not reflect.
|
Command detectmodels reports when Google has shipped something the module's default model does not reflect. |
|
genmodels
command
Command genmodels regenerates the per-model capability table.
|
Command genmodels regenerates the per-model capability table. |