From b10d6051ba9545441dd3acf2214347fd63c8b781 Mon Sep 17 00:00:00 2001 From: Yeuoly Date: Mon, 2 Dec 2024 16:51:37 +0800 Subject: [PATCH] fix: summary and create_file_by_url --- api/controllers/inner_api/plugin/plugin.py | 12 +++++++----- api/core/tools/tool_file_manager.py | 5 ++--- api/core/tools/utils/message_transformer.py | 3 --- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/api/controllers/inner_api/plugin/plugin.py b/api/controllers/inner_api/plugin/plugin.py index fd317519bb..d147404517 100644 --- a/api/controllers/inner_api/plugin/plugin.py +++ b/api/controllers/inner_api/plugin/plugin.py @@ -242,11 +242,13 @@ class PluginInvokeSummaryApi(Resource): def post(self, user_model: Account | EndUser, tenant_model: Tenant, payload: RequestInvokeSummary): try: return BaseBackwardsInvocationResponse( - data=PluginModelBackwardsInvocation.invoke_summary( - user_id=user_model.id, - tenant=tenant_model, - payload=payload, - ) + data={ + "summary": PluginModelBackwardsInvocation.invoke_summary( + user_id=user_model.id, + tenant=tenant_model, + payload=payload, + ) + } ).model_dump() except Exception as e: return BaseBackwardsInvocationResponse(error=str(e)).model_dump() diff --git a/api/core/tools/tool_file_manager.py b/api/core/tools/tool_file_manager.py index a028668c07..bba4be6772 100644 --- a/api/core/tools/tool_file_manager.py +++ b/api/core/tools/tool_file_manager.py @@ -8,9 +8,8 @@ from mimetypes import guess_extension, guess_type from typing import Optional, Union from uuid import uuid4 -from httpx import get - from configs import dify_config +from core.helper import ssrf_proxy from extensions.ext_database import db from extensions.ext_storage import storage from models.model import MessageFile @@ -94,7 +93,7 @@ class ToolFileManager: ) -> ToolFile: # try to download image try: - response = get(file_url) + response = ssrf_proxy.get(file_url) response.raise_for_status() blob = response.content except Exception as e: diff --git a/api/core/tools/utils/message_transformer.py b/api/core/tools/utils/message_transformer.py index 8d436d7bed..2385aa9b5b 100644 --- a/api/core/tools/utils/message_transformer.py +++ b/api/core/tools/utils/message_transformer.py @@ -30,9 +30,6 @@ class ToolFileMessageTransformer: ): # try to download image try: - if not conversation_id: - raise - assert isinstance(message.message, ToolInvokeMessage.TextMessage) file = ToolFileManager.create_file_by_url(