llmgen

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package llmgen is the multi-backend seam for one-shot structured LLM calls: system + user prompt in, schema-validated JSON out. Three backends share it — the Anthropic API (strongest: server-side forced-tool schema), the claude CLI (subscription-billed, no key), and local Ollama (free, private). Both the import reconciler and the learning pipelines build on this seam, so a user's backend choice works everywhere culi calls a model.

Never imported by hook hot-path packages (dependency contract C2): the anthropic backend links gopheragent + the vendor SDK.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator

type Generator interface {
	Generate(ctx context.Context, system, user, name string, schema map[string]any, out any) (Usage, error)
	ModelName() string
}

Generator is one structured-output call: decode the model's JSON reply into out, which must match schema. name labels the call in errors and (for the anthropic backend) the forced tool. Implementations are safe for sequential reuse; none are goroutine-safe by contract.

func NewAnthropic

func NewAnthropic(model, apiKeyFile string) (Generator, error)

NewAnthropic builds a generator on the given model. apiKeyFile is optional (""): when set, the ANTHROPIC_API_KEY is read from that file (headless learning can't rely on the env var reaching a hook-spawned process); when empty, gopheragent reads ANTHROPIC_API_KEY from the environment as before. Temperature 0: re-running the same call should produce the same output, so review conclusions survive a re-run (best-effort — Anthropic has no seed).

func NewCLI

func NewCLI(model, tokenFile string) (Generator, error)

NewCLI builds a generator on the claude CLI found in PATH. tokenFile is optional (""): when set, each headless call reads a CLAUDE_CODE_OAUTH_TOKEN from that file and injects it into the subprocess env — needed for headless background learning, since Claude Code does not hand its OAuth token to hook-spawned processes.

func NewOllama

func NewOllama(endpoint, model string) Generator

NewOllama builds a generator on a local Ollama chat model (a GENERATION model, e.g. qwen3 — not the embedding model).

type Usage

type Usage struct {
	Prompt     int
	Completion int
}

Usage accumulates token counts for cost reporting. For retried calls it sums across attempts — the user pays for every attempt.

func (*Usage) Add

func (u *Usage) Add(o Usage)

Add folds another call's usage into the total.

Jump to

Keyboard shortcuts

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