From ca549703943f16359d6832781d793dd1abbe72bc Mon Sep 17 00:00:00 2001 From: peiwenYe <963623403@qq.com> Date: Fri, 17 Jan 2025 17:24:11 +0800 Subject: [PATCH 1/2] =?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=20(#718)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 将get_filename_from_url实现迁移至utils * 回滚版本号 --------- Co-authored-by: yepeiwen01 --- 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 ++++++++++- 4 files changed, 15 insertions(+), 27 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""" From b38dd1856e939d1fac653fe4bc063343211e626b Mon Sep 17 00:00:00 2001 From: Chengmo Date: Mon, 20 Jan 2025 18:16:35 +0800 Subject: [PATCH 2/2] update Functioncall (#721) Co-authored-by: chengmo --- python/core/component.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python/core/component.py b/python/core/component.py index 6ebedc73b..7e2e77098 100644 --- a/python/core/component.py +++ b/python/core/component.py @@ -121,6 +121,7 @@ class FunctionCall(BaseModel, extra='allow'): thought: str = Field(default="", description="思考结果") name: str = Field(default="", description="工具名") arguments: dict = Field(default={}, description="参数列表") + component: Optional[str] = Field(default="", description="组件名class name") class Json(BaseModel, extra='allow'): @@ -128,7 +129,7 @@ class Json(BaseModel, extra='allow'): class Content(BaseModel): - name: str = Field(default="", + name: Optional[str] = Field(default="", description="介绍当前yield内容的阶段名, 使用name的必要条件,是同一组件会输出不同type的content,并且需要加以区分,方便前端渲染与用户展示") visible_scope: str = Field(default="all", description="为了界面展示明确的说明字段,三种取值:llm、user、all。llm为思考模型可见,类似function calling结果中submit的执行结果,user为终端用户可见,all包含上述两者")