Skip to content

fix: remove last message role restriction in chat completion endpoint#2

Open
amumu96 wants to merge 4 commits into
mainfrom
fix/remove-chat-completion-role-restriction
Open

fix: remove last message role restriction in chat completion endpoint#2
amumu96 wants to merge 4 commits into
mainfrom
fix/remove-chat-completion-role-restriction

Conversation

@amumu96
Copy link
Copy Markdown
Owner

@amumu96 amumu96 commented Apr 22, 2026

Summary

  • Remove the validation that required the last message role to be "user", "system", or "tool" in the create_chat_completion endpoint
  • Only keep the messages empty check, aligning with OpenAI API behavior
  • Fixes 400 errors from frameworks like LangGraph that pass conversation history including assistant messages

Synced from enterprise MR: orbitai/xinference-enterprise/xinference-backend!428

Test plan

  • Verify chat completion works with assistant message as the last message
  • Verify empty messages still returns 400
  • Verify normal user/system/tool messages still work as before

🤖 Generated with Claude Code

arthur and others added 4 commits April 22, 2026 08:54
Remove the validation that required the last message role to be
"user", "system", or "tool" in the create_chat_completion endpoint.
This aligns with OpenAI API behavior and fixes 400 errors from
frameworks like LangGraph that pass conversation history including
assistant messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The test expected a 400 when the last message role was "assistant",
but the previous commit intentionally removed that restriction. Update
the test to expect a successful completion response instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The underlying model may not return a standard completion response
for assistant-terminated conversations, so just assert the API no
longer rejects the request with a 400.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The llama.cpp backend rejects assistant response prefill with
enable_thinking, causing a 500. The API validation change is already
covered by the existing test that sends only system messages (which
passes since it doesn't require assistant as last role).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

1 participant