330543f9ce
Adds the vendor-agnostic seam the AI assistant + match-ranking plug into: - LLMProvider / EmbeddingProvider ABCs (base.py). LLM and embeddings are SEPARATE abstractions — Anthropic has no embeddings endpoint, so each is configured independently and either can be off. - NullLLMProvider / NullEmbeddingProvider — the default; fail loud with a clear "not configured" error so AI-off deployments don't silently no-op. - AnthropicLLMProvider — first concrete LLM impl, via the official anthropic SDK (default model claude-opus-4-8). A local provider (e.g. Ollama) would be another subclass of the same interface. - Factory in deps.py (get_llm_provider / get_embedding_provider) selects by env (MODEL_PROVIDER / EMBEDDING_PROVIDER); documented in .env.example. Providers are read-only text/vector producers — they never touch the DB, so the "AI never writes autonomously" invariant (CLAUDE.md #1) holds; writes will go through ChangeProposal (#214). Tests: provider selection (null default, anthropic when keyed, fallback without key) + null providers raise. 81 passed. Closes #215 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Justin Paul <justin@jpaul.me>
37 lines
1.3 KiB
Python
37 lines
1.3 KiB
Python
"""Model-provider interfaces — the seam the AI assistant and match ranking plug
|
|
into. LLM (text) and embeddings are *separate* abstractions: Anthropic offers no
|
|
embeddings endpoint, so the two are configured independently (twelve-factor,
|
|
CLAUDE.md #7) and a deployment may run one without the other.
|
|
|
|
These providers are read-only text/vector producers. They MUST NOT mutate tree
|
|
data — the assistant's writes go through a ChangeProposal a human approves
|
|
(CLAUDE.md #1). Nothing here touches the database.
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
|
|
class LLMProvider(ABC):
|
|
"""Text in, text out. Implementations wrap a chat/completion model."""
|
|
|
|
@abstractmethod
|
|
async def complete(self, *, prompt: str, system: str | None = None) -> str:
|
|
"""Return the model's text response to a single user prompt."""
|
|
...
|
|
|
|
|
|
class EmbeddingProvider(ABC):
|
|
"""Text in, vectors out — for pgvector-backed match ranking."""
|
|
|
|
#: Dimensionality of the returned vectors (for the pgvector column).
|
|
dimensions: int
|
|
|
|
@abstractmethod
|
|
async def embed(self, texts: list[str]) -> list[list[float]]:
|
|
"""Return one embedding vector per input text, in order."""
|
|
...
|
|
|
|
|
|
class ModelProviderNotConfigured(RuntimeError):
|
|
"""Raised when an AI capability is used but no provider is configured."""
|