This commit is contained in:
DDDonut 2026-09-04 11:45:06 +08:00 committed by GitHub
commit 3011bc49dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View file

@ -872,6 +872,8 @@ class OpenAIChatCompletionStreamingHandler(BaseModelResponseIterator):
}
if "usage" in chunk and chunk["usage"] is not None:
kwargs["usage"] = chunk["usage"]
if "service_tier" in chunk and chunk["service_tier"] is not None:
kwargs["service_tier"] = chunk["service_tier"]
return ModelResponseStream(**kwargs)
except Exception as e:
raise e

View file

@ -5,7 +5,6 @@ Tests for OpenAI GPT transformation (litellm/llms/openai/chat/gpt_transformation
import pytest
import litellm
from litellm.litellm_core_utils.prompt_templates.common_utils import TOOL_RESULT_IMAGE_BOUNDARY
from litellm.llms.openai.chat.gpt_5_transformation import OpenAIGPT5Config
@ -247,6 +246,24 @@ class TestOpenAIChatCompletionStreamingHandler:
assert result.usage.completion_tokens == 350
assert result.usage.total_tokens == 14147
def test_chunk_parser_preserves_service_tier(self):
"""Provider service-tier responses must survive chunk normalization."""
handler = OpenAIChatCompletionStreamingHandler(
streaming_response=None, sync_stream=True
)
result = handler.chunk_parser(
{
"id": "gen-123",
"created": 1234567890,
"model": "xai/grok-4.6",
"choices": [],
"service_tier": "priority",
}
)
assert result.service_tier == "priority"
def test_chunk_parser_raises_on_in_body_error_payload(self):
"""vLLM/sglang return HTTP 200 streams whose body carries the error,
e.g. data: {"error": {..., "code": 400}}. chunk_parser must surface it