mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Streaming Doesn't Work When Using Tools #233
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @VacantHusky on GitHub (Mar 7, 2025).
Description
When using
toolswithstream=Truein thechatfunction, the streaming output doesn't work as expected. The responses are not yielded incrementally, but instead, they seem to be processed only after all tool calls are completed.Steps to Reproduce
Expected Behavior
The response should be streamed incrementally, even when tool calls are involved.
Actual Behavior
Environment
Additional Information
It seems like the
OLLAMA_CLIENT.chatfunction doesn't return partial results when tool calls are required. Is there a way to make tool calls asynchronous while maintaining streaming behavior?@antoninoLorenzo commented on GitHub (Mar 11, 2025):
Hi, when you provide tools to
chatand setstream=Trueyou'll either get a normal streams if the model doesn't call any tool, or, in your case, you should get two dictionaries, the first containing thetool_callskey and the second will contain some metadata such aseval_countand similar.Basically in your code the parts should be something like the following:
@lemassykoi commented on GitHub (Mar 17, 2025):
I finally understand what you mean:
I adapted your script, and I'm sending 2 inputs to LLM (with messages from input 1 passed to input 2, to simulate history).
First input is asking the same question as yours, which involve 2 tools calls.
For me the result is acceptable:
but for second input, which involves 2 other functions, it's not the same behavior (notice the tool call results logged at the exact same time):
but, I'm not sure if the LLM got the tool output at the same time than me, as it's thinking process doesn't reflect problems:
I also had been positively surprised that this setup makes the LLM to be able to retry on tool call errors
@8LWXpg commented on GitHub (Mar 19, 2025):
Can reproduce this issue
Script used:
With
toolshttps://github.com/user-attachments/assets/b7871045-1cfb-4384-9b16-19d4868dafad
With
toolscommented:https://github.com/user-attachments/assets/a7d0a8ee-6f16-4412-b53d-a5431837b128
@8LWXpg commented on GitHub (Mar 19, 2025):
After further testing with API, I can conclude that the issue is from the model API itself, not the python binding
/api/chat@lemassykoi commented on GitHub (Mar 22, 2025):
https://github.com/ollama/ollama/issues/6127
@8LWXpg commented on GitHub (Mar 23, 2025):
https://github.com/ollama/ollama/pull/9938
@ParthSareen commented on GitHub (Mar 31, 2025):
Being worked on! Will try to get back to it soon https://github.com/ollama/ollama/pull/10028
@MohamedYasserOaf commented on GitHub (May 2, 2025):
@ParthSareen any updates ?
@ParthSareen commented on GitHub (May 2, 2025):
almost here!! https://github.com/ollama/ollama/pull/10415 @MohamedYasserOaf
@MohamedYasserOaf commented on GitHub (May 2, 2025):
@ParthSareen caught you in the middle of the heat xD , good luck and looking forward to the fix.
@tobiaswuerth commented on GitHub (May 10, 2025):
yes please
@mukesh-dream11 commented on GitHub (May 15, 2025):
@ParthSareen hope this lands soon! Fingers crossed :)
@jonigl commented on GitHub (May 19, 2025):
Experiencing the same issue. When tools are available but not called by the model, the response is returned all at once instead of streaming incrementally.
@ParthSareen commented on GitHub (May 26, 2025):
Will be in next release!