Remplace TechStepClassifierService's node-nlp (NlpManager) par services/tech-step-intent-service, un microservice FastAPI/spaCy dedie (PhraseMatcher pour le NER par synonymes, textcat pour la classification d'intention). Corpus (TECH_STEP_TRAINING_DATA) toujours possede par apps/api, pousse au service via POST /v1/train a chaque warm-up ; le service ne touche jamais Postgres (meme posture que services/tech-step-llm-worker). Cote apps/api : - intent-service-client.ts : client HTTP vers le nouveau service - tech-step-matcher.ts : delegue NER + intent classification au client, logique pure (splitIntoClauses, seuil/fallback) inchangee - env.ts : INTENT_SERVICE_BASE_URL/INTENT_SERVICE_SECRET (secret requis, service coeur non optionnel) - server.ts : warm-up avec retry/backoff (service Python demarre a part) - scripts/calibrate-tech-step-threshold.ts : recalibration empirique de CONFIDENCE_THRESHOLD contre le jeu d'eval existant - node-nlp retire (package.json, node-nlp.d.ts, model.nlp du .gitignore) docker-compose.yml : nouveau service tech-step-intent-service (pas de port expose, healthcheck, app en depend). CI : job intent-service-test (pytest) + le job test demarre le service en arriere-plan avant la suite Mocha (jamais de mock d'un service interne, cf specs/dev-conventions.md). Verifie : 26/26 tests pytest du service (dont les offsets caracteres exacts de tech-step-matcher.test.ts), lint + build complets du monorepo, smoke test HTTP reel bout en bout. La suite Mocha et docker compose build/up n'ont pas pu etre executes dans cet environnement (pas de Postgres/Docker disponibles ici) — a confirmer via la CI et en local. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
"""Contrat JSON de `POST /v1/process` — voir `schemas.py`/`routes/process.py`."""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from intent_service.config import settings
|
|
from intent_service.main import app
|
|
|
|
_HEADERS = {"X-Intent-Service-Secret": settings.intent_service_secret}
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
with TestClient(app) as test_client:
|
|
yield test_client
|
|
|
|
|
|
def test_process_against_an_untrained_locale_returns_empty_result(client: TestClient):
|
|
response = client.post(
|
|
"/v1/process", headers=_HEADERS, json={"locale": "fr", "text": "faire mijoter à feu doux"}
|
|
)
|
|
assert response.status_code == 200
|
|
assert response.json() == {"entities": [], "intent": None, "score": 0.0}
|
|
|
|
|
|
def test_process_after_train_returns_entities_and_intent(client: TestClient):
|
|
client.post(
|
|
"/v1/train",
|
|
headers=_HEADERS,
|
|
json={
|
|
"locale": "fr",
|
|
"entries": [
|
|
# `textcat` (exclusive_classes) exige >= 2 labels (voir
|
|
# LocalePipeline.train) — un second label est nécessaire
|
|
# même si ce test ne vérifie que celui de "simmer".
|
|
{
|
|
"uid": "simmer",
|
|
"synonyms": ["mijoter"],
|
|
"utterances": ["faire mijoter à feu doux", "laisser mijoter à couvert"],
|
|
},
|
|
{
|
|
"uid": "boil",
|
|
"synonyms": ["bouillir"],
|
|
"utterances": ["faire bouillir l'eau", "porter à ébullition"],
|
|
},
|
|
],
|
|
},
|
|
)
|
|
|
|
response = client.post(
|
|
"/v1/process", headers=_HEADERS, json={"locale": "fr", "text": "Faire mijoter à feu doux"}
|
|
)
|
|
assert response.status_code == 200
|
|
body = response.json()
|
|
assert body["intent"] == "simmer"
|
|
assert body["score"] > 0
|
|
assert [entity["uid"] for entity in body["entities"]] == ["simmer"]
|
|
|
|
|
|
def test_process_with_blank_text_returns_empty_result(client: TestClient):
|
|
client.post(
|
|
"/v1/train",
|
|
headers=_HEADERS,
|
|
json={
|
|
"locale": "en",
|
|
"entries": [{"uid": "boil", "synonyms": ["boil"], "utterances": ["bring to the boil"]}],
|
|
},
|
|
)
|
|
response = client.post("/v1/process", headers=_HEADERS, json={"locale": "en", "text": " "})
|
|
assert response.status_code == 200
|
|
assert response.json() == {"entities": [], "intent": None, "score": 0.0}
|