Skip to content

Commit ed411bd

Browse files
authored
Handle unknown hi_res_model_name (#332)
Closes #330 Raises 400 error if hi_res_model_name is an unknown model.
1 parent 5e10fba commit ed411bd

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.61-dev0
2+
3+
* Handle invalid hi_res_model_name kwarg
4+
15
## 0.0.60
26

37
* Enable self-hosted authorization using UNSTRUCTURED_API_KEY env variable

prepline_general/api/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
app = FastAPI(
1212
title="Unstructured Pipeline API",
1313
description="""""",
14-
version="0.0.60",
14+
version="0.0.61",
1515
docs_url="/general/docs",
1616
openapi_url="/general/openapi.json",
1717
)

prepline_general/api/general.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
elements_from_json,
4848
)
4949
from unstructured_inference.models.chipper import MODEL_TYPES as CHIPPER_MODEL_TYPES
50+
from unstructured_inference.models.base import UnknownModelException
5051

5152

5253
app = FastAPI()
@@ -470,6 +471,12 @@ def pipeline_api(
470471
detail="File is not a valid docx",
471472
)
472473

474+
except UnknownModelException:
475+
raise HTTPException(
476+
status_code=400,
477+
detail=f"Unknown model type: {hi_res_model_name}",
478+
)
479+
473480
# Clean up returned elements
474481
# Note(austin): pydantic should control this sort of thing for us
475482
for i, element in enumerate(elements):
@@ -675,7 +682,7 @@ def return_content_type(filename):
675682

676683

677684
@router.post("/general/v0/general")
678-
@router.post("/general/v0.0.60/general")
685+
@router.post("/general/v0.0.61/general")
679686
def pipeline_1(
680687
request: Request,
681688
gz_uncompressed_content_type: Optional[str] = Form(default=None),

preprocessing-pipeline-family.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
name: general
2-
version: 0.0.60
2+
version: 0.0.61

test_general/api/test_app.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,3 +900,19 @@ def test_chipper_not_available_errors(monkeypatch, mocker, exception, status_cod
900900

901901
assert resp.status_code == status_code
902902
assert resp.json().get("detail") == message
903+
904+
905+
def test_invalid_hi_res_model_name_returns_400():
906+
"""Verify that we get a 400 if we pass in a bad model_name"""
907+
client = TestClient(app)
908+
test_file = Path("sample-docs") / "layout-parser-paper-fast.pdf"
909+
response = client.post(
910+
MAIN_API_ROUTE,
911+
files=[("files", (str(test_file), open(test_file, "rb")))],
912+
data={
913+
"strategy": "hi_res",
914+
"hi_res_model_name": "invalid_model",
915+
},
916+
)
917+
assert response.status_code == 400
918+
assert "Unknown model type" in response.text

0 commit comments

Comments
 (0)