Documentation
¶
Overview ¶
Package llm is the one client every AI feature of the panel uses to talk to a language model (TASK-0190, ADR-0041, REQ-0109). The caller names a provider (Anthropic, OpenAI, Google Gemini or OpenRouter), a model and a key; each provider is reached through its official Go SDK, and the code that asks does not change with the provider. Answers and errors have one shape.
The SDKs never open a connection of their own: the caller gives the HTTP client, which in the panel is the safe outbound client (REQ-0092). A key is used for the call and is never logged, returned or put in an error.
Index ¶
Constants ¶
const ( User = "user" Assistant = "assistant" )
Roles of a message.
const ( StopEnd = "end" // the model finished StopLength = "length" // it reached MaxTokens StopRefused = "refused" // it declined, or the provider's safety filter did StopOther = "other" )
Stop reasons, the same for every provider.
Variables ¶
var Providers = []Provider{Anthropic, OpenAI, Gemini, OpenRouter}
Providers lists them in the order screens show them.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
Provider() Provider
// Complete asks and waits for the whole answer.
Complete(ctx context.Context, r Request) (Response, error)
// Stream asks and calls emit with each piece as it arrives; it returns the
// whole answer. A non-nil error from emit stops the stream and is returned.
Stream(ctx context.Context, r Request, emit func(Chunk) error) (Response, error)
}
Client talks to one provider with one key and one model.
type Config ¶
type Config struct {
Provider Provider
APIKey string
Model string
// BaseURL replaces the provider's address; tests point it at a fake.
BaseURL string
// HTTPClient carries every request. It is required: the SDKs must not use a
// client the panel did not give them.
HTTPClient *http.Client
}
Config makes a client.
type Error ¶
type Error struct {
Kind Kind
Provider Provider
Status int // the HTTP status, when there was one
Message string // a short reason in words
}
Error is a failure of a call. Its text never holds the key or the provider's body.
type Kind ¶
type Kind string
Kind classifies an error the same way for every provider.
const ( ErrAuth Kind = "auth" // the key was refused or lacks the right ErrRateLimit Kind = "rate_limit" // too many requests, or the quota is used up ErrTooLarge Kind = "too_large" // the request is more than the model takes ErrBadRequest Kind = "bad_request" // the request or the model name is wrong ErrCanceled Kind = "canceled" // the caller stopped it ErrInternal Kind = "internal" // anything else )
Error kinds.
type Provider ¶
type Provider string
Provider names a service.
type Request ¶
type Request struct {
System string
Messages []Message // alternating, starting with a user turn
MaxTokens int // the most the model may write; required
Temperature *float64 // nil: the provider's default
}
Request is what is asked of the model.