mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-26 06:03:19 +00:00
Merge a98d9d5964 into 934ecdca78
This commit is contained in:
commit
b3d2fc5e5b
1 changed files with 16 additions and 0 deletions
|
|
@ -803,6 +803,22 @@ class OpenAIChatCompletionStreamingHandler(BaseModelResponseIterator):
|
|||
|
||||
def chunk_parser(self, chunk: dict) -> ModelResponseStream:
|
||||
try:
|
||||
# Handle error responses embedded in SSE streams (e.g. from sglang)
|
||||
if "error" in chunk:
|
||||
error_data = chunk["error"]
|
||||
if isinstance(error_data, dict):
|
||||
error_message = error_data.get("message", str(error_data))
|
||||
error_code = error_data.get("code", 400)
|
||||
else:
|
||||
error_message = str(error_data)
|
||||
error_code = 400
|
||||
raise litellm.BadRequestError(
|
||||
message=f"Received error in stream: {error_message}",
|
||||
model=chunk.get("model", ""),
|
||||
llm_provider=self.custom_llm_provider,
|
||||
response=httpx.Response(status_code=error_code, request=httpx.Request(method="POST", url="")),
|
||||
)
|
||||
|
||||
choices = chunk.get("choices", [])
|
||||
choices = self._map_reasoning_to_reasoning_content(choices)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue