@@ -32,21 +35,6 @@ class MistralDetector(BaseFormatDetector):
...
@@ -32,21 +35,6 @@ class MistralDetector(BaseFormatDetector):
"""Check if the text contains a Mistral format tool call."""
"""Check if the text contains a Mistral format tool call."""
returnself.bot_tokenintext
returnself.bot_tokenintext
def_clean_text(self,text:str)->str:
"""
clean text to only leave ''[TOOL_CALLS] [{"name": xxx, "arguments": {xxx}}]'
for example,
text = '[TOOL_CALLS] [{"name": "get_current_weather", "arguments": {"location": "Boston, MA", "unit": "fahrenheit"}}]\n\nToday\'s weather in Boston is :{function call result} (in Fahrenheit)\n\nIf you prefer Celsius, please let me know.'
"""Test parsing Mistral format with nested brackets in JSON content.
This test case specifically addresses the issue where the regex pattern
was incorrectly truncating JSON when it contained nested brackets like [City Name].
"""
# This is the exact problematic text from the original test failure
test_text='[TOOL_CALLS] [{"name":"make_next_step_decision", "arguments":{"decision":"","content":"```\\nTOOL: Access a weather API or service\\nOBSERVATION: Retrieve the current weather data for the top 5 populated cities in the US\\nANSWER: The weather in the top 5 populated cities in the US is as follows: [City Name] - [Weather Conditions] - [Temperature]\\n```"}}]'
self.assertEqual(len(result.calls),1,"Should detect exactly one tool call")
call=result.calls[0]
self.assertEqual(
call.name,
"make_next_step_decision",
"Should detect the correct function name",
)
# Verify that the parameters are valid JSON and contain the expected content
params=json.loads(call.parameters)
self.assertEqual(
params["decision"],"","Decision parameter should be empty string"
)
# The content should contain the full text including the nested brackets [City Name]
expected_content="```\nTOOL: Access a weather API or service\nOBSERVATION: Retrieve the current weather data for the top 5 populated cities in the US\nANSWER: The weather in the top 5 populated cities in the US is as follows: [City Name] - [Weather Conditions] - [Temperature]\n```"
self.assertEqual(
params["content"],
expected_content,
"Content should include nested brackets without truncation",
)
# Verify that normal text is empty (since the entire input is a tool call)
self.assertEqual(
result.normal_text,"","Normal text should be empty for pure tool call"
)
deftest_detect_and_parse_simple_case(self):
"""Test parsing a simple Mistral format tool call without nested brackets."""
"""Test parsing text that has content before the tool call."""
test_text='Here is some text before the tool call: [TOOL_CALLS] [{"name":"make_next_step_decision", "arguments":{"decision":"ANSWER", "content":"The answer is 42"}}]'