Repository navigation
fix: honour tool_choice on /v1/chat/completions - #270
Merged
Merged
Conversation
tool_choice was never decoded, so every value behaved like auto. "none" now keeps the tools out of the prompt and a tool call out of the reply, a named function offers only that tool, and a value the API does not have or a function that is not in tools is a 400 that names tool_choice. "required" is still handled like auto, with a line in the server log. Closes SharpAI#269.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #269.
tool_choicewas never decoded, so every value behaved likeauto: with"none"the model still got all the tools and could answer with a tool call, a named function didn't narrow anything, and a typo was a normal 200.What it does now:
none– no tools go to the template. If the model emits a tool call anyway, it's dropped and logged instead of sent back.tools– 400invalid_request_errorthat namestool_choice.auto, or notool_choice– same as before.required– still behaves likeauto, now with a line in the server log. Really forcing a call needs constrained decoding, so I left that out to keep this one small.Same requests on main and on this branch (two tools in the request,
mlx-community/Qwen2.5-0.5B-Instruct-4bit, M1 Max):tool_choiceautoorrequirednoneget_time"sometimes"get_stock, which isn't intoolsTests:
ToolChoiceTests, 15 new: decoding, which tools reach the prompt, the 400s, and both chat handlers dropping a call that the choice ruled out.tests/test-contract.shblock 18:noneand a named function show up inprompt_tokens, and the two bad values are a 400. All 4 checks fail on main.swift test --filter SwiftLMTests: 365 tests, 0 failures. Contract suite against the CI model: 32 passed, 0 failed, 2 skipped (the two usual skips for the tiny model).I also added the
tool_choicerow todocs/api-response-formats.md.