Documentation
¶
Overview ¶
Package gemini implements the model_protocol adapter for the Google Gemini protocol (generateContent / streamGenerateContent).
Index ¶
- type Adapter
- func (a *Adapter) ErrorNormalizer() utils.ErrorNormalizer
- func (a *Adapter) ExtraHeaders() map[string]string
- func (a *Adapter) ExtractUsageFields(data []byte) utils.UsageFields
- func (a *Adapter) InjectAuth(outreq *bfe_http.Request, key string) error
- func (a *Adapter) IsFinalUsageEvent(ev utils.StreamEvent) bool
- func (a *Adapter) IsStreamTerminal(ev utils.StreamEvent) bool
- func (a *Adapter) Key() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct{}
Adapter is the Gemini protocol adapter. It is stateless.
func (*Adapter) ErrorNormalizer ¶
func (a *Adapter) ErrorNormalizer() utils.ErrorNormalizer
ErrorNormalizer returns the phase-1 default normalizer (never recognizes errors, callers keep their status-code whitelist).
func (*Adapter) ExtraHeaders ¶
ExtraHeaders returns nil: the Gemini protocol needs no supplementary headers (no version header).
func (*Adapter) ExtractUsageFields ¶
func (a *Adapter) ExtractUsageFields(data []byte) utils.UsageFields
ExtractUsageFields extracts usage fields from the top-level usageMetadata object (promptTokenCount / candidatesTokenCount / cachedContentTokenCount / totalTokenCount), normalizing them into the protocol-neutral UsageFields (see utils.ParseGeminiUsageFields).
func (*Adapter) InjectAuth ¶
InjectAuth writes the upstream credential as the x-goog-api-key header. An empty key is a no-op.
func (*Adapter) IsFinalUsageEvent ¶
func (a *Adapter) IsFinalUsageEvent(ev utils.StreamEvent) bool
IsFinalUsageEvent reports whether the event data carries a usageMetadata object. Every Gemini streaming chunk carries the accumulated usage, so this is true for (intermediate and) final chunks alike; the caller's "last event wins" accumulation guarantees the final chunk's values are the ones billed, while a chunk without usageMetadata (e.g. a bare content candidate) is never mistaken for a usage event.
func (*Adapter) IsStreamTerminal ¶
func (a *Adapter) IsStreamTerminal(ev utils.StreamEvent) bool
IsStreamTerminal always returns false: Gemini streams (streamGenerateContent) carry no SSE termination event; the response ends at HTTP stream EOF, which the callers already handle as the completion fallback.