From 5668d9cb3e2126687fc5ad685d873adaff1f9e8d Mon Sep 17 00:00:00 2001 From: Umer Mansoor Date: Sun, 28 Jul 2024 06:40:07 -0700 Subject: [PATCH 1/2] Update error language and corresponding tests --- autogen/agentchat/conversable_agent.py | 4 ++-- test/agentchat/test_function_call.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/autogen/agentchat/conversable_agent.py b/autogen/agentchat/conversable_agent.py index 674c8b9248d7..2d8958f3282d 100644 --- a/autogen/agentchat/conversable_agent.py +++ b/autogen/agentchat/conversable_agent.py @@ -2234,7 +2234,7 @@ def execute_function(self, func_call, verbose: bool = False) -> Tuple[bool, Dict arguments = json.loads(input_string) except json.JSONDecodeError as e: arguments = None - content = f"Error: {e}\n You argument should follow json format." + content = f"Error: {e}\n The argument must be in JSON format." # Try to execute the function if arguments is not None: @@ -2291,7 +2291,7 @@ async def a_execute_function(self, func_call): arguments = json.loads(input_string) except json.JSONDecodeError as e: arguments = None - content = f"Error: {e}\n You argument should follow json format." + content = f"Error: {e}\n The argument must be in JSON format." # Try to execute the function if arguments is not None: diff --git a/test/agentchat/test_function_call.py b/test/agentchat/test_function_call.py index 0f1d4f909426..7023a709d3c1 100755 --- a/test/agentchat/test_function_call.py +++ b/test/agentchat/test_function_call.py @@ -115,7 +115,7 @@ def add_num(num_to_be_added): "name": "add_num", "arguments": '{ "num_to_be_added": 5, given_num: 10 }', } # should be "given_num" with quotes - assert "You argument should follow json format." in user.execute_function(func_call=wrong_json_format)[1]["content"] + assert "The argument must be in JSON format." in user.execute_function(func_call=wrong_json_format)[1]["content"] # function execution error with wrong arguments passed wrong_args = {"name": "add_num", "arguments": '{ "num_to_be_added": 5, "given_num": 10 }'} @@ -174,7 +174,7 @@ async def add_num(num_to_be_added): "arguments": '{ "num_to_be_added": 5, given_num: 10 }', } # should be "given_num" with quotes assert ( - "You argument should follow json format." + "The argument must be in JSON format." in (await user.a_execute_function(func_call=wrong_json_format))[1]["content"] ) From 5556ab00124c30f366543eda0381dffe60251a3a Mon Sep 17 00:00:00 2001 From: Umer Mansoor Date: Sun, 28 Jul 2024 06:41:13 -0700 Subject: [PATCH 2/2] Updated another test to use the new error message --- test/agentchat/test_function_and_tool_calling.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/agentchat/test_function_and_tool_calling.py b/test/agentchat/test_function_and_tool_calling.py index 893fbe351203..4e0775d014c0 100644 --- a/test/agentchat/test_function_and_tool_calling.py +++ b/test/agentchat/test_function_and_tool_calling.py @@ -94,11 +94,11 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str: { "tool_call_id": "1", "role": "tool", - "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.", + "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.", }, {"tool_call_id": "2", "role": "tool", "content": "_tool_func_2: value3 value4"}, ], - "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.\n\n_tool_func_2: value3 value4", + "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.\n\n_tool_func_2: value3 value4", } _tool_use_message_1_error_expected_reply = { @@ -154,7 +154,7 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str: _function_use_message_1_bad_json_expected_reply = { "name": "_tool_func_1", "role": "function", - "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n You argument should follow json format.", + "content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.", } _function_use_message_1_error_expected_reply = {