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

llm

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package llm is the only way apps run LLM inference (docs/adr/0009-copilot-sdk-llm-gateway.md): a thin, provider-neutral client for platformd's gateway. Apps never talk to a model provider directly.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmbedUnavailable = errors.New("embeddings unavailable")

ErrEmbedUnavailable reports that the gateway has no embeddings backend (BESPOKE_LEMONADE_URL unset on platformd). Callers MUST degrade — switch semantic features off and keep lexical paths working — rather than fail the surrounding feature (ADR-0029).

Functions

func Cosine added in v0.3.0

func Cosine(a, b []float32) float64

Cosine returns the cosine similarity of two vectors in [-1, 1], or 0 for mismatched or zero-magnitude inputs. The one ranking function every app uses, so scores stay comparable across the platform (ADR-0029).

Types

type Client

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

func New

func New(app string) *Client

New returns the gateway client for an app. The gateway address comes from BESPOKE_LLM_URL (set in the production env file); the default matches platformd's local internal listener.

func (*Client) Classify

func (c *Client) Classify(ctx context.Context, text string, categories []string) (string, error)

Classify returns the category from categories that best fits text — the canonical tier-1 capability helper (docs/adr/0012-internal-services-two-tier.md): pure composition over CompleteJSON, with the model's answer validated against the caller's list so apps never receive an invented category.

func (*Client) Complete

func (c *Client) Complete(ctx context.Context, prompt string, opts ...Option) (string, error)

Complete returns the model's text response for prompt.

func (*Client) CompleteJSON

func (c *Client) CompleteJSON(ctx context.Context, prompt string, out any, opts ...Option) error

CompleteJSON asks for JSON only and unmarshals the response into out (pass a pointer). Markdown fences are stripped if the model adds them.

func (*Client) Embed added in v0.3.0

func (c *Client) Embed(ctx context.Context, texts []string) (*Embedded, error)

Embed embeds documents for storage and later ranking with llm.Cosine (ADR-0029). Mechanical like Classify — no options, never user-brief-tagged. At most 64 texts of 8KB each per call; embedding is best-effort by design, so a failed Embed should never fail the write that triggered it. Returns ErrEmbedUnavailable (wrapped) when the gateway has no backend.

func (*Client) EmbedQuery added in v0.3.0

func (c *Client) EmbedQuery(ctx context.Context, q string) (*Embedded, error)

EmbedQuery embeds a search query for ranking against stored document vectors (retrieval models treat queries and documents asymmetrically; the gateway applies the model's task prefixes). One text in, one vector out at Vectors[0].

func (*Client) Healthy

func (c *Client) Healthy(ctx context.Context) error

Healthy reports whether the gateway is up and authenticated.

type Embedded added in v0.3.0

type Embedded struct {
	Model   string
	Vectors [][]float32
}

Embedded is the result of an embedding call: one vector per input text, in input order, plus the backend model that produced them. Store Model alongside vectors — a model change invalidates them (ADR-0029).

type Option

type Option func(*request)

func WithBuiltins

func WithBuiltins(names ...string) Option

WithBuiltins re-enables curated runtime builtins for assistant surfaces (ADR-0024) — e.g. "web_search", "web_fetch", and the read-only GitHub tools. The gateway rejects names outside its allowlist, so this is a request, not a grant. Requires WithUser, like tools.

func WithSystem

func WithSystem(s string) Option

WithSystem adds system instructions to a completion.

func WithTools

func WithTools(tools []Tool) Option

WithTools lets the model call actions during the completion (agentic mode, ADR-0021). Requires WithUser — tools execute as that user.

func WithUser

func WithUser(login string) Option

WithUser tags the completion with the requesting user's login; the gateway prepends that user's self-provided brief (ADR-0019). Use for anything user-facing (chat, summaries); omit for mechanical calls.

type Tool

type Tool struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Schema      map[string]any `json:"schema"`
	URL         string         `json:"url"`
}

Tool is an action the model may call during a completion (ADR-0021). The gateway invokes URL with the tagged user's identity when the model requests it.

Jump to

Keyboard shortcuts

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