@@ -267,6 +267,70 @@ def test_callback(chunk: StreamingChunk):
267267 assert streaming_chunks [1 ].start is False
268268 assert streaming_chunks [2 ].start is False
269269
270+ def test_handle_streaming_response_with_thinking (self ):
271+ ollama_chunks = [
272+ ChatResponse (
273+ model = "qwen3:0.6b" ,
274+ created_at = "2025-07-31T15:27:09.265818Z" ,
275+ done = False ,
276+ message = Message (role = "assistant" , content = "" , thinking = "Let me think" ),
277+ ),
278+ ChatResponse (
279+ model = "qwen3:0.6b" ,
280+ created_at = "2025-07-31T15:27:09.265818Z" ,
281+ done = False ,
282+ message = Message (role = "assistant" , content = "" , thinking = " about this." ),
283+ ),
284+ ChatResponse (
285+ model = "qwen3:0.6b" ,
286+ created_at = "2025-07-31T15:27:09.265818Z" ,
287+ done = False ,
288+ message = Message (role = "assistant" , content = "The capital" ),
289+ ),
290+ ChatResponse (
291+ model = "qwen3:0.6b" ,
292+ created_at = "2025-07-31T15:27:09.265818Z" ,
293+ done = False ,
294+ message = Message (role = "assistant" , content = " is Amman." ),
295+ ),
296+ ChatResponse (
297+ model = "qwen3:0.6b" ,
298+ created_at = "2025-07-31T15:27:09.355211Z" ,
299+ done = True ,
300+ done_reason = "stop" ,
301+ total_duration = 1303416458 ,
302+ load_duration = 953922333 ,
303+ prompt_eval_count = 22 ,
304+ prompt_eval_duration = 254166208 ,
305+ eval_count = 3 ,
306+ eval_duration = 92965792 ,
307+ message = Message (role = "assistant" , content = "" ),
308+ ),
309+ ]
310+
311+ generator = OllamaChatGenerator ()
312+ streaming_chunks = []
313+
314+ def test_callback (chunk : StreamingChunk ):
315+ streaming_chunks .append (chunk )
316+
317+ response = generator ._handle_streaming_response (ollama_chunks , test_callback )
318+ assert response ["replies" ][0 ].text == "The capital is Amman."
319+ assert response ["replies" ][0 ].reasoning .reasoning_text == "Let me think about this."
320+
321+ assert len (streaming_chunks ) == 5
322+ # First reasoning chunk: start=True
323+ assert streaming_chunks [0 ].start is True
324+ assert streaming_chunks [0 ].reasoning .reasoning_text == "Let me think"
325+ # Second reasoning chunk: start=False
326+ assert streaming_chunks [1 ].start is False
327+ # First content chunk after reasoning: start=True
328+ assert streaming_chunks [2 ].start is True
329+ assert streaming_chunks [2 ].content == "The capital"
330+ # Remaining content chunks: start=False
331+ assert streaming_chunks [3 ].start is False
332+ assert streaming_chunks [4 ].start is False
333+
270334 def test_handle_streaming_response_tool_calls (self ):
271335 ollama_chunks = [
272336 ChatResponse (
0 commit comments