google

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package google adapts the Google Generative AI API to cogito.LLM.

cogito speaks OpenAI Chat Completions natively; Google Gemini does not. This adapter follows the same pattern as the Anthropic adapter: translate openai.ChatCompletionRequest → Gemini generateContent, parse the response back into openai types, and wrap in cogito.LLMReply. Both API-key (x-goog-api-key) and OAuth (Bearer) auth are supported.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoResponse = errors.New("google: completed without an assistant message")

ErrNoResponse is returned when the API returns a candidate with no content.

Functions

func KnownChatModels added in v0.9.1

func KnownChatModels() []string

KnownChatModels are Gemini chat models for backends that cannot enumerate them: Cloud Code Assist (Gemini CLI) has no listing endpoint, and Vertex's publisher-model listing refuses API keys. It is a suggestion for the model picker, where a name missing from it can still be typed; the server decides whether the account may use it. Returns a fresh copy.

func TranslateRequest

func TranslateRequest(req openai.ChatCompletionRequest) ([]byte, error)

TranslateRequest translates an OpenAI Chat Completion request to a Gemini generateContent JSON body. Exported for reuse by other Gemini-based adapters (e.g., google-vertex).

func TranslateResponse

func TranslateResponse(body []byte, requestModel string) (cogito.LLMReply, cogito.LLMUsage, error)

TranslateResponse parses a Gemini generateContent JSON response into OpenAI types. Exported for reuse by other Gemini-based adapters.

Types

type Config

type Config struct {
	Model   string
	BaseURL string // default "https://generativelanguage.googleapis.com/v1beta"
	APIKey  string // x-goog-api-key auth (when IsOAuth is false)
	Token   string // Bearer auth (when IsOAuth is true)
	IsOAuth bool   // true = OAuth bearer; false = x-goog-api-key
}

Config holds the connection + auth parameters for the Google Gemini adapter.

type LLM

type LLM struct {
	// contains filtered or unexported fields
}

LLM implements cogito.LLM against the Google Generative AI API.

func New

func New(config Config) *LLM

New returns a Google Gemini adapter. If BaseURL is empty, defaults to https://generativelanguage.googleapis.com/v1beta.

func (*LLM) Ask

func (l *LLM) Ask(ctx context.Context, fragment cogito.Fragment) (cogito.Fragment, error)

Ask delegates to CreateChatCompletion, mirroring the anthropic/codexapp pattern.

func (*LLM) CreateChatCompletion

func (l *LLM) CreateChatCompletion(ctx context.Context, request openai.ChatCompletionRequest) (cogito.LLMReply, cogito.LLMUsage, error)

CreateChatCompletion translates an OpenAI Chat Completion request to the Gemini generateContent API, calls it, and translates the response back.

func (*LLM) ListModels added in v0.9.1

func (l *LLM) ListModels(ctx context.Context) ([]string, error)

ListModels returns the Gemini models that can generate content (GET {base}/models), following nextPageToken pagination. Embedding-only and other non-chat models are left out, and the "models/" prefix is dropped so the IDs are what the chat request expects.

Jump to

Keyboard shortcuts

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