fix: harden classify response handling

This commit is contained in:
Devin AI 2026-07-10 09:42:14 +00:00
parent 51be2e42f2
commit 7c21da5caa
3 changed files with 13 additions and 4 deletions

View file

@ -384,7 +384,8 @@ def classification_passthrough_request(
client=client,
timeout=timeout,
)
assert isinstance(response, httpx.Response)
if not isinstance(response, httpx.Response):
raise TypeError(f"Expected httpx.Response from classify passthrough, got {type(response).__name__}")
return response
@ -411,7 +412,8 @@ async def aclassification_passthrough_request(
client=client,
timeout=timeout,
)
assert isinstance(response, httpx.Response)
if not isinstance(response, httpx.Response):
raise TypeError(f"Expected httpx.Response from classify passthrough, got {type(response).__name__}")
return response

View file

@ -22,7 +22,7 @@ class ClassificationData(BaseModel):
model_config = ConfigDict(extra="allow")
index: int
label: str | None
label: str | None = None
probs: list[float]
num_classes: int

View file

@ -69,7 +69,13 @@ async def test_aclassify_accepts_token_ids() -> None:
"priority": 0,
"add_special_tokens": False,
}
return httpx.Response(status_code=200, json=CLASSIFICATION_RESPONSE)
return httpx.Response(
status_code=200,
json={
**CLASSIFICATION_RESPONSE,
"data": [{"index": 0, "probs": [0.1, 0.9], "num_classes": 2}],
},
)
async with httpx.AsyncClient(transport=httpx.MockTransport(transport)) as async_client:
response = await litellm.aclassify(
@ -82,3 +88,4 @@ async def test_aclassify_accepts_token_ids() -> None:
assert isinstance(response, ClassificationResponse)
assert response.id == "classify-test"
assert response.data[0].label is None