Skip to content

Commit 3de7249

Browse files
committed
chore: refactor imports for better organization in tool_code.py
1 parent 56f9132 commit 3de7249

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from application.flow.i_step_node import NodeResult, INode
2020
from application.flow.step_node.ai_chat_step_node.i_chat_node import IChatNode
2121
from application.flow.tools import Reasoning, mcp_response_generator
22-
from application.models import Application
22+
from application.models import Application, ApplicationApiKey
2323
from common.utils.rsa_util import rsa_long_decrypt
2424
from common.utils.tool_code import ToolExecutor
2525
from models_provider.models import Model
@@ -257,8 +257,14 @@ def _handle_mcp_request(self, mcp_enable, tool_enable, mcp_source, mcp_servers,
257257
self.context['application_ids'] = application_ids
258258
for application_id in application_ids:
259259
app = QuerySet(Application).filter(id=application_id).first()
260+
app_key = QuerySet(ApplicationApiKey).filter(application_id=application_id, is_active=True).first()
261+
# TODO 处理api
262+
if app_key is not None:
263+
api_key = app_key.secret_key
264+
else:
265+
continue
260266
executor = ToolExecutor()
261-
app_config = executor.get_app_mcp_config(app.id, app.name, app.desc)
267+
app_config = executor.get_app_mcp_config(api_key, app.name, app.desc)
262268
mcp_servers_config[str(app.id)] = app_config
263269

264270
if len(mcp_servers_config) > 0:

apps/common/utils/tool_code.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,11 @@ def get_tool_mcp_config(self, code, params, name, description):
236236
def get_app_mcp_config(self, api_key, name, description):
237237
chat_path = CONFIG.get_chat_path()
238238
_code = f'''
239-
import requests
240239
from typing import Optional
241240
242241
def _get_chat_id() -> Optional[str]:
242+
import requests
243+
243244
url = f"http://127.0.0.1:8080{chat_path}/api/open"
244245
headers = {{
245246
'accept': '*/*',
@@ -254,6 +255,8 @@ def _get_chat_id() -> Optional[str]:
254255
255256
256257
def _chat_with_ai(chat_id: str, message: str) -> Optional[str]:
258+
import requests
259+
257260
url = f"http://127.0.0.1:8080{chat_path}/api/chat_message/{{chat_id}}"
258261
headers = {{"Content-Type": "application/json", "Authorization": f'Bearer {api_key}'}}
259262
payload = {{

0 commit comments

Comments
 (0)