"""Anthropic LLM provider (official SDK). Self-hosters who want everything to stay on their own metal would configure a local provider instead (e.g. Ollama) — that's a future implementation of the same LLMProvider interface.""" from anthropic import AsyncAnthropic from app.integrations.models.base import LLMProvider class AnthropicLLMProvider(LLMProvider): def __init__(self, *, api_key: str, model: str, max_tokens: int = 4096) -> None: self._client = AsyncAnthropic(api_key=api_key) self._model = model self._max_tokens = max_tokens async def complete(self, *, prompt: str, system: str | None = None) -> str: resp = await self._client.messages.create( model=self._model, max_tokens=self._max_tokens, system=system or "", messages=[{"role": "user", "content": prompt}], ) # content is a list of blocks; concatenate the text ones. return "".join(b.text for b in resp.content if b.type == "text")