-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Ollama streamed tool calls. Set finish_reason to tool_calls for all tool_calls responses #3469
Fix Ollama streamed tool calls. Set finish_reason to tool_calls for all tool_calls responses #3469
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8 tests added here for (ollama, ollama_chat) x (stream False, True) x (def, async def). All passing locally for me (mac, ollama running in background) - I'm not sure how your automated testing will handle this.
Command to run just these
poetry run pytest -vv test_completion.py::test_completion_ollama_function_call test_completion.py::test_completion_ollama_function_call_stream test_completion.py::test_acompletion_ollama_function_call test_completion.py::test_acompletion_ollama_function_call_stream
Title
Fix Ollama streamed tool calls. Set finish_reason to tool_calls for all tool_calls responses
Relevant issues
Fixes #3333
Fixes #2209
Closes #2597
Type
🐛 Bug Fix
Changes
ollama/
andollama_chat/
responsesfinish_reason
to "tool_calls" for allollama/
andollama_chat/
responsesdata
instead ofoptional_params
so that JSON response format is correctly detected in ollama completion.For the streamed tool calls the entire response is joined before parsing, so only one chunk/delta is yielded. This makes it much easier to parse out the function name and arguments. In future it would be nice to update this to stream the tool calls the same way openai does.
Testing
Adapted the test cases from #3333
which output
Pre-Submission Checklist (optional but appreciated):
OS Tests (optional but appreciated):