ollama: Add tool call support
The goal of this PR is to support tool calls using ollama. A lot of the serialization work was done in https://github.com/zed-industries/zed/pull/15803 however the abstraction over language models always disables tools.
Changelog:
- Use
serde_json::ValueinsideOllamaFunctionCalljust as it's used inOllamaFunctionCall. This fixes deserialization of ollama tool calls. - Added deserialization tests using json from official ollama api docs.
- Fetch model capabilities during model enumeration from ollama provider
- Added
supports_toolssetting to manually configure if a model supports tools
TODO:
- [x] Fix tool call serialization/deserialization
- [x] Fetch model capabilities from ollama api
- [x] Add tests for parsing model capabilities
- [ ] Documentation for
supports_toolsfield for ollama language model config - [ ] Convert between generic language model types
- [x] Pass tools to ollama
Release Notes:
- N/A
The best way to allow tool calls on specific models is likely to have the user explicitly allow tools on specific models in settings.json under the ollama provider. However this means ollama wouldn't work with the agent crate out of the box, rather a user must enable it by allowing tools calls manually.
The show model information API should have what you're looking for. You'll just have to call it on each model.
The show model information API should have what you're looking for. You'll just have to call it on each model.
Unfortunately I believe the show endpoint does not contain a field for whether the model supports tools. Atleast not one which would be consistent across different model families :(
Does it not? The capabilities key contains "tools" on llama models which have tool support. Are there models where this doesn't apply?
I just checked with a bunch of different model families are it seems I was wrong! Thank you @lj3954, I'll work on something to make use of it.
@mgsloan Hey! I saw you recently worked on https://github.com/zed-industries/zed/pull/29885. I looked at creating a similar map_to_completion_events function for the ollama provider, but it doesn't seem to be working as I hoped for. Would you like to take a look at this PR's implementation and see if there's anything you could point out at a quick glance? Otherwise I'll schedule myself a deep dive into the agent crate. Thank you in advance!
Thanks so much for getting this started! Very helpful :heart:
Really nice work here, @tidely! We made some small tweaks to your pull request, but it was already working great for the most part!