Skip to content

Commit

Permalink
Components新增文件名称处,同时更新V2文生图参数 (#711)
Browse files Browse the repository at this point in the history
Co-authored-by: yinjiaqi <[email protected]>
  • Loading branch information
C9luster and yinjiaqi authored Jan 8, 2025
1 parent fd9fa0b commit 102957f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion python/core/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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 @@ -581,3 +581,14 @@ def create_output(cls, type, text, role="tool", name="", visible_scope="all", ra
}]
}
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)
2 changes: 1 addition & 1 deletion python/core/components/v2/text_to_image/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def tool_eval(
yield self.create_output(
type='image',
text={
'filename': "",
'filename': self.get_filename_from_url(img_urls[url_number]),
'url': img_urls[url_number],
},
raw_data=raw_data,
Expand Down

0 comments on commit 102957f

Please sign in to comment.