feat: architecture multi-modèles LLM + quality engine + benchmark
- Multi-modèles : 4 rôles LLM (coding=gemma3:27b-cloud, cpam=gemma3:27b-cloud, validation=deepseek-v3.2:cloud, qc=gemma3:12b) avec get_model(role) - Prompts externalisés : 7 templates dans src/prompts/templates.py - Cache Ollama : modèle stocké par entrée (migration auto ancien format) - call_ollama() : paramètre role= (priorité: model > role > global) - Quality engine : veto_engine + decision_engine + rules_router (YAML) - Benchmark qualité : scripts/benchmark_quality.py (A/B, métriques CIM-10) - Fix biologie : valeurs qualitatives (troponine négative) non filtrées - Fix CPAM : gemma3:27b-cloud au lieu de deepseek (JSON tronqué par thinking) - CPAM max_tokens 4000→6000, viewer admin multi-modèles - Benchmark 10 dossiers : 100% DAS valides, 10/10 CPAM, 243s/dossier Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -49,15 +49,14 @@ class TestOllamaCache:
|
||||
cache.save()
|
||||
assert not path.exists()
|
||||
|
||||
def test_model_change_invalidates(self, tmp_path):
|
||||
path = tmp_path / "cache.json"
|
||||
cache = OllamaCache(path, "gemma3:12b")
|
||||
def test_model_change_returns_none(self, tmp_path):
|
||||
"""Entrées d'un autre modèle retournent None (pas d'invalidation globale)."""
|
||||
cache = OllamaCache(tmp_path / "cache.json", "gemma3:12b")
|
||||
cache.put("HTA", "das", {"code": "I10"})
|
||||
cache.save()
|
||||
|
||||
cache2 = OllamaCache(path, "llama3:8b")
|
||||
assert cache2.get("HTA", "das") is None
|
||||
assert len(cache2) == 0
|
||||
# Même cache, modèle différent → miss
|
||||
assert cache.get("HTA", "das", model="llama3:8b") is None
|
||||
# Modèle original → hit
|
||||
assert cache.get("HTA", "das") == {"code": "I10"}
|
||||
|
||||
def test_corrupted_file(self, tmp_path):
|
||||
path = tmp_path / "cache.json"
|
||||
@@ -95,14 +94,75 @@ class TestOllamaCache:
|
||||
assert not errors
|
||||
assert len(cache) == 20
|
||||
|
||||
def test_json_format(self, tmp_path):
|
||||
"""Le fichier JSON contient le modèle et les entrées."""
|
||||
def test_json_format_new(self, tmp_path):
|
||||
"""Le nouveau format stocke le modèle PAR ENTRÉE (pas global)."""
|
||||
path = tmp_path / "cache.json"
|
||||
cache = OllamaCache(path, "gemma3:12b")
|
||||
cache.put("HTA", "das", {"code": "I10"})
|
||||
cache.save()
|
||||
|
||||
raw = json.loads(path.read_text(encoding="utf-8"))
|
||||
assert raw["model"] == "gemma3:12b"
|
||||
assert "entries" in raw
|
||||
assert len(raw["entries"]) == 1
|
||||
assert "model" not in raw # plus de model global
|
||||
# Chaque entrée contient model + result
|
||||
entry = list(raw["entries"].values())[0]
|
||||
assert entry["model"] == "gemma3:12b"
|
||||
assert entry["result"] == {"code": "I10"}
|
||||
|
||||
def test_migration_old_format(self, tmp_path):
|
||||
"""Ancien format (model global) migré automatiquement."""
|
||||
path = tmp_path / "cache.json"
|
||||
# Écrire un cache ancien format
|
||||
old_data = {
|
||||
"model": "gemma3:12b",
|
||||
"entries": {
|
||||
"das::hta": {"code": "I10", "confidence": "high"},
|
||||
},
|
||||
}
|
||||
path.write_text(json.dumps(old_data), encoding="utf-8")
|
||||
|
||||
cache = OllamaCache(path, "gemma3:12b")
|
||||
# L'entrée doit être accessible
|
||||
assert cache.get("HTA", "das") == {"code": "I10", "confidence": "high"}
|
||||
assert len(cache) == 1
|
||||
|
||||
# Sauvegarder et vérifier le nouveau format
|
||||
cache.save()
|
||||
raw = json.loads(path.read_text(encoding="utf-8"))
|
||||
assert "model" not in raw
|
||||
entry = raw["entries"]["das::hta"]
|
||||
assert entry["model"] == "gemma3:12b"
|
||||
assert entry["result"]["code"] == "I10"
|
||||
|
||||
def test_migration_old_format_different_model(self, tmp_path):
|
||||
"""Migration ancien format : les entrées sont bien taggées avec l'ancien modèle."""
|
||||
path = tmp_path / "cache.json"
|
||||
old_data = {
|
||||
"model": "old-model",
|
||||
"entries": {
|
||||
"das::hta": {"code": "I10"},
|
||||
},
|
||||
}
|
||||
path.write_text(json.dumps(old_data), encoding="utf-8")
|
||||
|
||||
# Charger avec un modèle différent
|
||||
cache = OllamaCache(path, "new-model")
|
||||
# L'entrée est taggée "old-model" → miss avec "new-model"
|
||||
assert cache.get("HTA", "das") is None
|
||||
# Mais accessible avec l'ancien modèle
|
||||
assert cache.get("HTA", "das", model="old-model") == {"code": "I10"}
|
||||
|
||||
def test_put_with_explicit_model(self, tmp_path):
|
||||
"""put() avec model= explicite stocke ce modèle."""
|
||||
cache = OllamaCache(tmp_path / "cache.json", "default-model")
|
||||
cache.put("HTA", "das", {"code": "I10"}, model="explicit-model")
|
||||
# get sans model → utilise default → miss
|
||||
assert cache.get("HTA", "das") is None
|
||||
# get avec le bon modèle → hit
|
||||
assert cache.get("HTA", "das", model="explicit-model") == {"code": "I10"}
|
||||
|
||||
def test_get_returns_none_if_model_mismatch(self, tmp_path):
|
||||
"""get() retourne None si le modèle stocké ≠ modèle demandé."""
|
||||
cache = OllamaCache(tmp_path / "cache.json", "gemma3:12b")
|
||||
cache.put("HTA", "das", {"code": "I10"})
|
||||
assert cache.get("HTA", "das", model="llama3:8b") is None
|
||||
|
||||
Reference in New Issue
Block a user