Help us shape the future of Go! Take the 2026 Go Developer Survey

google

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package google is the weft adapter for the Gemini API via the official google.golang.org/genai SDK. weft never owns the HTTP: every request goes through the SDK's client, and the SDK's stream iterator is the contract.

Mapping highlights (ADR 0013 has the full tables):

  • Tool definitions become function declarations from Schema. Thought signatures round-trip as reasoning: surfaced from whichever part carries them, sent back on the first function call of a tool turn (where the API validates them) or on a thought part otherwise; unsigned reasoning is dropped.
  • FilePart becomes inline data (base64) or a file URI.
  • Function calls arrive whole; the adapter prefers the call id the API populates and synthesises call_<i> per step when absent, matching responses by position (the API matches by name and order).
  • SequentialTools has no Gemini switch: function-calling config stays AUTO and the adapter's conformance run declares the sequential cap false — a documented gap, not a silent one.

Retry stance: transport retries (429, 5xx, connection errors) belong to the SDK via MaxRetries (off unless asked); the weft loop never retries a model call, and logic retries are model-seam middleware.

Vertex AI and Bedrock-style setups compose through Client(c) with their own genai.Client. Grounding, search, and code-execution tools are not wrapped here.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Model

func Model(name string, opts ...Option) weft.Model

Model returns a weft.Model backed by the Gemini API. The SDK client is created lazily on the first run (its constructor wants a context for credential discovery), so constructing a Model performs no I/O. A Model is immutable and safe for concurrent runs; tool definitions are converted once per *ToolDef and cached by pointer.

Example

Constructing a model performs no I/O; credentials ($GEMINI_API_KEY / $GOOGLE_API_KEY, then application default) are read on the first run. Swap providers by swapping this one line.

package main

import (
	"context"

	"github.com/weftgo/weft"
	"github.com/weftgo/weft/google"
)

func main() {
	m := google.Model("gemini-2.5-flash")
	echo := weft.Tool("echo", "Echo a message.", func(ctx context.Context, in struct {
		Message string `json:"message" jsonschema:"the text to repeat"`
	}) (string, error) {
		return in.Message, nil
	})
	agt := weft.New(m, echo)
	_ = agt // a run is agt.Generate(ctx, weft.Prompt("Echo: hello"))
}

Types

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures the adapter at construction, the same functional style as the core. The zero configuration discovers credentials the SDK's way ($GOOGLE_API_KEY / $GEMINI_API_KEY, then application default) and does not set a base URL.

func APIKey

func APIKey(k string) Option

APIKey sets the API key. Default: the SDK's own discovery ($GOOGLE_API_KEY / $GEMINI_API_KEY, then application default credentials).

func BaseURL

func BaseURL(u string) Option

BaseURL points the adapter at a custom endpoint (a gateway, a proxy). When the option is not given the SDK applies its own $GOOGLE_GEMINI_BASE_URL.

func Client

func Client(c *genai.Client) Option

Client uses an already-configured SDK client (Vertex AI projects and regions compose here); it overrides BaseURL, APIKey, and MaxRetries.

func IdleTimeout

func IdleTimeout(d time.Duration) Option

IdleTimeout is the maximum gap between two stream chunks before the call fails wrapping weft.ErrStreamIdle (default 60s; zero disables it). The ctx deadline stays the hard limit on the whole call — a slow but actively streaming response is never killed.

func MaxRetries

func MaxRetries(n int) Option

MaxRetries forwards to the SDK's transport retry configuration (429/5xx/connection errors only; the SDK retries nothing unless asked). The weft loop never retries a model call; logic retries are model-seam middleware (TODO §4.1).

func MaxTokens

func MaxTokens(n int) Option

MaxTokens caps a step's output tokens (maxOutputTokens). Zero keeps the provider default.

func Temperature

func Temperature(t float64) Option

Temperature sets the sampling temperature; it is not sent unless the option is given.

Directories

Path Synopsis
Command example runs a two-step agent conversation against the real Gemini API.
Command example runs a two-step agent conversation against the real Gemini API.

Jump to

Keyboard shortcuts

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