Documentation
¶
Overview ¶
Package gemini implements the Gemini generateContent–compatible HTTP frontend.
v1 subset vs vendor spec (cross-check) ¶
Spec: https://ai.google.dev/gemini-api/docs , https://ai.google.dev/api/all-methods , https://ai.google.dev/gemini-api/docs/text-generation
| Area | v1 status | Tests | |-------------------|------------|-------| | POST …:generateContent / :streamGenerateContent | Supported | path_test.go, integration_test.go | | contents, systemInstruction | Supported | decode_test.go | | generationConfig, tools, toolConfig | Supported (decode) | decode_test.go | | functionCall on response | Supported (encode) | encode_test.go, integration_test.go | | safetySettings, cachedContent, … | Out of scope | — |
Index ¶
- Constants
- func ModelFromCall(c *lipapi.Call) string
- func Mount(mux *http.ServeMux, opts lipsdk.FrontendMountOptions) error
- func ParseGenerateContentPath(urlPath string) (model string, stream bool, ok bool)
- func RouteClaims(ownerID string) ([]httpcontract.RouteClaim, error)
- func WriteErrorJSON(w http.ResponseWriter, status int, message string) error
- func WriteErrorJSONWithStatus(w http.ResponseWriter, status int, message, googleStatus string) error
- func WriteNonStreamJSON(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, ...) error
- func WriteStreamSSE(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, ...) error
- type Config
- type DecodeOptions
- type DecodedGenerate
- type EncodeOptions
- type Handler
- type RouteDescriptor
- type WireErrors
- func (WireErrors) WriteAdmissionReject(w http.ResponseWriter, d decodeqos.Decision) error
- func (WireErrors) WriteBodyTooLarge(w http.ResponseWriter) error
- func (WireErrors) WriteEncodeFailed(w http.ResponseWriter) error
- func (WireErrors) WriteExecuteError(w http.ResponseWriter, out execerr.Outcome) error
- func (WireErrors) WriteExecutorNotConfigured(w http.ResponseWriter) error
- func (WireErrors) WriteInvalidJSON(w http.ResponseWriter) error
- func (WireErrors) WriteInvalidRequest(w http.ResponseWriter) error
- func (WireErrors) WritePreflightCanceled(w http.ResponseWriter) error
- func (WireErrors) WriteReadBodyFailed(w http.ResponseWriter) error
Constants ¶
const HeaderRouteSelector = routeselect.HeaderRouteSelector
const ID = "gemini"
ID is the reserved plugin identifier for the Gemini frontend.
Variables ¶
This section is empty.
Functions ¶
func ModelFromCall ¶
ModelFromCall returns the wire model string stored during decode.
func Mount ¶
func Mount(mux *http.ServeMux, opts lipsdk.FrontendMountOptions) error
Mount registers the Gemini generateContent-compatible handler on mux.
func ParseGenerateContentPath ¶
ParseGenerateContentPath extracts model id and streaming mode from a Gemini REST path (e.g. /v1beta/models/gemini-2.0-flash:generateContent or …:streamGenerateContent?alt=sse).
func RouteClaims ¶
func RouteClaims(ownerID string) ([]httpcontract.RouteClaim, error)
RouteClaims returns normalized ownership claims; MountPattern is intentionally not exposed through this compatibility projection.
func WriteErrorJSON ¶
func WriteErrorJSON(w http.ResponseWriter, status int, message string) error
WriteErrorJSON writes a Google-style JSON error for generateContent failures. Status strings are derived from the HTTP status code.
func WriteErrorJSONWithStatus ¶
func WriteErrorJSONWithStatus(w http.ResponseWriter, status int, message, googleStatus string) error
WriteErrorJSONWithStatus writes a Google-style JSON error with an explicit RPC status string.
func WriteNonStreamJSON ¶
func WriteNonStreamJSON(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, es lipapi.EventStream, opts EncodeOptions) error
WriteNonStreamJSON encodes a completed canonical stream as a generateContent JSON body.
func WriteStreamSSE ¶
func WriteStreamSSE(ctx context.Context, w http.ResponseWriter, call *lipapi.Call, es lipapi.EventStream, opts EncodeOptions) error
WriteStreamSSE emits Gemini stream chunks incrementally from the canonical stream.
Types ¶
type Config ¶
type Config = frontendconfig.Config
type DecodeOptions ¶
type DecodeOptions struct {
// RouteSelector is required (e.g. "stub:gemini-2.0-flash"); usually from X-LIP-Route header.
RouteSelector string
// Model is taken from the URL path (…/models/{model}:generateContent); must be non-empty.
Model string
// Stream is true when the request targets :streamGenerateContent.
Stream bool
Headers http.Header
}
DecodeOptions configures decoding of a generateContent request body.
type DecodedGenerate ¶
DecodedGenerate is the result of decoding a generateContent JSON body.
func DecodeGenerateContentRequest ¶
func DecodeGenerateContentRequest(body []byte, opts DecodeOptions) (*DecodedGenerate, error)
DecodeGenerateContentRequest maps a Gemini generateContent JSON body into a canonical call.
type EncodeOptions ¶
type EncodeOptions struct {
ExposeLipUsageExtensions bool
}
EncodeOptions controls optional encoding tweaks.
type Handler ¶
type Handler struct {
Exec lipsdk.ExecutorView
// DefaultRouteSelector is used when HeaderRouteSelector is absent.
DefaultRouteSelector string
// RoutePrefixes are backend route-selector prefixes accepted from URL model.
RoutePrefixes routeselect.PrefixSet
MaxRequestBodyBytes int64
Log *slog.Logger
TrafficPorts traffic.PortBundle
DecodeAdmission lipsdk.DecodeAdmission
PreRequestKeepalive lipsdk.FrontendKeepaliveConfig
Config Config
HTTPHeaders lipsdk.HTTPHeaders
StreamKeepaliveInterval time.Duration
// contains filtered or unexported fields
}
Handler wires HTTP POST …/models/{model}:generateContent (and stream variant) to decode → executor → encode.
type RouteDescriptor ¶
type RouteDescriptor struct {
MountPattern string
Claim httpcontract.RouteClaim
}
RouteDescriptor keeps the raw ServeMux mount pattern separate from the normalized route claim used by ownership and diagnostics.
func RouteDescriptors ¶
func RouteDescriptors(ownerID string) ([]RouteDescriptor, error)
RouteDescriptors describes the routes Mount registers for one frontend owner.
type WireErrors ¶
type WireErrors struct{}
WireErrors implements frontendpipe.WireErrors for Gemini generateContent errors.
func (WireErrors) WriteAdmissionReject ¶
func (WireErrors) WriteAdmissionReject(w http.ResponseWriter, d decodeqos.Decision) error
func (WireErrors) WriteBodyTooLarge ¶
func (WireErrors) WriteBodyTooLarge(w http.ResponseWriter) error
func (WireErrors) WriteEncodeFailed ¶
func (WireErrors) WriteEncodeFailed(w http.ResponseWriter) error
func (WireErrors) WriteExecuteError ¶
func (WireErrors) WriteExecuteError(w http.ResponseWriter, out execerr.Outcome) error
func (WireErrors) WriteExecutorNotConfigured ¶
func (WireErrors) WriteExecutorNotConfigured(w http.ResponseWriter) error
func (WireErrors) WriteInvalidJSON ¶
func (WireErrors) WriteInvalidJSON(w http.ResponseWriter) error
func (WireErrors) WriteInvalidRequest ¶
func (WireErrors) WriteInvalidRequest(w http.ResponseWriter) error
func (WireErrors) WritePreflightCanceled ¶
func (WireErrors) WritePreflightCanceled(w http.ResponseWriter) error
func (WireErrors) WriteReadBodyFailed ¶
func (WireErrors) WriteReadBodyFailed(w http.ResponseWriter) error