Skip to content

Commit

Permalink
Merge pull request #972 from RockChinQ/fix/dify-back-image
Browse files Browse the repository at this point in the history
fix(dify): display agent image
  • Loading branch information
RockChinQ authored Jan 6, 2025
2 parents 599ab83 + 7f034b4 commit 53dde06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/plugin/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async def initialize(self):
# ========== 插件可调用的 API(主程序API) ==========

def get_platform_adapters(self) -> list[platform_adapter.MessageSourceAdapter]:
"""获取所有消息平台适配器
"""获取已启用的消息平台适配器列表
Returns:
list[platform.adapter.MessageSourceAdapter]: 已启用的消息平台适配器列表
Expand Down
24 changes: 21 additions & 3 deletions pkg/provider/runners/difysvapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import uuid
import base64

import aiohttp

from .. import runner
from ...core import entities as core_entities
from .. import entities as llm_entities
Expand Down Expand Up @@ -97,7 +99,7 @@ async def _chat_messages(
files=files,
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':
mode = "workflow"
Expand Down Expand Up @@ -149,7 +151,8 @@ async def _agent_chat_messages(
files=files,
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:
continue
if chunk["event"] == "agent_thought":
Expand Down Expand Up @@ -179,6 +182,21 @@ async def _agent_chat_messages(
],
)
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"]

Expand Down Expand Up @@ -215,7 +233,7 @@ async def _workflow_messages(
files=files,
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:
continue

Expand Down

0 comments on commit 53dde06

Please sign in to comment.