From ebfcbaa459384a085e6cc03a64a22a1fee5e95bb Mon Sep 17 00:00:00 2001 From: peiwenYe <963623403@qq.com> Date: Wed, 22 Jan 2025 21:30:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=BE=93=E5=85=A5dict?= =?UTF-8?q?=E5=88=9B=E5=BB=BAjson=E8=BE=93=E5=87=BA=20(#725)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 将get_filename_from_url实现迁移至utils * 回滚版本号 * 支持输入dict创建json输出 * 支持输入dict创建json输出 * 跳过vdb单测 --------- Co-authored-by: yepeiwen01 --- python/core/component.py | 2 ++ python/tests/test_base_component.py | 2 ++ python/tests/test_core_components_baidu_vdb_retriever.py | 2 +- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/python/core/component.py b/python/core/component.py index 7e2e77098..e5c0c8870 100644 --- a/python/core/component.py +++ b/python/core/component.py @@ -560,6 +560,8 @@ def create_output(cls, type, text, role="tool", name="", visible_scope="all", ra key_list = ["detail", "steps"] elif type == "function_call": key_list = ["thought", "name", "arguments"] + elif type == "json": + key_list = ["data"] else: raise ValueError("Unknown type: {}".format(type)) assert all(key in text for key in key_list), "all keys:{} must be included in the text field".format(key_list) diff --git a/python/tests/test_base_component.py b/python/tests/test_base_component.py index a560cf78e..bf40e0720 100644 --- a/python/tests/test_base_component.py +++ b/python/tests/test_base_component.py @@ -33,6 +33,7 @@ def test_valid_output_with_dict(self): output9 = self.component.create_output(type="plan", text={"detail": "hello", "steps":[{"name": "1", "arguments": {"query": "a", "chat_history": "world"}}]}) output10 = self.component.create_output(type="function_call", text={"thought": "hello", "name": "AppBuilder", "arguments": {"query": "a", "chat_history": "world"}}) output11 = self.component.create_output(type="references", text={"type": "engine", "doc_id": "1", "content": "hello, world", "title": "Have a nice day", "source": "bing", "extra": {"key": "value"}}) + output12 = self.component.create_output(type="json", text={"data": "value"}) self.assertIsInstance(output1, ComponentOutput) self.assertIsInstance(output2, ComponentOutput) self.assertIsInstance(output3, ComponentOutput) @@ -44,6 +45,7 @@ def test_valid_output_with_dict(self): self.assertIsInstance(output9, ComponentOutput) self.assertIsInstance(output10, ComponentOutput) self.assertIsInstance(output11, ComponentOutput) + self.assertIsInstance(output12, ComponentOutput) self.assertEqual(output11.content[0].text.extra["key"], "value") def test_valid_output_type_with_same_key(self): diff --git a/python/tests/test_core_components_baidu_vdb_retriever.py b/python/tests/test_core_components_baidu_vdb_retriever.py index 530adc6e7..d0b598671 100644 --- a/python/tests/test_core_components_baidu_vdb_retriever.py +++ b/python/tests/test_core_components_baidu_vdb_retriever.py @@ -21,7 +21,7 @@ from appbuilder import BaiduVDBVectorStoreIndex,TableParams from appbuilder.core.component import Message -@unittest.skipUnless(os.getenv("TEST_CASE", "UNKNOWN") == "CPU_PARALLEL", "") +@unittest.skip(reason="vdb欠费了,跳过") class TestBaiduVbdRetriever(unittest.TestCase): def setUp(self): self.instance_id=os.getenv("INSTANCE_ID", "UNKNOWN")