Some checks failed
E2E Tests / e2e (push) Waiting to run
Tests unitaires / Web (Angular · vitest + couverture) (push) Successful in 26s
Build & Push Images / tests (push) Failing after 13s
Build & Push Images / build (brain) (push) Has been skipped
Build & Push Images / build (core) (push) Has been skipped
Build & Push Images / build (web) (push) Has been skipped
Build & Push Images / build-switcher (push) Has been skipped
Tests unitaires / Brain (Python · pytest + couverture) (push) Successful in 1m12s
Tests unitaires / Core (Java · mvn test + JaCoCo) (push) Failing after 1m28s
Mise en place de tests unitaires coté Python et Angular Mise en place de la couverture de test directement dans le workflow : le programme ne build pas si jamais un test échoue Passage en v0.16.2 en conséquence
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
"""Adapter Mistral — implémente les ports LLMProvider / LLMChatProvider.
|
|
|
|
Mistral (La Plateforme) expose l'API OpenAI standard (POST {base}/chat/completions,
|
|
SSE) : client "OpenAI-compatible" qui hérite de BaseOpenAICompatibleAdapter et ne
|
|
fournit que ses spécificités.
|
|
|
|
Tier GRATUIT : compte sur console.mistral.ai (tier « Experiment »), clé API à
|
|
coller dans l'écran Paramètres. Modèles conseillés pour l'extraction : un grand
|
|
contexte fidèle comme `mistral-large-latest` (128k) ou `mistral-small-latest`.
|
|
|
|
Mode JSON natif : TOUS les modèles Mistral le supportent (`_supports_json_object`).
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
from app.core.config import Settings
|
|
from app.domain.ports import LLMProviderError
|
|
from app.infrastructure.base_openai_adapter import (
|
|
_FIRST_TOKEN_TIMEOUT_SECONDS,
|
|
BaseOpenAICompatibleAdapter,
|
|
)
|
|
|
|
|
|
class MistralLLMProvider(BaseOpenAICompatibleAdapter):
|
|
"""Adapter Mistral (OpenAI-compatible) — satisfait LLMProvider et LLMChatProvider."""
|
|
|
|
_provider_label = "Mistral"
|
|
_api_url = "https://api.mistral.ai/v1/chat/completions"
|
|
_supports_json_object = True
|
|
|
|
def __init__(self, settings: Settings) -> None:
|
|
if not settings.mistral_api_key:
|
|
raise LLMProviderError(
|
|
"Clé API Mistral manquante. Configure-la depuis l'écran Paramètres."
|
|
)
|
|
super().__init__(
|
|
settings.mistral_api_key, settings.mistral_model, settings.llm_timeout_seconds
|
|
)
|
|
|
|
def _headers(self) -> dict[str, str]:
|
|
return {**super()._headers(), "Accept": "application/json"}
|
|
|
|
def _first_token_timeout_message(self) -> str:
|
|
return (
|
|
f"Erreur Mistral : aucun contenu produit en "
|
|
f"{int(_FIRST_TOKEN_TIMEOUT_SECONDS)}s — le modèle est probablement "
|
|
"en file d'attente (tier gratuit, 2 req/min). Réessayez plus tard ou "
|
|
"choisissez un modèle plus disponible."
|
|
)
|