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 ¶
var ErrNoResponse = errors.New("google: completed without an assistant message")
ErrNoResponse is returned when the API returns a candidate with no content.
Functions ¶
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).
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 ¶
New returns a Google Gemini adapter. If BaseURL is empty, defaults to https://generativelanguage.googleapis.com/v1beta.
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.