mirror of
https://github.com/ollama/ollama-python.git
synced 2026-07-21 09:05:23 -04:00
Calling chat with function as tool gives an empty response #173
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 @mjvmiller on GitHub (Nov 27, 2024).
I defined a test function as:
I initialize it as a tool using:
Finally, using
oclient = ollama.Client(host="localhost"), I call:The latter prints nothing, while the former prints
role='assistant' content='' images=None tool_calls=[ToolCall(function=Function(name='alfalfa', arguments={'a': '2', 'b': '4'}))]. When I omit thetools=..., I get a response as normal:I had similar results with other functions tested. This is on the latest version (v0.4.1).
@ameen-91 commented on GitHub (Nov 29, 2024):
Its the expected behaviour. In
[ToolCall(function=Function(name='alfalfa', arguments={'a': '2', 'b': '4'}))], the tool is being called with the correct parameters.As for the json definition, I can get the output:
Output:
@mjvmiller commented on GitHub (Nov 29, 2024):
Just to clarify, the expected behavior of asking the model a question is to receive no answer? I can see this behaviour being useful for cases such as asking the model to turn on/off a setting in an app, but does the current state of the api allow for the model to use tools to inform its response to the user?
@ParthSareen commented on GitHub (Nov 29, 2024):
@mjm9189 Hey! So the initial call to the LLM just generates a toolcall - which is what you need to use to execute your function with the provided params. You can pass the output of the tool back to the LLM and generate a response for the user. There's an example in the JS repo for this - will add one for python soon too! https://github.com/ollama/ollama-js/blob/main/examples/tools/tools.ts
Hope this helps!
@mjvmiller commented on GitHub (Nov 29, 2024):
Amazing, thank you for the help! I'd only looked through the Python one so far, but I'm glad it's being updated soon. Thanks again!
@ParthSareen commented on GitHub (Nov 29, 2024):
@mjm9189 Just updated! https://github.com/ollama/ollama-python/blob/main/examples/tools.py