mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Check tool called when stream is set to true #159
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 @javixeneize on GitHub (Nov 5, 2024).
Hi
I am validating in my code which tools are called in Ollama by printing this:
print(response["message"].get("tool_calls"))
When i set stream to true like this
I have this error
TypeError: 'generator' object is not subscriptable
How can i check which tools the LLM is calling when stream is set to true?
Thanks
@ParthSareen commented on GitHub (Nov 14, 2024):
Hey! Since yield is a generator you'd have to convert it something you can access. You'd need to yield to a variable and then convert to a list. I'd just recommend checking out our example: https://github.com/ollama/ollama-python/blob/main/examples/tools/main.py
@javixeneize commented on GitHub (Nov 19, 2024):
Hi
Yeah, i checked that example but it doesnt stream the output. I know how to use tools, what i need to know is how to use tools together with the stream functionality
@ParthSareen can you help me with an example that combines stream and tools in the same call?
Thanks
@ParthSareen commented on GitHub (Nov 19, 2024):
We don't have streaming tools enabled yet unfortunately but it is something we are looking into!
@javixeneize commented on GitHub (Nov 19, 2024):
Thanks! i will keep an eye into it
@AlejoPrietoDavalos commented on GitHub (Feb 6, 2025):
Hi @ParthSareen.
I need the same thing, to be able to use stream=True and have a reliable way to know if there was a tool call or if I should just stream the bot's response.
Is there an issue where this is being discussed?
Thanks
@ParthSareen commented on GitHub (Feb 6, 2025):
@AlejoPrietoDavalos you'd currently be able to either see complete tool calls or a chunk of the response with
contentso you have a way to decipher whether tools are coming or not