dify 支持图片http请求,方便随时追加API
This commit is contained in:
@@ -11,6 +11,7 @@ from plugin_common.message_plugin_interface import MessagePluginInterface
|
||||
from plugin_common.plugin_interface import PluginStatus
|
||||
from plugins.stats_collector.decorators import plugin_stats_decorator
|
||||
from robot_cmd.robot_command import Feature, PermissionStatus, GroupBotManager
|
||||
from utils.media_downloader import MediaDownloader
|
||||
|
||||
|
||||
class DifyPlugin(MessagePluginInterface):
|
||||
@@ -152,7 +153,13 @@ class DifyPlugin(MessagePluginInterface):
|
||||
|
||||
# 发送回复
|
||||
if response:
|
||||
wcf.send_text(response, (roomid if roomid else sender), sender if roomid else "")
|
||||
# 判断是否为本地文件路径
|
||||
if os.path.isfile(response):
|
||||
# 如果是文件路径,使用发送文件方法
|
||||
wcf.send_file(response, (roomid if roomid else sender))
|
||||
else:
|
||||
# 如果是普通文本,使用发送文本方法
|
||||
wcf.send_text(response, (roomid if roomid else sender), sender if roomid else "")
|
||||
return True, "发送成功"
|
||||
else:
|
||||
wcf.send_text("❌未能获取到回复,请稍后再试", (roomid if roomid else sender), sender if roomid else "")
|
||||
@@ -256,10 +263,17 @@ class DifyPlugin(MessagePluginInterface):
|
||||
# 获取输出内容
|
||||
outputs = response_data.get("data", {}).get("outputs", {})
|
||||
if outputs:
|
||||
# 尝试从text字段获取回答
|
||||
if "text" in outputs and isinstance(outputs["text"], str):
|
||||
# 处理媒体类型返回
|
||||
if "result" in outputs and "type" in outputs:
|
||||
if outputs["type"] == "image":
|
||||
downloader = MediaDownloader()
|
||||
image_url = outputs["result"]
|
||||
image_path = downloader.download_media(image_url)
|
||||
answer = image_path
|
||||
# 处理文本类型返回
|
||||
elif "text" in outputs and isinstance(outputs["text"], str):
|
||||
answer = outputs["text"]
|
||||
# 如果没有text字段,尝试从其他字段获取
|
||||
# 兼容旧版处理逻辑
|
||||
else:
|
||||
for key, value in outputs.items():
|
||||
if isinstance(value, str) and value.strip():
|
||||
|
||||
Reference in New Issue
Block a user