Documentation
¶
Overview ¶
Package llm provides an OpenAI-compatible chat completion client. It is used by the Discord gateway to generate RAG-based answers from retrieved context documents.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an OpenAI-compatible chat completion client. It communicates with any endpoint that speaks the /v1/chat/completions protocol (OpenAI, Azure OpenAI, local proxies such as cliproxy, etc.).
func New ¶
New returns a Client configured with the given Config. httpClient may be nil — an http.Client with cfg.Timeout (default 60 s) is used. When cfg.Timeout is positive it overrides the default. Pass a pre-built httpClient to take full control of transport settings.
func (*Client) Complete ¶
Complete sends a single-turn chat completion request. system is the system prompt; user is the user turn content. 4xx responses are not retried. 5xx and network errors are retried up to 2 times.
func (*Client) CompleteWithMessages ¶
func (c *Client) CompleteWithMessages(ctx context.Context, system string, messages []Message) (string, error)
CompleteWithMessages sends a multi-turn chat completion request. system is the system prompt; messages is the ordered conversation history including the final user turn. The system message is always prepended. 4xx responses are not retried. 5xx and network errors are retried up to 2 times.
type Completer ¶
type Completer interface {
Enabled() bool
CompleteWithMessages(ctx context.Context, system string, messages []Message) (string, error)
}
Completer is the minimal interface for LLM chat completion. It is satisfied by *Client and can be used by callers that need to inject a mock or alternative implementation for testing.
type Config ¶
type Config struct {
BaseURL string
Model string
APIKey string // static Bearer token (overrides AuthFile)
AuthFile string // path to CliProxyAPI OAuth JSON (e.g. ~/.cli-proxy-api/user.json)
MaxTokens int
Temperature float64
// Timeout is the per-request HTTP timeout for LLM calls.
// When zero or negative, the default of 60 s is used.
// Increase for slow local CPU inference (e.g. gemma3:4b) by setting
// LLM_TIMEOUT_SECONDS in the environment.
Timeout time.Duration
}
Config holds the parameters required to construct a Client.
Token resolution order:
- APIKey non-empty → static Bearer token
- AuthFile non-empty → CliProxyAPI OAuth token (auto-refreshed from disk, 5-min TTL)
- both empty → no Authorization header sent