feat(nlp-service): FastAPI app with /parse and /health endpoints

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-07 10:29:32 +02:00
parent cc4c81e218
commit 8521e6f173
2 changed files with 86 additions and 0 deletions

34
nlp-service/main.py Normal file
View File

@@ -0,0 +1,34 @@
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI, HTTPException
from extractor import extract, load_all_models
from models import ParseRequest, ParseResponse
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("Loading spaCy models...")
load_all_models()
logger.info("All models ready.")
yield
app = FastAPI(lifespan=lifespan)
@app.get("/health")
def health() -> dict:
return {"status": "ok"}
@app.post("/parse", response_model=ParseResponse)
def parse(request: ParseRequest) -> ParseResponse:
try:
return extract(request.query, request.lang)
except Exception as exc:
logger.exception("Extraction pipeline failed")
raise HTTPException(status_code=500, detail=str(exc)) from exc