Skip to content

Commit 3d52232

Browse files
authored
Merge pull request #24 from kagent-dev/peterj/fixollamaendlessloop
set the final content to "" instead of [] -- this prevents endless lo…
2 parents 8fc21ee + de49499 commit 3d52232

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,15 +806,21 @@ async def create_stream(
806806
completion_tokens = chunk.eval_count
807807
else:
808808
completion_tokens = 0
809-
elif len(content_chunks) > 1:
809+
elif len(content_chunks) > 0:
810810
content = "".join(content_chunks)
811811
if chunk and chunk.eval_count:
812812
completion_tokens = chunk.eval_count
813813
else:
814814
completion_tokens = 0
815+
elif len(full_tool_calls) > 0:
816+
content = full_tool_calls
817+
completion_tokens = chunk.eval_count if chunk and chunk.eval_count else 0
818+
elif normalize_stop_reason(stop_reason) == "stop":
819+
content = ""
820+
completion_tokens = 0
815821
else:
822+
content = []
816823
completion_tokens = 0
817-
content = full_tool_calls
818824

819825
usage = RequestUsage(
820826
prompt_tokens=prompt_tokens,

0 commit comments

Comments
 (0)