Skip to content

Commit

Permalink
将get_filename_from_url实现迁移至utils
Browse files Browse the repository at this point in the history
  • Loading branch information
yepeiwen01 committed Jan 17, 2025
1 parent 3fd3095 commit 1cef2cb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 28 deletions.
14 changes: 1 addition & 13 deletions python/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
3 changes: 2 additions & 1 deletion python/core/components/v2/text_to_image/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 2 additions & 12 deletions python/core/components/v2/tree_mind/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
11 changes: 10 additions & 1 deletion python/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
packages=packages,
Expand Down

0 comments on commit 1cef2cb

Please sign in to comment.