44 lines
2.8 KiB
Markdown
44 lines
2.8 KiB
Markdown
# Optional source-grounded AI
|
||||
|
|
|
|||
|
|
This GUI-free crate sends a bounded explicit request to a user-configured
|
|||
|
|
OpenAI-compatible Chat Completions endpoint. It is independent of search and
|
|||
|
|
contains no default provider, endpoint, model, implicit setup call or download.
|
|||
|
|
Validating configuration and constructing a client do not contact the endpoint.
|
|||
|
|
|
|||
|
|
`AiConfig {base_url, model, api_key}` accepts an explicit HTTP(S) base such as
|
|||
|
|
`http://127.0.0.1:1234/v1`; `/chat/completions` is appended. URL credentials,
|
|||
|
|
queries and fragments are rejected. Credentials are optional, header-only,
|
|||
|
|
marked sensitive, and redacted by configuration Debug. Redirects and ambient
|
|||
|
|
proxies are disabled. Reqwest with rustls provides portable maintained HTTP/TLS.
|
|||
|
|
Errors contain static descriptions/status codes, never raw URLs, provider error
|
|||
|
|
bodies, credentials or selected text. The crate performs no logging.
|
|||
|
|
|
|||
|
|
`AiClient::generate(&AiRequest)` is the sole network operation. Callers must
|
|||
|
|
require explicit enablement and a user action, validate that sources belong to
|
|||
|
|
the current index, and obtain consent before sending excerpts to the configured
|
|||
|
|
endpoint. Desktop code should use a blocking worker; background searches must
|
|||
|
|
never depend on this client. Session credential storage is a caller concern.
|
|||
|
|
|
|||
|
|
Requests contain `AiMode::Summary` or `Question`, an optional question, and
|
|||
|
|
1–8 `AiSource` records with short unique IDs, title, text and optional location.
|
|||
|
|
Bounds: 16 KiB per source, 32 KiB total selected text, 2 KiB question, 96 KiB
|
|||
|
|
encoded HTTP payload, 64 KiB response and 16 KiB answer. Request timeout is
|
|||
|
|
45 seconds including response consumption, with a five-second connect limit.
|
|||
|
|
There is no automatic retry or silent truncation.
|
|||
|
|
|
|||
|
|
Sources are explicitly untrusted data in the system instruction; source commands
|
|||
|
|
cannot authorize tools or application actions. The only Chat Completions fields
|
|||
|
|
sent are model and messages, for broad provider compatibility. The model must
|
|||
|
|
return a JSON answer/citations object inside `choices[0].message.content`.
|
|||
|
|
Returned IDs must exist, citations must appear inline as `[id]`, and the inline
|
|||
|
|
ID set must match the citation array. Unknown or inconsistent IDs are rejected.
|
|||
|
|
A no-citation answer remains an **uncited draft**; citation validation does not
|
|||
|
|
prove factual grounding or neutralize all model prompt injection. Callers must
|
|||
|
|
label output accordingly and retain the original source for verification.
|
|||
|
|
|
|||
|
|
Local HTTP tests inspect actual endpoint path/messages/header-only credential,
|
|||
|
|
untrusted source boundaries, offline validation, pre-network input limits,
|
|||
|
|
malformed/unknown/mismatched citations, keyless local endpoints, actual timeout,
|
|||
|
|
response cap and error redaction. They use no real provider credentials, cloud
|
|||
|
|
endpoints, GPU inference or simulated production model output. Real-provider
|
|||
|
|
behavior and Linux/macOS execution remain untested release checks.
|