Expand description
Pluggable LLM backend for the journal’s optional AI operations (consolidation, dream backfill). One small trait, several adapters, picked by name so this public package can grow new providers without touching callers.
Default is claude-p — the local Claude CLI on your subscription, so the
out-of-the-box experience needs no API key. Override with TJ_BACKEND (env,
global) or a per-command --backend:
claude-p(default) — localclaude -p, Haiku, subscription auth.anthropic— direct Anthropic API (ANTHROPIC_API_KEY).openai— any OpenAI-compatible chat API (OPENAI_API_KEY,TJ_OPENAI_BASE_URL,TJ_OPENAI_MODEL). Covers OpenAI, Codex, and other compatible providers by pointing the base URL.ollama— a local Ollama model (its OpenAI-compatible endpoint), free: no key, no network beyond localhost.TJ_OLLAMA_URL,TJ_OLLAMA_MODEL.
A backend that isn’t usable (no key, no claude on PATH) yields Ok(None)
from backend_from_env so the caller skips cleanly — we never fabricate
output without a model.
Structs§
- Anthropic
Backend - Claude
CliBackend - LlmUsage
- Token usage reported by a backend for one call.
cost_usdisNonewhen the backend doesn’t report a price (most APIs report tokens, not dollars;claude -preportstotal_cost_usd, which is 0 under a subscription). - Open
AiBackend
Traits§
- LlmBackend
- One AI call: a prompt in, the model’s text reply out.
Functions§
- backend_
from_ env - Resolve the backend from an explicit name (e.g. a
--backendflag) orTJ_BACKEND, defaulting toclaude-p. Returns: