[Frontend] Fix the parsing of missing string= in DeepSeek V4 (#56271)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Bugen Zhao <i@bugenzhao.com> Signed-off-by: lazymio <mio@lazym.io>
This commit is contained in:
co-authored by
Claude Opus 5
Bugen Zhao
parent
dee37d8911
commit
39e33db7f3
@@ -119,6 +119,35 @@ class TestArgConverter:
|
||||
result = json.loads(_dsml_arg_converter("", partial=False))
|
||||
assert result == {}
|
||||
|
||||
def _bare(self, name: str, value: str) -> str:
|
||||
return f'<|DSML|parameter name="{name}">{value}{_PARAM_CLOSE}'
|
||||
|
||||
def test_missing_string_attribute_keeps_literal(self):
|
||||
"""The model sometimes omits ``string``; the parameter must survive."""
|
||||
raw = self._bare("name", "alpha")
|
||||
assert json.loads(_dsml_arg_converter(raw, partial=False)) == {"name": "alpha"}
|
||||
|
||||
def test_missing_string_attribute_parses_json(self):
|
||||
raw = self._bare("count", "7") + self._bare("opts", '{"k": [1]}')
|
||||
assert json.loads(_dsml_arg_converter(raw, partial=False)) == {
|
||||
"count": 7,
|
||||
"opts": {"k": [1]},
|
||||
}
|
||||
|
||||
def test_missing_string_attribute_alongside_annotated(self):
|
||||
raw = self._bare("a", "x") + _param("b", "true", "42")
|
||||
assert json.loads(_dsml_arg_converter(raw, partial=False)) == {
|
||||
"a": "x",
|
||||
"b": "42",
|
||||
}
|
||||
|
||||
def test_missing_string_attribute_partial_value(self):
|
||||
raw = _param("a", "true", "x") + '<|DSML|parameter name="n">12'
|
||||
assert json.loads(_dsml_arg_converter(raw, partial=True)) == {
|
||||
"a": "x",
|
||||
"n": 12,
|
||||
}
|
||||
|
||||
def test_invalid_json_fallback(self):
|
||||
raw = self._raw(("data", "false", "[broken"))
|
||||
result = json.loads(_dsml_arg_converter(raw, partial=False))
|
||||
@@ -232,6 +261,47 @@ class TestImplicitParameterClose:
|
||||
}
|
||||
|
||||
|
||||
class TestMissingStringAttribute:
|
||||
def test_non_streaming_keeps_parameter(self, mock_tokenizer, mock_request):
|
||||
text = (
|
||||
f"{DSML_TOOL_START}"
|
||||
f"{DSML_INVOKE_PREFIX}get_weather{DSML_INVOKE_NAME_END}\n"
|
||||
f'<|DSML|parameter name="location">Paris{_PARAM_CLOSE}\n'
|
||||
f"{_param('date', 'true', 'tomorrow')}\n"
|
||||
f"{DSML_INVOKE_END}{DSML_TOOL_END}"
|
||||
)
|
||||
|
||||
result = DeepSeekV4Parser(mock_tokenizer).extract_tool_calls(text, mock_request)
|
||||
|
||||
assert result.tools_called is True
|
||||
assert json.loads(result.tool_calls[0].function.arguments) == {
|
||||
"location": "Paris",
|
||||
"date": "tomorrow",
|
||||
}
|
||||
|
||||
def test_streaming_keeps_parameter(self, mock_tokenizer, mock_request):
|
||||
chunks = [
|
||||
DSML_TOOL_START,
|
||||
f"{DSML_INVOKE_PREFIX}get_weather{DSML_INVOKE_NAME_END}\n",
|
||||
'<|DSML|parameter name="loc',
|
||||
'ation">Par',
|
||||
"is",
|
||||
_PARAM_CLOSE,
|
||||
f"\n{_param('date', 'true', 'tomorrow')}\n",
|
||||
DSML_INVOKE_END,
|
||||
DSML_TOOL_END,
|
||||
]
|
||||
|
||||
results = simulate_tool_streaming(
|
||||
DeepSeekV4Parser(mock_tokenizer), mock_request, chunks
|
||||
)
|
||||
|
||||
assert json.loads(collect_tool_arguments(results)) == {
|
||||
"location": "Paris",
|
||||
"date": "tomorrow",
|
||||
}
|
||||
|
||||
|
||||
# ── Bare </think> absorption and duplicate <think> absorption ─────────
|
||||
|
||||
|
||||
|
||||
@@ -137,10 +137,12 @@ def test_python_argument_conversion_and_partial_values():
|
||||
'<|DSML| parameter name="object" string="false">'
|
||||
'{"a": [true, null]}</|DSML| parameter>'
|
||||
'<|DSML| parameter name="bad" string="false">[broken</|DSML| parameter>'
|
||||
'<|DSML| parameter name="bare">7</|DSML| parameter>'
|
||||
'<|DSML| parameter name="text" string="true"> a<b'
|
||||
)
|
||||
assert json.loads(converter(raw, True)) == {
|
||||
"object": {"a": [True, None]},
|
||||
"bad": "[broken",
|
||||
"bare": 7,
|
||||
"text": " a<b",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user