From 75c3d8abbd0900a19a6091ba67617ac956b442ef Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Wed, 14 May 2025 19:18:36 +0800 Subject: [PATCH] =?UTF-8?q?feat(t2i):=20=E4=B8=BA=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E8=BD=AC=E5=9B=BE=E5=83=8F=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E6=9C=8D=E5=8A=A1=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/config/default.py | 6 ++++++ astrbot/core/pipeline/result_decorate/stage.py | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index d9d604d68..8712ff72b 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -92,6 +92,7 @@ DEFAULT_CONFIG = { "t2i_word_threshold": 150, "t2i_strategy": "remote", "t2i_endpoint": "", + "t2i_use_file_service": False, "http_proxy": "", "dashboard": { "enable": True, @@ -1448,6 +1449,11 @@ CONFIG_METADATA_2 = { "type": "string", "hint": "当 t2i_strategy 为 remote 时生效。为空时使用 AstrBot API 服务", }, + "t2i_use_file_service": { + "description": "本地文本转图像使用文件服务提供文件", + "type": "bool", + "hint": "当 t2i_strategy 为 local 并且配置 callback_api_base 时生效。是否使用文件服务提供文件。", + }, "pip_install_arg": { "description": "pip 安装参数", "type": "string", diff --git a/astrbot/core/pipeline/result_decorate/stage.py b/astrbot/core/pipeline/result_decorate/stage.py index 920e9204a..fd1134edd 100644 --- a/astrbot/core/pipeline/result_decorate/stage.py +++ b/astrbot/core/pipeline/result_decorate/stage.py @@ -248,6 +248,14 @@ class ResultDecorateStage(Stage): if url: if url.startswith("http"): result.chain = [Image.fromURL(url)] + elif ( + self.ctx.astrbot_config["t2i_use_file_service"] + and self.ctx.astrbot_config["callback_api_base"] + ): + token = await file_token_service.register_file(url) + url = f"{self.ctx.astrbot_config['callback_api_base']}/api/file/{token}" + logger.debug(f"已注册:{url}") + result.chain = [Image.fromURL(url)] else: result.chain = [Image.fromFileSystem(url)]