Skip to content

Commit 238dc3a

Browse files
authored
fix(ollama): fix the bug in streaming output of ollama chat model (#1082)
1 parent 17830ad commit 238dc3a

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/agentscope/model/_ollama_model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ async def _parse_ollama_stream_completion_response(
261261
print(f"Error parsing tool call input: {e}")
262262

263263
# Generate response when there's new content or at final chunk
264-
if chunk.done and contents:
264+
if chunk.done or contents:
265265
res = ChatResponse(
266266
content=contents,
267267
usage=usage,

tests/model_anthropic_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ async def mock_stream() -> AsyncGenerator:
318318
async for response in result:
319319
responses.append(response)
320320

321-
self.assertGreater(len(responses), 0)
321+
self.assertEqual(len(responses), 2)
322322
final_response = responses[-1]
323323
self.assertIsInstance(final_response, ChatResponse)
324324
expected_content = [

tests/model_ollama_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ async def test_streaming_response_processing(self) -> None:
281281
async for response in result:
282282
responses.append(response)
283283

284-
self.assertGreaterEqual(len(responses), 1)
284+
self.assertEqual(len(responses), 2)
285285
final_response = responses[-1]
286286
expected_content = [TextBlock(type="text", text="Hello there!")]
287287
self.assertEqual(final_response.content, expected_content)

tests/model_openai_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ async def test_streaming_response_processing(self) -> None:
244244
async for response in result:
245245
responses.append(response)
246246

247-
self.assertGreaterEqual(len(responses), 1)
247+
self.assertEqual(len(responses), 2)
248248
final_response = responses[-1]
249249
expected_content = [TextBlock(type="text", text="Hello there!")]
250250
self.assertEqual(final_response.content, expected_content)

0 commit comments

Comments
 (0)