@@ -459,6 +459,28 @@ def test_chunk_parser_normal_response(self):
459459 assert result .choices and result .choices [0 ].delta is not None
460460 assert result .choices [0 ].delta .content == "Hello world"
461461 assert getattr (result .choices [0 ].delta , "reasoning_content" , None ) is None
462+
463+ def test_chunk_parser_empty_response_without_thinking (self ):
464+ """Test that empty response chunks without thinking still work."""
465+ iterator = OllamaTextCompletionResponseIterator (
466+ streaming_response = iter ([]), sync_stream = True , json_mode = False
467+ )
468+
469+ # Test empty response chunk without thinking
470+ empty_response_chunk = {
471+ "model" : "qwen3:4b" ,
472+ "created_at" : "2025-10-16T11:27:14.82881Z" ,
473+ "response" : "" ,
474+ "done" : False ,
475+ }
476+
477+ result = iterator .chunk_parser (empty_response_chunk )
478+
479+ # Updated to handle ModelResponseStream return type
480+ assert isinstance (result , ModelResponseStream )
481+ assert result .choices and result .choices [0 ].delta is not None
482+ assert result .choices [0 ].delta .content == None
483+ assert getattr (result .choices [0 ].delta , "reasoning_content" , None ) is ""
462484
463485 def test_chunk_parser_done_chunk (self ):
464486 """Test that done chunks work correctly."""
@@ -482,6 +504,6 @@ def test_chunk_parser_done_chunk(self):
482504 assert result ["is_finished" ] is True
483505 assert result ["finish_reason" ] == "stop"
484506 assert result ["usage" ] is not None
485- assert result ["usage" ]["prompt_tokens" ] == 10
486- assert result ["usage" ]["completion_tokens" ] == 5
487- assert result ["usage" ]["total_tokens" ] == 15
507+ assert result ["usage" ]["prompt_tokens" ] == 10 # pyright: ignore[reportOptionalSubscript]
508+ assert result ["usage" ]["completion_tokens" ] == 5 # pyright: ignore[reportOptionalSubscript]
509+ assert result ["usage" ]["total_tokens" ] == 15 # pyright: ignore[reportOptionalSubscript]
0 commit comments