Expand description
ApiClient implementation that talks to a local Ollama instance.
Critical knobs:
- Calls
/api/chatdirectly withthink: falseso reasoning models like qwen3.5:9b skip their chain-of-thought. - Uses native tool calling: passes a
toolsarray on every request and parsesmessage.tool_callsfrom the response. - Holds the tool list and context window on the client itself, so the
crate::ApiClienttrait does not need to change.
Structs§
- Ollama
ApiClient - Ollama-backed
ApiClientfor the secretary mode.
Enums§
- Tools
Provider - How the client sources the
toolsarray for each request. Agents use aToolsProvider::Fixedvalue (a pre-filtered allowlist); the main Claudette runtime usesToolsProvider::Dynamicso the model can enable tool groups mid-conversation.
Constants§
- DEFAULT_
NUM_ CTX - Default Ollama context window.
- DEFAULT_
NUM_ PREDICT - Maximum tokens the model can generate per request. 6144 gives ~50%
headroom over the original 4096 ceiling — room for researcher summaries
and long multi-turn answers without eating too much of the input budget.
Override with
CLAUDETTE_NUM_PREDICT.
Functions§
- current_
num_ ctx - Resolve the actual
num_ctxto use. Sprint 14: reads frommodel_config::active().brain.num_ctx, which itself mergesCLAUDETTE_NUM_CTXon first init. Keeps/statusandget_capabilitiesin sync with slash-command overrides. - current_
num_ predict - Resolve the actual
num_predictto use. Same story ascurrent_num_ctx— delegates to the active model config so slash-command overrides are reflected immediately. - host_
of_ url - Parse the lowercased host out of a URL (or a bare
host[:port]). Strips the scheme, path, userinfo (user[:pass]@), and port, and unwraps an IPv6 bracket literal ([::1]:11434→::1). Returns the host verbatim, lowercased:localhost,127.0.0.1,192.168.1.5,::1,api.github.com, … An empty string is returned for input with no host. - is_
local_ ollama_ url - Returns true when the given URL’s host is a loopback / localhost
address. Used to warn users when
OLLAMA_HOSTpoints at a remote endpoint — the README tagline is “runs entirely on your hardware,” so aOLLAMA_HOST=https://someone-elses-server:11434(accidentally inherited from~/.claudette/.envor a shell snippet copied from a tutorial) is worth surfacing loudly. As of the dotenv-CWD fix, arbitrary project.envfiles no longer feed into this path. - probe_
ollama - Short-timeout GET on the resolved Ollama base URL to verify the daemon is reachable before we drop into any interactive mode. Ollama answers its root path with “Ollama is running” and a 200; we only care that the TCP connect + HTTP round-trip succeed.
- resolve_
max_ tools - Resolve the per-request tools-array cap. Set
CLAUDETTE_MAX_TOOLS=Nto truncate the advertised tools to N entries — theenable_toolsmeta-tool is moved to position 0 first so the model can still expand the registry mid-conversation.0(or unset / unparseable) = no cap. - resolve_
ollama_ url - Resolve the Ollama base URL (no trailing slash). Honors
OLLAMA_HOST; falls back tohttp://localhost:11434. - resolve_
openai_ compat - Returns true when LM Studio (or any OpenAI Chat Completions-compatible)
mode is requested. Set
CLAUDETTE_OPENAI_COMPAT=1to opt in. The brain client will then POST to/v1/chat/completionsinstead of/api/chat, parse a non-streaming JSON response (no SSE yet), and skip Ollama-specific request fields (think,options.num_*,keep_alive). - stdout_
text_ callback - Convenience constructor for the standard “print to stdout immediately”
callback used by the REPL. Lives here (and not in
run.rs) so other callers — tests, future TUIs — can pick it up without re-implementing the flush dance. - telegram_
stream_ buffer - Accessor for the Telegram stream buffer. Lazily initialised on first call.
- telegram_
stream_ reset - Reset the Telegram stream buffer. Called at the start of each turn so leftover bytes from the previous turn don’t leak.
- telegram_
text_ callback - Callback for Telegram mode: appends deltas to the shared stream buffer and also mirrors them to stdout so the server terminal still shows the model’s output as it streams.
- tui_
text_ callback - Convenience constructor for forwarding text deltas to the TUI via a
sync channel. Each delta fires one
TuiEvent::Token. Used by the TUI worker thread instead of the REPL’s stdout callback.
Type Aliases§
- Text
Callback - Callback type fired once per text delta when streaming is enabled. The
callback owns no state shared with the runtime — it just receives bytes
and is expected to side-effect (print, accumulate to a buffer, etc.).
Send + Syncso the client can be used across threads if a future runtime ever wants to.