This commit is contained in:
Saylee 2026-11-04 05:55:29 +00:00 • committed by GitHub
commit 9de76e4ea7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 0 deletions

View file

@ -1129,6 +1129,7 @@ class CustomStreamWrapper:
and model_response.choices[0].delta.role is not None
)
or (getattr(model_response.choices[0].delta, "reasoning_items", None) is not None)
or (getattr(model_response.choices[0].delta, "refusal", None) is not None)
):
return True
else:

View file

@ -276,6 +276,31 @@ def test_is_chunk_non_empty(initialized_custom_stream_wrapper: CustomStreamWrapp
)
def test_is_chunk_non_empty_with_refusal(
initialized_custom_stream_wrapper: CustomStreamWrapper,
):
"""Unit test if non-empty when the delta carries only a refusal"""
chunk: Final = {
"id": "chatcmpl-abc",
"object": "chat.completion.chunk",
"created": 1700000000,
"model": "m",
"choices": [
{
"index": 0,
"delta": {"refusal": "I can't help"},
"logprobs": None,
"finish_reason": None,
}
],
}
assert initialized_custom_stream_wrapper.is_chunk_non_empty(
completion_obj=MagicMock(),
model_response=ModelResponseStream(**chunk),
response_obj=MagicMock(),
)
def test_is_chunk_non_empty_with_annotations(
initialized_custom_stream_wrapper: CustomStreamWrapper,
):