Skip to main content

Module llm

Module llm 

Source
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) — local claude -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§

AnthropicBackend
ClaudeCliBackend
LlmUsage
Token usage reported by a backend for one call. cost_usd is None when the backend doesn’t report a price (most APIs report tokens, not dollars; claude -p reports total_cost_usd, which is 0 under a subscription).
OpenAiBackend

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 --backend flag) or TJ_BACKEND, defaulting to claude-p. Returns: