pub struct AiConfig {
pub provider: String,
pub endpoint: String,
pub model: String,
pub api_key: String,
pub system: String,
pub max_tokens: u32,
pub temperature: f32,
pub access: String,
pub timeout_secs: u64,
}Expand description
An AI chat assistant: which service answers, and what to say to it.
Off by default (provider = "none"). Turning it on connects one client and
mounts <base>/ai/chat, which takes a list of messages and streams the
reply back token by token — and gives every function a chat call over the
same provider.
The three providers differ only in wire format. custom is the one that
matters most in practice: anything speaking the OpenAI chat-completions
shape — llama.cpp, vLLM, Ollama, LM Studio, a gateway of your own — is
reached by pointing endpoint at it, with no key at all
if it wants none.
Fields§
§provider: Stringnone (default), openai, anthropic or custom.
endpoint: StringWhere to send the request.
Empty uses the provider’s own API (https://api.openai.com,
https://api.anthropic.com) and is required for custom. A bare origin
or a base path (http://localhost:8080, .../v1) gets the provider’s
standard path appended; a URL that already names the full path
(…/v1/chat/completions, …/v1/messages) is used exactly as written,
for a gateway that mounts it somewhere of its own.
model: StringModel to ask for when a request doesn’t name one, e.g. gpt-4o-mini.
Some local servers serve a single model and ignore this.
api_key: StringThe provider’s API key. Optional: a local model behind
provider = "custom" usually wants no credential, and sending an empty
one is different from sending none — so an empty key means the request
carries no authorization header at all.
system: StringPrepended to every conversation as the system prompt, unless the request carries its own. Empty = none.
max_tokens: u32Cap on the tokens generated per reply. Anthropic requires one, so this is sent to every provider rather than being special-cased.
temperature: f32Sampling temperature sent when a request doesn’t name one. Negative (the default) sends nothing and lets the provider choose.
access: StringWho may call <base>/ai/chat, in the grammar a resource’s
[permissions] uses: public, authenticated (the default), member,
role:<name>.
Defaulting to authenticated is deliberate. The endpoint spends money
(or a GPU) on behalf of whoever calls it, and a public one is an open
proxy to your provider account — which is a decision an app should have
to write down.
timeout_secs: u64How long one completion may take before it is abandoned. Generous by default: a long answer from a local model is slow, not broken.