[CI][RFC] Replace black-jupyter with ruff-format (#37210)
Co-authored-by: Alison Shao <a.shao@wustl.edu>
This commit is contained in:
co-authored by
Alison Shao
parent
2641e427be
commit
28262c20df
@@ -373,7 +373,7 @@ class TestInklingDetector(unittest.TestCase):
|
||||
self.assertEqual(result.normal_text, "Here you go.")
|
||||
|
||||
def test_empty_name_is_allowed_on_the_canonical_path(self):
|
||||
source = "<|content_invoke_tool_json|>" '{"name":"","args":{}}<|end_message|>'
|
||||
source = '<|content_invoke_tool_json|>{"name":"","args":{}}<|end_message|>'
|
||||
result = InklingDetector().detect_and_parse(source, self.tools)
|
||||
self.assertEqual(len(result.calls), 1)
|
||||
self.assertEqual(result.calls[0].name, "")
|
||||
@@ -1305,7 +1305,6 @@ class TestLlama32Detector(unittest.TestCase):
|
||||
|
||||
|
||||
class TestKimiK2Detector(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
"""Set up test tools and detector."""
|
||||
self.tools = [
|
||||
@@ -1374,7 +1373,6 @@ class TestKimiK2Detector(unittest.TestCase):
|
||||
result = self.detector.parse_streaming_increment(chunk, self.tools)
|
||||
for tool_call_chunk in result.calls:
|
||||
if tool_call_chunk.tool_index is not None:
|
||||
|
||||
while len(tool_calls) <= tool_call_chunk.tool_index:
|
||||
tool_calls.append({"name": "", "parameters": ""})
|
||||
|
||||
@@ -1423,7 +1421,6 @@ class TestKimiK2Detector(unittest.TestCase):
|
||||
result = self.detector.parse_streaming_increment(chunk, self.tools)
|
||||
for tool_call_chunk in result.calls:
|
||||
if tool_call_chunk.tool_index is not None:
|
||||
|
||||
while len(tool_calls) <= tool_call_chunk.tool_index:
|
||||
tool_calls.append({"name": "", "parameters": ""})
|
||||
|
||||
@@ -1458,7 +1455,6 @@ class TestKimiK2Detector(unittest.TestCase):
|
||||
result = self.detector.parse_streaming_increment(chunk, self.tools)
|
||||
for tool_call_chunk in result.calls:
|
||||
if tool_call_chunk.tool_index is not None:
|
||||
|
||||
while len(tool_calls) <= tool_call_chunk.tool_index:
|
||||
tool_calls.append({"name": "", "parameters": ""})
|
||||
|
||||
@@ -1531,7 +1527,7 @@ class TestDeepSeekV3Detector(unittest.TestCase):
|
||||
"function<|tool▁sep|>",
|
||||
"get_tour",
|
||||
"ist_att",
|
||||
"ractions\n```" 'json\n{"',
|
||||
'ractions\n```json\n{"',
|
||||
'city": "',
|
||||
'Beijing"}\n',
|
||||
"```<|tool▁call▁end|>",
|
||||
@@ -1718,9 +1714,9 @@ class TestDeepSeekV32Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertGreater(num_tool_call_chunks, 8)
|
||||
|
||||
@@ -1773,9 +1769,9 @@ class TestDeepSeekV32Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertGreater(num_tool_call_chunks, 8)
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
@@ -1866,9 +1862,9 @@ class TestDeepSeekV32Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
# Verify that the no-parameter function was correctly parsed
|
||||
self.assertEqual(
|
||||
@@ -1926,9 +1922,9 @@ class TestDeepSeekV32Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
# Should still parse correctly even with whitespace-only content
|
||||
self.assertEqual(
|
||||
@@ -2128,9 +2124,9 @@ class TestDeepSeekV4Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertGreater(num_tool_call_chunks, 8)
|
||||
|
||||
@@ -4500,9 +4496,7 @@ class TestLfm2Detector(unittest.TestCase):
|
||||
def test_reserved_kwarg_with_nested_quote_recovered(self):
|
||||
"""A keyword-named parameter holding a nested-quote command needs
|
||||
the rename and requote rewrites to compose."""
|
||||
text = (
|
||||
"<|tool_call_start|>[search(from='sed -n '1,5p' f.py')]" "<|tool_call_end|>"
|
||||
)
|
||||
text = "<|tool_call_start|>[search(from='sed -n '1,5p' f.py')]<|tool_call_end|>"
|
||||
result = self.detector.detect_and_parse(text, self.tools)
|
||||
|
||||
self.assertEqual(len(result.calls), 1)
|
||||
@@ -4720,9 +4714,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
self.assertEqual(tool_calls_by_index[0]["name"], "manage_user_memory")
|
||||
@@ -4762,9 +4756,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(accumulated_text, "I'll help you.")
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
@@ -4802,9 +4796,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
self.assertEqual(tool_calls_by_index[0]["name"], "manage_user_memory")
|
||||
@@ -4841,9 +4835,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
self.assertEqual(tool_calls_by_index[0]["name"], "get_weather")
|
||||
@@ -4878,9 +4872,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
# Should have name but incomplete parameters
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
@@ -4916,9 +4910,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(accumulated_text, "I'll remember that.")
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
@@ -4961,9 +4955,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
self.assertEqual(tool_calls_by_index[0]["name"], "get_weather")
|
||||
@@ -5011,9 +5005,9 @@ function call<|role_sep|>
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(accumulated_text, "I'll help you.")
|
||||
self.assertEqual(len(tool_calls_by_index), 1)
|
||||
@@ -5265,9 +5259,9 @@ class TestQwen25Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
return tool_calls_by_index
|
||||
|
||||
def test_streaming_multiple_tool_calls(self):
|
||||
@@ -5515,9 +5509,9 @@ class TestGemma4Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
return normal_text, tool_calls_by_index
|
||||
|
||||
def test_streaming_multiple_tool_calls(self):
|
||||
@@ -5556,9 +5550,9 @@ class TestGemma4Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
|
||||
self.assertEqual(len(tool_calls_by_index), 2)
|
||||
self.assertEqual(tool_calls_by_index[0]["name"], "get_weather")
|
||||
@@ -5623,9 +5617,9 @@ class TestGemma4Detector(unittest.TestCase):
|
||||
if call.name:
|
||||
tool_calls_by_index[call.tool_index]["name"] = call.name
|
||||
if call.parameters:
|
||||
tool_calls_by_index[call.tool_index][
|
||||
"parameters"
|
||||
] += call.parameters
|
||||
tool_calls_by_index[call.tool_index]["parameters"] += (
|
||||
call.parameters
|
||||
)
|
||||
self.assertIn("Hello!", normal_text)
|
||||
self.assertIn("Let me also check", normal_text)
|
||||
self.assertEqual(len(tool_calls_by_index), 2)
|
||||
|
||||
@@ -351,9 +351,7 @@ class TestHunyuanDetectorStreaming(CustomTestCase):
|
||||
def test_complete_tool_call_single_chunk(self):
|
||||
detector = self._new_detector()
|
||||
text = (
|
||||
"<tool_calls>"
|
||||
"<tool_call>get_current_date<tool_sep></tool_call>"
|
||||
"</tool_calls>"
|
||||
"<tool_calls><tool_call>get_current_date<tool_sep></tool_call></tool_calls>"
|
||||
)
|
||||
result = detector.parse_streaming_increment(text, self.tools)
|
||||
collected = _collect_streamed_tool_calls(result.calls)
|
||||
|
||||
@@ -197,7 +197,7 @@ def test_strict_schema_rejects_invalid_parameters(arguments):
|
||||
|
||||
def test_required_allows_response_prefix_but_requires_tools():
|
||||
grammar = _grammar([_tool()], tool_choice="required")
|
||||
response = "<|open|>response<|sep|>Checking." "<|close|>response<|sep|>"
|
||||
response = "<|open|>response<|sep|>Checking.<|close|>response<|sep|>"
|
||||
|
||||
assert _accepts(grammar, response + _tools_section(_valid_weather_call()))
|
||||
assert not _accepts(grammar, response)
|
||||
|
||||
@@ -118,7 +118,7 @@ def test_detect_and_parse_cdata_multiline_v3():
|
||||
def test_unknown_tool_block_preserved_v3():
|
||||
detector = MiniCPM5Detector()
|
||||
tools = make_tools_weather()
|
||||
text = '<function name="unknown">' '<param name="x">1</param>' "</function>\n"
|
||||
text = '<function name="unknown"><param name="x">1</param></function>\n'
|
||||
res = detector.detect_and_parse(text, tools)
|
||||
assert len(res.calls) == 0
|
||||
assert "unknown" in res.normal_text
|
||||
@@ -168,7 +168,7 @@ def test_multiple_calls_interleaved_text_v3():
|
||||
def test_incomplete_missing_function_end_v3():
|
||||
detector = MiniCPM5Detector()
|
||||
tools = make_tools_weather()
|
||||
text = '<function name="get_weather">' '<param name="city">北京</param>'
|
||||
text = '<function name="get_weather"><param name="city">北京</param>'
|
||||
res = detector.detect_and_parse(text, tools)
|
||||
assert len(res.calls) == 0
|
||||
assert "get_weather" in res.normal_text
|
||||
@@ -204,11 +204,7 @@ def test_duplicate_param_names_invalid_v3():
|
||||
def test_case_sensitive_param_name_invalid_v3():
|
||||
detector = MiniCPM5Detector()
|
||||
tools = make_tools_weather()
|
||||
text = (
|
||||
'<function name="get_weather">'
|
||||
'<param name="City">北京</param>'
|
||||
"</function>\n"
|
||||
)
|
||||
text = '<function name="get_weather"><param name="City">北京</param></function>\n'
|
||||
res = detector.detect_and_parse(text, tools)
|
||||
assert len(res.calls) == 0
|
||||
|
||||
@@ -243,9 +239,7 @@ def test_streaming_increment_v3():
|
||||
def test_streaming_split_bot_token():
|
||||
detector = MiniCPM5Detector()
|
||||
tools = make_tools_weather()
|
||||
text = (
|
||||
'<function name="get_weather">' '<param name="city">北京</param>' "</function>"
|
||||
)
|
||||
text = '<function name="get_weather"><param name="city">北京</param></function>'
|
||||
|
||||
r1 = detector.parse_streaming_increment("<", tools)
|
||||
assert r1.normal_text == ""
|
||||
@@ -274,9 +268,7 @@ def test_streaming_multiple_complete_blocks_in_one_delta():
|
||||
def test_malformed_xml_with_unescaped_ampersand_falls_back_to_regex():
|
||||
detector = MiniCPM5Detector()
|
||||
tools = make_tools_weather()
|
||||
text = (
|
||||
'<function name="get_weather">' '<param name="city">A & B</param>' "</function>"
|
||||
)
|
||||
text = '<function name="get_weather"><param name="city">A & B</param></function>'
|
||||
|
||||
result = detector.detect_and_parse(text, tools)
|
||||
assert len(result.calls) == 1
|
||||
|
||||
@@ -400,8 +400,7 @@ class TestMuseGlimmerDetector(CustomTestCase):
|
||||
it never will. Goes red if the tool parser loses its stream-end flush
|
||||
(``parse_stream_end`` / detector ``finish``)."""
|
||||
raw = (
|
||||
" to=self<|message|>r<|eom|>"
|
||||
"<|start|>assistant to=user<|message|>answer<|st"
|
||||
" to=self<|message|>r<|eom|><|start|>assistant to=user<|message|>answer<|st"
|
||||
)
|
||||
for chunk_size in (1, 7, 100):
|
||||
_, content, calls = self.pipeline_stream(raw, chunk_size)
|
||||
|
||||
@@ -154,9 +154,7 @@ class TestPoolsideV1Detector(CustomTestCase):
|
||||
in-flight call, matching the old closing-tag-anchored regex behavior.
|
||||
Without the truncated-call filter in detect_and_parse, streaming-as-
|
||||
primitive surfaced a tool call with parameters="{}" on this input."""
|
||||
text = (
|
||||
"<tool_call>get_weather\n<arg_key>location</arg_key>\n" "<arg_value>San Fr"
|
||||
)
|
||||
text = "<tool_call>get_weather\n<arg_key>location</arg_key>\n<arg_value>San Fr"
|
||||
result = self.detector.detect_and_parse(text, self.tools)
|
||||
self.assertEqual(
|
||||
len(result.calls), 0, "truncated mid-arg_value must yield 0 calls"
|
||||
|
||||
Reference in New Issue
Block a user