zed icon indicating copy to clipboard operation
zed copied to clipboard

ollama: Add tool call support

Open tidely opened this issue 8 months ago • 5 comments

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::Value inside OllamaFunctionCall just as it's used in OllamaFunctionCall. 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_tools setting 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_tools field for ollama language model config
  • [ ] Convert between generic language model types
  • [x] Pass tools to ollama

Release Notes:

  • N/A

tidely avatar Apr 28 '25 20:04 tidely

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.

tidely avatar Apr 29 '25 07:04 tidely

The show model information API should have what you're looking for. You'll just have to call it on each model.

lj3954 avatar Apr 29 '25 16:04 lj3954

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 :(

tidely avatar Apr 29 '25 17:04 tidely

Does it not? The capabilities key contains "tools" on llama models which have tool support. Are there models where this doesn't apply?

lj3954 avatar Apr 29 '25 17:04 lj3954

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.

tidely avatar Apr 29 '25 17:04 tidely

@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!

tidely avatar May 04 '25 21:05 tidely

Thanks so much for getting this started! Very helpful :heart:

nathansobo avatar May 05 '25 17:05 nathansobo

Really nice work here, @tidely! We made some small tweaks to your pull request, but it was already working great for the most part!

as-cii avatar May 05 '25 17:05 as-cii