fix(ocr): use camelCase field names in Pydantic models
Pydantic v2 Field(alias=...) doesn't work with FastAPI as expected. The Java client sends camelCase (pdfUrl, scriptType, pageNumber). Use camelCase field names directly instead of aliases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -56,9 +56,9 @@ async def run_ocr(request: OcrRequest):
|
|||||||
if not _models_ready:
|
if not _models_ready:
|
||||||
raise HTTPException(status_code=503, detail="Models not loaded yet")
|
raise HTTPException(status_code=503, detail="Models not loaded yet")
|
||||||
|
|
||||||
images = await _download_and_convert_pdf(request.pdf_url)
|
images = await _download_and_convert_pdf(request.pdfUrl)
|
||||||
|
|
||||||
script_type = request.script_type.upper()
|
script_type = request.scriptType.upper()
|
||||||
|
|
||||||
if script_type == "HANDWRITING_KURRENT":
|
if script_type == "HANDWRITING_KURRENT":
|
||||||
if not kraken_engine.is_available():
|
if not kraken_engine.is_available():
|
||||||
|
|||||||
@@ -1,20 +1,21 @@
|
|||||||
from pydantic import BaseModel, Field
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
|
|
||||||
class OcrRequest(BaseModel):
|
class OcrRequest(BaseModel):
|
||||||
pdf_url: str = Field(..., alias="pdfUrl")
|
model_config = ConfigDict(populate_by_name=True)
|
||||||
script_type: str = Field("UNKNOWN", alias="scriptType")
|
|
||||||
|
pdfUrl: str
|
||||||
|
scriptType: str = "UNKNOWN"
|
||||||
language: str = "de"
|
language: str = "de"
|
||||||
|
|
||||||
|
|
||||||
class OcrBlock(BaseModel):
|
class OcrBlock(BaseModel):
|
||||||
page_number: int = Field(..., alias="pageNumber")
|
model_config = ConfigDict(populate_by_name=True)
|
||||||
|
|
||||||
|
pageNumber: int
|
||||||
x: float
|
x: float
|
||||||
y: float
|
y: float
|
||||||
width: float
|
width: float
|
||||||
height: float
|
height: float
|
||||||
polygon: list[list[float]] | None = None
|
polygon: list[list[float]] | None = None
|
||||||
text: str
|
text: str
|
||||||
|
|
||||||
class Config:
|
|
||||||
populate_by_name = True
|
|
||||||
|
|||||||
Reference in New Issue
Block a user