10000 ensure that zero-arg tools have valid parameters struct by tazjin · Pull Request #906 · karthink/gptel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ensure that zero-arg tools have valid parameters struct #906

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tazjin
Copy link
@tazjin tazjin commented Jun 12, 2025

Some implementations of the OpenAI API (notably, when talking to OpenAI's o3 and up) require tools that have no parameters to still supply a valid object describing them instead of just null.

OpenAI's own older implementations (e.g. when talking to 4.1) handle null fine, and so do basically all other OpenAI-like endpoints I've tested. All implementations seem to work with the empty but valid object.

I read the docs for json-serialize and couldn't figure out another way to ensure that we get an empty {} instead of just a :null, hence the empty hash-table.

@karthink
Copy link
Owner
karthink commented Jun 12, 2025

Thanks for the PR.

Is there some reason this doesn't work?

(gptel--json-encode '(:parameters (:type "object" :properties nil)))
;; => {"parameters":{"type":"object","properties":{}}}

All implementations seem to work with the empty but valid object.

It was changed recently to :parameters :null because of compatibility issues (#818), so we need to be sure of this. What providers have you tried besides OpenAI?

@tazjin
Copy link
Author
tazjin commented Jun 13, 2025

Is there some reason this doesn't work?

Huh, that does work. For some reason I was sure that nil would serialise as an empty list, but in testing this does yield the correct {} object.

What providers have you tried besides OpenAI?

OpenAI (various models), company-internal proxy to various models, Anthropic.

I'm going to be running this patch for a while and try some more models. For now I haven't run into any issues. It could at least be a config option if you want to be overly cautious, but I don't see much reason why a "more valid" object would cause failures than a "less valid" one.

By the way, thanks for gptel - it is by far the best interface to these things that exists so far. I mean in general, not just in Emacs.

@karthink
Copy link
Owner

OpenAI (various models), company-internal proxy to various models, Anthropic.

The non-uniformity of behavior is across "OpenAI-compatible" APIs, like OpenAI itself, Openrouter, Groq, Stability, Perplexity, Together.ai, Anyscale, Deepseek, Cerebras, xAI, Bedrock etc.

OpenAI does not publish a formal spec for its API, so every provider is free to interpret unspecified behavior however they'd like. These are the ones that need testing with this patch applied.

I'm going to be running this patch for a while and try some more models. For now I haven't run into any issues. It could at least be a config option if you want to be overly cautious,

Making this configurable is a worse option as I see it. I think it's gptel's job to sort details like this out so the user doesn't have to worry about it.

but I don't see much reason why a "more valid" object would cause failures than a "less valid" one.

True. Maybe we should just apply it and see if anyone using one of the other APIs above reports a bug.

By the way, thanks for gptel - it is by far the best interface to these things that exists so far. I mean in general, not just in Emacs.

Cheers!

@tazjin
Copy link
Author
tazjin commented Jun 16, 2025

True. Maybe we should just apply it and see if anyone using one of the other APIs above reports a bug.

I've tried it with our local DeepSeek installation, but it is experiencing general issues with tool calls atm so the results are inconclusive. It does seem to accept the tool list fine though. The other APIs in the list I personally don't use.

Some implementations of the OpenAI API (notably, when talking to
OpenAI's o3 and up) require tools that have no parameters to still
supply a valid object describing them instead of just `null`.

OpenAI's own older implementations (e.g. when talking to 4.1) handle
`null` fine, and so do basically all other OpenAI-like endpoints I've
tested. All implementations seem to work with the empty but valid
object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0