From f78b42734ef98a856cbbdd8dc6c47ad9293f7e15 Mon Sep 17 00:00:00 2001 From: femto Date: Sat, 9 Nov 2024 13:42:27 +0800 Subject: [PATCH] 1 --- tests/actions/test_action_node.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/actions/test_action_node.py b/tests/actions/test_action_node.py index 673f8190..10d39815 100644 --- a/tests/actions/test_action_node.py +++ b/tests/actions/test_action_node.py @@ -101,6 +101,30 @@ def test_normalize_response_json_string3(llm_action_node): assert parsed_result["correct"] is True assert parsed_result["score"] == 0.9 +def test_normalize_response_json_string4(llm_action_node): + # 测试JSON字符串输入 + json_input = r''' + ```json +{ + "feedback": "abc"xx"def", + "correct": true, + "score": 0.9 +} +``` + ''' + + result = llm_action_node.normalize_response(json_input) + # 验证返回的是提取并格式化后的JSON字符串 + assert isinstance(result, str) + # 确保可以被解析回JSON对象 + print(result) + parsed_result = json.loads(result) + assert "feedback" in parsed_result + assert "correct" in parsed_result + assert "score" in parsed_result + assert parsed_result["correct"] is True + assert parsed_result["score"] == 0.9 + def test_normalize_response_dict_with_answer(llm_action_node): # 测试包含answer字段的字典 input_dict = {"answer": "test answer"}