mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-07-18 10:26:07 +00:00
fix(dify): display agent image
This commit is contained in:
@@ -117,7 +117,7 @@ class APIHost:
|
|||||||
# ========== 插件可调用的 API(主程序API) ==========
|
# ========== 插件可调用的 API(主程序API) ==========
|
||||||
|
|
||||||
def get_platform_adapters(self) -> list[platform_adapter.MessageSourceAdapter]:
|
def get_platform_adapters(self) -> list[platform_adapter.MessageSourceAdapter]:
|
||||||
"""获取所有消息平台适配器
|
"""获取已启用的消息平台适配器列表
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
list[platform.adapter.MessageSourceAdapter]: 已启用的消息平台适配器列表
|
list[platform.adapter.MessageSourceAdapter]: 已启用的消息平台适配器列表
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import json
|
|||||||
import uuid
|
import uuid
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
from .. import runner
|
from .. import runner
|
||||||
from ...core import entities as core_entities
|
from ...core import entities as core_entities
|
||||||
from .. import entities as llm_entities
|
from .. import entities as llm_entities
|
||||||
@@ -97,7 +99,7 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
files=files,
|
files=files,
|
||||||
timeout=self.ap.provider_cfg.data["dify-service-api"]["chat"]["timeout"],
|
timeout=self.ap.provider_cfg.data["dify-service-api"]["chat"]["timeout"],
|
||||||
):
|
):
|
||||||
self.ap.logger.debug("dify-chat-chunk: ", chunk)
|
self.ap.logger.debug("dify-chat-chunk: " + str(chunk))
|
||||||
|
|
||||||
if chunk['event'] == 'workflow_started':
|
if chunk['event'] == 'workflow_started':
|
||||||
mode = "workflow"
|
mode = "workflow"
|
||||||
@@ -149,7 +151,8 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
files=files,
|
files=files,
|
||||||
timeout=self.ap.provider_cfg.data["dify-service-api"]["chat"]["timeout"],
|
timeout=self.ap.provider_cfg.data["dify-service-api"]["chat"]["timeout"],
|
||||||
):
|
):
|
||||||
self.ap.logger.debug("dify-agent-chunk: ", chunk)
|
self.ap.logger.debug("dify-agent-chunk: " + str(chunk))
|
||||||
|
|
||||||
if chunk["event"] in ignored_events:
|
if chunk["event"] in ignored_events:
|
||||||
continue
|
continue
|
||||||
if chunk["event"] == "agent_thought":
|
if chunk["event"] == "agent_thought":
|
||||||
@@ -179,6 +182,21 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
yield msg
|
yield msg
|
||||||
|
if chunk['event'] == 'message_file':
|
||||||
|
|
||||||
|
if chunk['type'] == 'image' and chunk['belongs_to'] == 'assistant':
|
||||||
|
|
||||||
|
base_url = self.dify_client.base_url
|
||||||
|
|
||||||
|
if base_url.endswith('/v1'):
|
||||||
|
base_url = base_url[:-3]
|
||||||
|
|
||||||
|
image_url = base_url + chunk['url']
|
||||||
|
|
||||||
|
yield llm_entities.Message(
|
||||||
|
role="assistant",
|
||||||
|
content=[llm_entities.ContentElement.from_image_url(image_url)],
|
||||||
|
)
|
||||||
|
|
||||||
query.session.using_conversation.uuid = chunk["conversation_id"]
|
query.session.using_conversation.uuid = chunk["conversation_id"]
|
||||||
|
|
||||||
@@ -215,7 +233,7 @@ class DifyServiceAPIRunner(runner.RequestRunner):
|
|||||||
files=files,
|
files=files,
|
||||||
timeout=self.ap.provider_cfg.data["dify-service-api"]["workflow"]["timeout"],
|
timeout=self.ap.provider_cfg.data["dify-service-api"]["workflow"]["timeout"],
|
||||||
):
|
):
|
||||||
self.ap.logger.debug("dify-workflow-chunk: ", chunk)
|
self.ap.logger.debug("dify-workflow-chunk: " + str(chunk))
|
||||||
if chunk["event"] in ignored_events:
|
if chunk["event"] in ignored_events:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user