[Bugfix] Return HTTP 400 instead of 501 for unknown chat roles in DeepSeek encoders (#53071)

Signed-off-by: JC-ut0 <809602657@qq.com>
This commit is contained in:
JC-ut0
2026-08-20 09:23:41 +00:00
committed by GitHub
parent c8de519917
commit 38e9cefdef
4 changed files with 29 additions and 2 deletions
+16
View File
@@ -271,3 +271,19 @@ def test_encode_messages_preserves_small_chat_prompt(encoding_module):
"<|begin▁of▁sentence|><|User|>Hello<|Assistant|></think>"
"Hi<|end▁of▁sentence|>Again<|end▁of▁sentence|>"
)
@pytest.mark.parametrize(
"encoding_module",
ENCODING_MODULES,
ids=["deepseek_v32", "deepseek_v4"],
)
def test_encode_messages_unknown_role_raises_value_error(encoding_module):
# An invalid role (e.g. uppercase "SYSTEM") is a client error and must be
# raised as ValueError so the OpenAI serving layer maps it to HTTP 400
# instead of NotImplementedError, which would map to HTTP 501.
with pytest.raises(ValueError, match="Invalid role: SYSTEM"):
encoding_module.encode_messages(
[{"role": "SYSTEM", "content": "Hello"}],
thinking_mode="chat",
)