gemini

package
v1.8.8 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gemini implements the model_protocol adapter for the Google Gemini protocol (generateContent / streamGenerateContent).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractModelFromPath added in v1.8.8

func ExtractModelFromPath(path string) string

ExtractModelFromPath extracts the model name from a Gemini native request path of the form /v1beta/models/{model}[:action], where action is one of generateContent / streamGenerateContent / countTokens etc. The model name is the segment between the prefix and the first ":" (or the end of the path). It returns "" for paths that do not carry a model (issue #1384).

Types

type Adapter

type Adapter struct{}

Adapter is the Gemini protocol adapter. It is stateless.

func New

func New() *Adapter

New returns the Gemini protocol adapter.

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

func (a *Adapter) ExtraHeaders() map[string]string

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

func (a *Adapter) InjectAuth(outreq *bfe_http.Request, key string) error

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.

func (*Adapter) Key

func (a *Adapter) Key() string

Jump to

Keyboard shortcuts

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