diff --git a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py index d4bcc4f96..36297a60f 100644 --- a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py +++ b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py @@ -19,7 +19,7 @@ from langchain_core.messages import BaseMessage, AIMessage from application.flow.i_step_node import NodeResult, INode from application.flow.step_node.ai_chat_step_node.i_chat_node import IChatNode from application.flow.tools import Reasoning, mcp_response_generator -from application.models import Application +from application.models import Application, ApplicationApiKey from common.utils.rsa_util import rsa_long_decrypt from common.utils.tool_code import ToolExecutor from models_provider.models import Model @@ -257,8 +257,14 @@ class BaseChatNode(IChatNode): self.context['application_ids'] = application_ids for application_id in application_ids: app = QuerySet(Application).filter(id=application_id).first() + app_key = QuerySet(ApplicationApiKey).filter(application_id=application_id, is_active=True).first() + # TODO 处理api + if app_key is not None: + api_key = app_key.secret_key + else: + continue executor = ToolExecutor() - app_config = executor.get_app_mcp_config(app.id, app.name, app.desc) + app_config = executor.get_app_mcp_config(api_key, app.name, app.desc) mcp_servers_config[str(app.id)] = app_config if len(mcp_servers_config) > 0: diff --git a/apps/common/utils/tool_code.py b/apps/common/utils/tool_code.py index cd0e21226..9b86a456f 100644 --- a/apps/common/utils/tool_code.py +++ b/apps/common/utils/tool_code.py @@ -236,10 +236,11 @@ exec({dedent(code)!a}) def get_app_mcp_config(self, api_key, name, description): chat_path = CONFIG.get_chat_path() _code = f''' -import requests from typing import Optional def _get_chat_id() -> Optional[str]: + import requests + url = f"http://127.0.0.1:8080{chat_path}/api/open" headers = {{ 'accept': '*/*', @@ -254,6 +255,8 @@ def _get_chat_id() -> Optional[str]: def _chat_with_ai(chat_id: str, message: str) -> Optional[str]: + import requests + url = f"http://127.0.0.1:8080{chat_path}/api/chat_message/{{chat_id}}" headers = {{"Content-Type": "application/json", "Authorization": f'Bearer {api_key}'}} payload = {{