mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-26 06:03:19 +00:00
fix(aiohttp_openai): forward service_tier onto the ModelResponse
This commit is contained in:
parent
cfee0ffe41
commit
ee2ee58661
2 changed files with 38 additions and 0 deletions
|
|
@ -86,4 +86,7 @@ class AiohttpOpenAIChatConfig(OpenAILikeChatConfig):
|
|||
model_response.model = _json_response.get("model")
|
||||
model_response.object = _json_response.get("object")
|
||||
model_response.system_fingerprint = _json_response.get("system_fingerprint")
|
||||
service_tier: Final = _json_response.get("service_tier")
|
||||
if isinstance(service_tier, str) and service_tier:
|
||||
setattr(model_response, "service_tier", service_tier) # noqa: B010 # pydantic extra, not a declared field
|
||||
return model_response
|
||||
|
|
|
|||
|
|
@ -99,3 +99,38 @@ async def test_transform_response_rejects_choices_that_are_not_a_list_of_objects
|
|||
async def test_transform_response_rejects_a_choice_whose_message_is_not_an_object():
|
||||
with pytest.raises(ValidationError, match="validation error for Choices"):
|
||||
await _transform({"choices": [{"message": "text"}]})
|
||||
|
||||
|
||||
async def test_transform_response_forwards_service_tier():
|
||||
response = await _transform(
|
||||
{
|
||||
"id": "chatcmpl-1",
|
||||
"created": 1700000000,
|
||||
"model": "gpt-4o",
|
||||
"object": "chat.completion",
|
||||
"service_tier": "flex",
|
||||
"choices": [
|
||||
{"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "Hi"}},
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
assert response.service_tier == "flex"
|
||||
|
||||
|
||||
async def test_transform_response_omits_service_tier_when_absent_or_blank():
|
||||
for service_tier in (None, "", 42):
|
||||
body: dict = {
|
||||
"id": "chatcmpl-1",
|
||||
"created": 1700000000,
|
||||
"model": "gpt-4o",
|
||||
"object": "chat.completion",
|
||||
"choices": [
|
||||
{"index": 0, "finish_reason": "stop", "message": {"role": "assistant", "content": "Hi"}},
|
||||
],
|
||||
}
|
||||
if service_tier is not None:
|
||||
body["service_tier"] = service_tier
|
||||
response = await _transform(body)
|
||||
|
||||
assert getattr(response, "service_tier", None) is None
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue