Skip to main content

Module api

Module api 

Source
Expand description

ApiClient implementation that talks to a local Ollama instance.

Critical knobs:

  • Calls /api/chat directly with think: false so reasoning models like qwen3.5:9b skip their chain-of-thought.
  • Uses native tool calling: passes a tools array on every request and parses message.tool_calls from the response.
  • Holds the tool list and context window on the client itself, so the crate::ApiClient trait does not need to change.

Structs§

OllamaApiClient
Ollama-backed ApiClient for the secretary mode.

Enums§

ToolsProvider
How the client sources the tools array for each request. Agents use a ToolsProvider::Fixed value (a pre-filtered allowlist); the main Claudette runtime uses ToolsProvider::Dynamic so 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_ctx to use. Sprint 14: reads from model_config::active().brain.num_ctx, which itself merges CLAUDETTE_NUM_CTX on first init. Keeps /status and get_capabilities in sync with slash-command overrides.
current_num_predict
Resolve the actual num_predict to use. Same story as current_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_HOST points at a remote endpoint — the README tagline is “runs entirely on your hardware,” so a OLLAMA_HOST=https://someone-elses-server:11434 (accidentally inherited from ~/.claudette/.env or a shell snippet copied from a tutorial) is worth surfacing loudly. As of the dotenv-CWD fix, arbitrary project .env files 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=N to truncate the advertised tools to N entries — the enable_tools meta-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 to http://localhost:11434.
resolve_openai_compat
Returns true when LM Studio (or any OpenAI Chat Completions-compatible) mode is requested. Set CLAUDETTE_OPENAI_COMPAT=1 to opt in. The brain client will then POST to /v1/chat/completions instead 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§

TextCallback
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 + Sync so the client can be used across threads if a future runtime ever wants to.