mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-22 00:31:44 +00:00
fix(streaming): skip role-only first chunk when logprobs.content is empty
When logprobs are requested, OpenAI's first streaming chunk has role='assistant' and logprobs=ChoiceLogprobs(content=[]). The Azure streaming fix (PR #25638) made is_chunk_non_empty() treat any first chunk with a non-None role as non-empty, which caused this role-only chunk to be emitted. Callers checking 'logprobs in chunk.choices[0]' then crashed on logprobs.content[0] (IndexError: list index out of range). Guard the role condition: don't emit the first chunk as non-empty when logprobs is present but has no content entries. Azure's use case (no logprobs, empty choices[]) is unaffected.
This commit is contained in:
parent
473f5dc4ba
commit
bd5740a367
1 changed files with 4 additions and 0 deletions
|
|
@ -839,6 +839,10 @@ class CustomStreamWrapper:
|
|||
not self.sent_first_chunk
|
||||
and hasattr(model_response.choices[0].delta, "role")
|
||||
and model_response.choices[0].delta.role is not None
|
||||
and not (
|
||||
model_response.choices[0].logprobs is not None
|
||||
and not model_response.choices[0].logprobs.content
|
||||
)
|
||||
)
|
||||
):
|
||||
return True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue