feat(llm): añade Protocol LLMProvider con Message y CompletionResult

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Juan
2026-05-10 10:28:40 +02:00
co-authored by Claude Opus 4.7
parent 201ecade9f
commit bc16059738
2 changed files with 57 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
"""Tipos y Protocol del proveedor LLM (Strategy pattern)."""
from __future__ import annotations
from typing import Any, Literal, Protocol
from pydantic import BaseModel
class Message(BaseModel):
"""Mensaje individual de la conversación enviada al LLM."""
role: Literal["system", "user", "assistant"]
content: str
class CompletionResult(BaseModel):
"""Resultado normalizado de una llamada a un proveedor LLM."""
content: str
model: str
tokens_in: int
tokens_out: int
latency_ms: int
class LLMProvider(Protocol):
"""Interfaz mínima común a todos los proveedores LLM."""
name: str
async def complete(
self,
messages: list[Message],
schema: dict[str, Any] | None = None,
temperature: float = 0.2,
max_tokens: int = 2000,
) -> CompletionResult: ...