mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
chore: refactor imports for better organization in tool_code.py
This commit is contained in:
parent
56f9132b64
commit
3de7249587
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 = {{
|
||||
|
|
|
|||
Loading…
Reference in New Issue