Draft
Conversation
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.
Summary
Addresses #1045 by adding explicit OpenAI-compatible
tool_choicehandling to the/chat/completionsand/responsesendpoints.This follows the approach discussed in the issue thread:
tool_choiceomitted: preserve existing behavior and pass tools through when provided.tool_choice: "none": omit tools from chat-template rendering and suppress tool-call parsing.tool_choice: "auto": render tools normally and parse model-emitted tool calls.tool_choice: "required"and named function choices: return a clear 400 because current VLM chat templates do not provide a reliable way to force required or pinned tool use.Why
The larger tool-capable VLMs we checked, including Qwen3.5/Qwen3.6 and Gemma-4/Hermes-Gemma-4 variants, support tool schemas in their chat templates, but the templates do not consume
tool_choiceto change prompt rendering. Acceptingnoneandautoimproves compatibility with OpenAI-style clients while avoiding a false guarantee for unsupported enforcement modes.The Responses API path also now emits parsed function-call output items when the loaded template has a supported parser, and streaming
response.completedevents preserve the finaloutput_textaggregate.Validation
uv run --with pytest python -m pytest mlx_vlm/tests/test_server.py51 passed, 3 warningsuv run --with pytest python -m pytest mlx_vlm/tests/test_server.py mlx_vlm/tests/test_gemma4_tool_parser.py58 passed, 3 warningspython3 -m compileall -q mlx_vlm/server.py mlx_vlm/tests/test_server.pygit diff --checkWarnings were the existing MLX/Pydantic serializer warnings observed in the local test environment.