Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle unknown hi_res_model_name #332

Merged
merged 3 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.61-dev0

* Handle invalid hi_res_model_name kwarg

## 0.0.60

* Enable self-hosted authorization using UNSTRUCTURED_API_KEY env variable
Expand Down
2 changes: 1 addition & 1 deletion prepline_general/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
app = FastAPI(
title="Unstructured Pipeline API",
description="""""",
version="0.0.60",
version="0.0.61",
docs_url="/general/docs",
openapi_url="/general/openapi.json",
)
Expand Down
9 changes: 8 additions & 1 deletion prepline_general/api/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
elements_from_json,
)
from unstructured_inference.models.chipper import MODEL_TYPES as CHIPPER_MODEL_TYPES
from unstructured_inference.models.base import UnknownModelException


app = FastAPI()
Expand Down Expand Up @@ -470,6 +471,12 @@ def pipeline_api(
detail="File is not a valid docx",
)

except UnknownModelException:
raise HTTPException(
status_code=400,
detail=f"Unknown model type: {hi_res_model_name}",
)

# Clean up returned elements
# Note(austin): pydantic should control this sort of thing for us
for i, element in enumerate(elements):
Expand Down Expand Up @@ -675,7 +682,7 @@ def return_content_type(filename):


@router.post("/general/v0/general")
@router.post("/general/v0.0.60/general")
@router.post("/general/v0.0.61/general")
def pipeline_1(
request: Request,
gz_uncompressed_content_type: Optional[str] = Form(default=None),
Expand Down
2 changes: 1 addition & 1 deletion preprocessing-pipeline-family.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
name: general
version: 0.0.60
version: 0.0.61
16 changes: 16 additions & 0 deletions test_general/api/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -900,3 +900,19 @@ def test_chipper_not_available_errors(monkeypatch, mocker, exception, status_cod

assert resp.status_code == status_code
assert resp.json().get("detail") == message


def test_invalid_hi_res_model_name_returns_400():
"""Verify that we get a 400 if we pass in a bad model_name"""
client = TestClient(app)
test_file = Path("sample-docs") / "layout-parser-paper-fast.pdf"
response = client.post(
MAIN_API_ROUTE,
files=[("files", (str(test_file), open(test_file, "rb")))],
data={
"strategy": "hi_res",
"hi_res_model_name": "invalid_model",
},
)
assert response.status_code == 400
assert "Unknown model type" in response.text