From 1cef2cbfb0947df8fabc9cf6254f39ae9fc3f7b8 Mon Sep 17 00:00:00 2001 From: yepeiwen01 Date: Fri, 17 Jan 2025 16:02:27 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=B0=86get=5Ffilename=5Ffrom=5Furl?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=BF=81=E7=A7=BB=E8=87=B3utils?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/core/component.py | 14 +------------- .../core/components/v2/text_to_image/component.py | 3 ++- python/core/components/v2/tree_mind/component.py | 14 ++------------ python/core/utils.py | 11 ++++++++++- setup.py | 2 +- 5 files changed, 16 insertions(+), 28 deletions(-) diff --git a/python/core/component.py b/python/core/component.py index da864415b..6ebedc73b 100644 --- a/python/core/component.py +++ b/python/core/component.py @@ -24,7 +24,6 @@ from appbuilder.core.utils import ttl_lru_cache from appbuilder.core._client import HTTPClient, AsyncHTTPClient from appbuilder.core.message import Message -from urllib.parse import urlparse, unquote class ComponentArguments(BaseModel): """ @@ -580,15 +579,4 @@ def create_output(cls, type, text, role="tool", name="", visible_scope="all", ra "metrics": metrics }] } - return ComponentOutput(**result) - - @staticmethod - def get_filename_from_url(url): - """从给定URL中提取文件名""" - parsed_url = urlparse(url) - # 提取路径部分 - path = parsed_url.path - # 从路径中获取文件名 - filename = path.split('/')[-1] - # 解码URL编码的文件名 - return unquote(filename) + return ComponentOutput(**result) \ No newline at end of file diff --git a/python/core/components/v2/text_to_image/component.py b/python/core/components/v2/text_to_image/component.py index 07972597b..f05cbb18a 100644 --- a/python/core/components/v2/text_to_image/component.py +++ b/python/core/components/v2/text_to_image/component.py @@ -21,6 +21,7 @@ from appbuilder.core.component import Component from appbuilder.core.message import Message from appbuilder.core._client import HTTPClient +from appbuilder.core.utils import get_filename_from_url from appbuilder.core._exception import AppBuilderServerException, RiskInputException from appbuilder.core.components.text_to_image.model import Text2ImageSubmitRequest, Text2ImageQueryRequest, \ Text2ImageQueryResponse, Text2ImageSubmitResponse, Text2ImageOutMessage @@ -197,7 +198,7 @@ def tool_eval( yield self.create_output( type='image', text={ - 'filename': self.get_filename_from_url(img_urls[url_number]), + 'filename': get_filename_from_url(img_urls[url_number]), 'url': img_urls[url_number], }, raw_data=raw_data, diff --git a/python/core/components/v2/tree_mind/component.py b/python/core/components/v2/tree_mind/component.py index d3f56e4c1..5bf8e674a 100644 --- a/python/core/components/v2/tree_mind/component.py +++ b/python/core/components/v2/tree_mind/component.py @@ -20,6 +20,7 @@ from appbuilder.core.message import Message from appbuilder.core._client import HTTPClient from appbuilder.core._exception import * +from appbuilder.core.utils import get_filename_from_url from appbuilder.utils.trace.tracer_wrapper import components_run_trace, components_run_stream_trace from appbuilder.core.components.v2.tree_mind.model import TreeMindRequest, TreeMindResponse @@ -84,17 +85,6 @@ def _post(self, query, **kwargs): img_link = treemind_response.info.downloadInfo.fileInfo.pic return img_link, jump_link - @staticmethod - def get_filename_from_url(url): - """从给定URL中提取文件名""" - parsed_url = urlparse(url) - # 提取路径部分 - path = parsed_url.path - # 从路径中获取文件名 - filename = path.split('/')[-1] - # 解码URL编码的文件名 - return unquote(filename) - @components_run_stream_trace def tool_eval( self, @@ -127,7 +117,7 @@ def tool_eval( img_link_result = self.create_output( type="image", text={ - "filename": self.get_filename_from_url(img_link), + "filename": get_filename_from_url(img_link), "url": img_link }, visible_scope='all', diff --git a/python/core/utils.py b/python/core/utils.py index 1b25c7f10..1c2896b55 100644 --- a/python/core/utils.py +++ b/python/core/utils.py @@ -14,7 +14,7 @@ import time import itertools from typing import List -from urllib.parse import urlparse +from urllib.parse import urlparse, unquote from appbuilder.core._client import HTTPClient from appbuilder.core._exception import TypeNotSupportedException, ModelNotSupportedException from appbuilder.utils.model_util import GetModelListRequest, Models, RemoteModelCollector @@ -57,6 +57,15 @@ def get_model_list(secret_key: str = "", api_type_filter: List[str] = [], is_ava models.append(model.name) return models +def get_filename_from_url(url): + """从给定URL中提取文件名""" + parsed_url = urlparse(url) + # 提取路径部分 + path = parsed_url.path + # 从路径中获取文件名 + filename = path.split('/')[-1] + # 解码URL编码的文件名 + return unquote(filename) def convert_cloudhub_url(client: HTTPClient, qianfan_url: str) -> str: """将千帆url转换为AppBuilder url""" diff --git a/setup.py b/setup.py index 742ad1922..cb263a935 100755 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ setup( name="appbuilder-sdk", # NOTE(chengmo): 修改此版本号时,请注意同时修改 __init__.py 中的 __version__ - version="1.0.1", + version="1.0.1.1", author="dongdaxiang", author_email="dongdaxiang@baidu.com", packages=packages, From 4289098de7e4be0937b16b84d7d01346177c30c7 Mon Sep 17 00:00:00 2001 From: yepeiwen01 Date: Fri, 17 Jan 2025 16:51:12 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=9B=9E=E6=BB=9A=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cb263a935..742ad1922 100755 --- a/setup.py +++ b/setup.py @@ -54,7 +54,7 @@ setup( name="appbuilder-sdk", # NOTE(chengmo): 修改此版本号时,请注意同时修改 __init__.py 中的 __version__ - version="1.0.1.1", + version="1.0.1", author="dongdaxiang", author_email="dongdaxiang@baidu.com", packages=packages, From d4355123b4615c6f4720ee6bdacbba4052994df6 Mon Sep 17 00:00:00 2001 From: yepeiwen01 Date: Wed, 22 Jan 2025 16:29:13 +0800 Subject: [PATCH 3/5] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/core/component.py | 2 ++ python/tests/test_base_component.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/python/core/component.py b/python/core/component.py index 6ebedc73b..0dd75f6db 100644 --- a/python/core/component.py +++ b/python/core/component.py @@ -559,6 +559,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..26d9b407d 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={"key": "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): From 9ef46461eaebead171d633211626496ade8cba58 Mon Sep 17 00:00:00 2001 From: yepeiwen01 Date: Wed, 22 Jan 2025 16:34:03 +0800 Subject: [PATCH 4/5] =?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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/tests/test_base_component.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tests/test_base_component.py b/python/tests/test_base_component.py index 26d9b407d..bf40e0720 100644 --- a/python/tests/test_base_component.py +++ b/python/tests/test_base_component.py @@ -33,7 +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={"key": "value"}) + output12 = self.component.create_output(type="json", text={"data": "value"}) self.assertIsInstance(output1, ComponentOutput) self.assertIsInstance(output2, ComponentOutput) self.assertIsInstance(output3, ComponentOutput) From 872df9242bb6ffdaf34ef73c33e95d811cc09397 Mon Sep 17 00:00:00 2001 From: yepeiwen01 Date: Wed, 22 Jan 2025 20:25:11 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=B7=B3=E8=BF=87vdb=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/tests/test_core_components_baidu_vdb_retriever.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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")