Check tool called when stream is set to true #159

Closed
opened 2026-02-15 16:28:22 -05:00 by yindo · 6 comments
Owner

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

    response = client.chat(
        model="llama3.2",
        messages=messages,
        tools=tools,
        stream=True)
    for chunk in response:
        yield chunk["message"]["content"]
   print(response["message"].get("tool_calls"))

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

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 ``` response = client.chat( model="llama3.2", messages=messages, tools=tools, stream=True) for chunk in response: yield chunk["message"]["content"] print(response["message"].get("tool_calls")) ``` 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
yindo closed this issue 2026-02-15 16:28:22 -05:00
Author
Owner

@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

@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
Author
Owner

@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

@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
Author
Owner

@ParthSareen commented on GitHub (Nov 19, 2024):

We don't have streaming tools enabled yet unfortunately but it is something we are looking into!

@ParthSareen commented on GitHub (Nov 19, 2024): We don't have streaming tools enabled yet unfortunately but it is something we are looking into!
Author
Owner

@javixeneize commented on GitHub (Nov 19, 2024):

Thanks! i will keep an eye into it

@javixeneize commented on GitHub (Nov 19, 2024): Thanks! i will keep an eye into it
Author
Owner

@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

@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
Author
Owner

@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 content so you have a way to decipher whether tools are coming or not

@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 `content` so you have a way to decipher whether tools are coming or not
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ollama/ollama-python#159