Repository navigation
fix: Ollama tool property types must be scalar - #342
Conversation
| properties <- lapply(x@properties, function(x) { | ||
| out <- as_json(provider, x) | ||
| if (!x@required) { | ||
| if (!x@required && provider@api_key != "ollama") { |
There was a problem hiding this comment.
This feels safe but a little hacky. chat_ollama() calls chat_openai() and sets api_key = "ollama". I briefly looked into adding a new ProviderOllama that inherits from ProviderOpenAI until I realized I could simply check here if the provider is Ollama. If you'd rather the ProviderOllama approach, I could go that way.
There was a problem hiding this comment.
Yeah, I'd rather make a single method(as_json, list(ProviderOllama, TypeObject)).
And should this warn to let the user know it isn't supported?
There was a problem hiding this comment.
Just a little more context: the reason I backed out of the ProviderOllama approach is because it involves untangling Ollama and OpenAI all the way up to chat_ollama(). I'm up for it, but just wanted to call out that it's a bigger change than adding a method.
I agree, a warning would make sense but should probably come from the $register_tool() call.
There was a problem hiding this comment.
I implemented ProviderOllama (fb07118) but while reading Ollama docs, I realized that Ollama is expecting the required properties in a separate array adjacent to properties (8ee8a59).
OpenAI, on the other hand, requires all properties to appear in required, so we still need a separate provider for Ollama.
1365595 to
8ee8a59
Compare
hadley
left a comment
There was a problem hiding this comment.
Thanks, that looks exactly like what I was expecting 😄
| properties <- lapply(x@properties, as_json, provider = provider) | ||
|
|
||
| # Unlike OpenAI, Ollama uses the `required` field to list required tool args | ||
| is_required <- vapply(x@properties, function(t) t@required, logical(1)) |
There was a problem hiding this comment.
You might take a quick look at some of the other provider methods for as_json(, TypeObject) just in case someone else uses the same pattern (which looks vaguely familiar to me)
There was a problem hiding this comment.
You're right, it's basically the same as for ProviderGroq. I refactored to match the code style. b094638
| testthat::skip("ollama not found") | ||
| } | ||
|
|
||
| testthat::skip_if_not( |
There was a problem hiding this comment.
Would you mind adding a test, even if it's not going to run on CI?
There was a problem hiding this comment.
Tests added in d3b42a1. I added one test around the shape of the tool def and one smoke test that chat_ollama() still works when a tool with optional arguments is registered.
Close match with `ProviderGroq`
|
Thanks! Just needs a news bullet and then I'll merge. |
|
I added one already 😊 (but I may have put it in the wrong place) |
|
FWIW our convention is to put new bullets at the top, but it doesn't really matter (and will get tweaked prior to releae) |
Problem
Ollama currently doesn't support arrays in the
tools.function.parameters.properties.typefield, instead it expects a scalar. ollama/ollama#5990In ellmer, this means that using
type_*(required = FALSE)results in the following warning:Edit: This behavior happens in the OpenAI-compatible API, Ollama's API supports
requiredas a separate field.After
This PR updates the
as_jsonmethod forProviderOpenAI, TypeObjectto avoid add"null"to theproperty.typewhen the provider is an Ollama model.