mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix: harden classify response handling
This commit is contained in:
parent
51be2e42f2
commit
7c21da5caa
3 changed files with 13 additions and 4 deletions
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue