Repository navigation
Conversation
Signed-off-by: kevin9327 <5299031+kevin9327@users.noreply.github.com>
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.
What & why
A request body that is not valid JSON, or is valid JSON but not a chat request, gets no usable answer:
do_POSTrunsjson.loadsoutside anytry, so a malformed body ({not json, or bytes that are not UTF-8) raises inside the handler. The client sees the connection closed with no HTTP response, while the Flask transport and the other validation errors answer 400invalid_request.parse_chat_requestassumes the shape.[1, 2],"hello",{"messages": "hi"},{"messages": ["hi"]}and{"messages": [null]}raiseAttributeErrorfrom.get, which is a 500 on Flask and a dropped connection on stdlib.This PR makes the stdlib handler answer a malformed body with 400 (
request body is not valid JSON: ...), and makesparse_chat_requestraise the sameValueErrorthe other bad inputs raise (request body must be a JSON object,messages must be a list of message objects), so both transports answer 400 before any generation or SSE headers.No issue filed; I found this while reading
server/app.py.Area
python/)macos/)ios/)android/)windows/)How was it tested?
python/tests/test_server.pygets two parametrized tests: malformed bodies on/v1/chat/completionsand/v1/completionsover the stdlib transport, and five non-chat-request bodies over both transports. All 14 new cases fail onmain(connection dropped orAttributeError) and pass with the change. Each also asserts the fake engine generated nothing.Ran on Linux with
mlx[cpu]==0.30.6andmlx-lm==0.31.0:pytest -m 'not slow' testsgives 181 passed, 16 failed. The 16 failures are all intests/test_streaming_math.pyand fail identically onmain(167 passed, same 16 failed) on this CPU build; I have no Apple silicon to run them on.Checklist
pytest -m 'not slow'passes locally for the server tests (see above for the unrelatedtest_streaming_mathfailures on a CPU-only MLX)mlxpast the pinned0.30.6AI-assisted: I used an AI coding assistant for this change. I reviewed the code and ran the tests above.