From 6f2759cc87a5ab22d434d782e513863b76925748 Mon Sep 17 00:00:00 2001 From: Ge Gao <49388944+dorisjoy@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:00:04 +0800 Subject: [PATCH] Fix test_retrieve_tool_func_result_error failure in python version >= 3.11 (#3017) Currently this test will fail in python version >= 3.11, the reason is because: ![image](https://github.com/microsoft/promptflow/assets/49388944/35195bc0-1a46-4969-bb28-e1ee1e196829) So the error message in python version >= 3.11 will be: 'Unable to retrieve tool func result due to \'ToolFuncCallScenario **ToolFuncCallScenario.REVERSE_GENERATED_BY** response must be a dict. {"index_type": "Azure Cognitive Search", "index": "index_1"} is not a dict.\'. \nPlease contact the tool author/support team for troubleshooting assistance.' But in the python version < 3.11, the error message will be: 'Unable to retrieve tool func result due to \'ToolFuncCallScenario **reverse_generated_by** response must be a dict. {"index_type": "Azure Cognitive Search", "index": "index_1"} is not a dict.\'. \nPlease contact the tool author/support team for troubleshooting assistance.' In order to keep the test stable in different python environment, so change the error message from: f"ToolFuncCallScenario {func_call_scenario} response must be a dict. " f"{result} is not a dict." to f"ToolFuncCallScenario {func_call_scenario.**value**} response must be a dict. " f"{result} is not a dict." --------- Co-authored-by: Ge Gao --- src/promptflow-core/promptflow/_utils/tool_utils.py | 2 +- .../tests/executor/unittests/_core/test_tools_manager.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/promptflow-core/promptflow/_utils/tool_utils.py b/src/promptflow-core/promptflow/_utils/tool_utils.py index 003d227a67b..ab802ea36ab 100644 --- a/src/promptflow-core/promptflow/_utils/tool_utils.py +++ b/src/promptflow-core/promptflow/_utils/tool_utils.py @@ -301,7 +301,7 @@ def validate_tool_func_result(func_call_scenario: str, result): if func_call_scenario == ToolFuncCallScenario.REVERSE_GENERATED_BY: if not isinstance(result, Dict): raise RetrieveToolFuncResultValidationError( - f"ToolFuncCallScenario {func_call_scenario} response must be a dict. " f"{result} is not a dict." + f"ToolFuncCallScenario {func_call_scenario.value} response must be a dict. " f"{result} is not a dict." ) elif func_call_scenario == ToolFuncCallScenario.DYNAMIC_LIST: validate_dynamic_list_func_response_type(result, f"ToolFuncCallScenario {func_call_scenario}") diff --git a/src/promptflow/tests/executor/unittests/_core/test_tools_manager.py b/src/promptflow/tests/executor/unittests/_core/test_tools_manager.py index f8e46f74238..d2bedd721c1 100644 --- a/src/promptflow/tests/executor/unittests/_core/test_tools_manager.py +++ b/src/promptflow/tests/executor/unittests/_core/test_tools_manager.py @@ -366,8 +366,9 @@ def test_retrieve_tool_func_result_error( def test_register_apis(self): from typing import Union - from promptflow._core.tools_manager import register_apis, connection_type_to_api_mapping + from promptflow._core.tool import ToolProvider + from promptflow._core.tools_manager import connection_type_to_api_mapping, register_apis from promptflow.connections import AzureOpenAIConnection, OpenAIConnection, ServerlessConnection class MockAI1(ToolProvider):