llm-api/exercise_router.py aktualisiert
All checks were successful
Deploy Trainer_LLM to llm-node / deploy (push) Successful in 2s

This commit is contained in:
Lars 2025-08-11 19:02:01 +02:00
parent 380b361e70
commit 21ce1dc395

View File

@ -1,13 +1,11 @@
# -*- coding: utf-8 -*-
"""
exercise_router.py v1.6.1
exercise_router.py v1.6.2
Änderungen ggü. v1.6.0:
- **Idempotenz-Fix:** Qdrant-Scroll liefert nun explizit den Payload (`WithPayloadSelector(enable=True)`)
für `/exercise/by-external-id` und `/exercise/{id}`. Dadurch kann der Importer den gespeicherten
Fingerprint korrekt gegen den Recalc-Hash prüfen (keine Phantom-Updates mehr).
- Capability-Facetten & Listen-Normalisierung wie in v1.6.0.
- Keine API-Signaturänderungen.
Fix:
- Entfernt Import von `WithPayloadSelector` (nicht in allen qdrant-client Builds exportiert)
- Scroll-Aufrufe liefern Payload jetzt über `with_payload=True` (breit kompatibel)
- Rest wie v1.6.1: Capability-Facetten + Listen-Normalisierung, Idempotenz via external_id
"""
from fastapi import APIRouter, HTTPException, Query
@ -24,7 +22,6 @@ from qdrant_client.models import (
Filter,
FieldCondition,
MatchValue,
WithPayloadSelector,
)
import os
@ -93,7 +90,7 @@ def _lookup_by_external_id(external_id: str) -> Optional[Dict[str, Any]]:
collection_name=COLLECTION,
scroll_filter=flt,
limit=1,
with_payload=WithPayloadSelector(enable=True),
with_payload=True,
)
if not pts:
return None
@ -209,7 +206,7 @@ def get_exercise(exercise_id: str):
collection_name=COLLECTION,
scroll_filter=Filter(must=[FieldCondition(key="id", match=MatchValue(value=exercise_id))]),
limit=1,
with_payload=WithPayloadSelector(enable=True),
with_payload=True,
)
if not pts:
raise HTTPException(status_code=404, detail="not found")
@ -222,7 +219,7 @@ def get_exercise(exercise_id: str):
def delete_by_external_id(external_id: str = Query(...)):
_ensure_collection()
flt = Filter(must=[FieldCondition(key="external_id", match=MatchValue(value=external_id))])
pts, _ = qdrant.scroll(collection_name=COLLECTION, scroll_filter=flt, limit=10000, with_payload=WithPayloadSelector(enable=False))
pts, _ = qdrant.scroll(collection_name=COLLECTION, scroll_filter=flt, limit=10000, with_payload=False)
ids = [str(p.id) for p in pts]
if not ids:
return DeleteResponse(status="🔍 Keine Einträge gefunden.", count=0, collection=COLLECTION)