From e078028f1a8da34f3cc2cb5095b8e103a996f553 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期五, 11 四月 2025 10:16:42 +0800
Subject: [PATCH] 首页智能体中心过滤掉自研类型
---
app/service/v2/mindmap.py | 77 ++++++++++++++++++++++++++++----------
1 files changed, 57 insertions(+), 20 deletions(-)
diff --git a/app/service/v2/mindmap.py b/app/service/v2/mindmap.py
index dd5b994..ff93e47 100644
--- a/app/service/v2/mindmap.py
+++ b/app/service/v2/mindmap.py
@@ -1,10 +1,11 @@
import json
from Log import logger
-from app.config.agent_base_url import DF_CHAT_AGENT
+from app.config.agent_base_url import DF_CHAT_AGENT, RG_CHAT_DIALOG
from app.config.config import settings
-from app.config.const import message_error, message_event, complex_knowledge_chat
+from app.config.const import message_error, message_event, complex_knowledge_chat, rg_api_token, workflow_finished
from app.models import ComplexChatSessionDao, ChatData
from app.service.v2.app_driver.chat_agent import ChatAgent
+from app.service.v2.app_driver.chat_dialog import ChatDialog
from app.service.v2.chat import get_chat_token
@@ -73,37 +74,59 @@
token = await get_chat_token(db, session.chat_id)
chat = ChatAgent()
url = settings.dify_base_url + DF_CHAT_AGENT
+ chat_request = json.loads(session.query)
if session.mindmap:
- chat_request = json.loads(session.query)
inputs = {"is_deep": chat_request.get("isDeep", 1)}
if session.chat_mode == complex_knowledge_chat:
- inputs["query_json"] = json.dumps(
- {"query": chat_request.get("query", ""), "dataset_ids": chat_request.get("knowledgeId", [])})
- try:
- async for ans in chat.chat_completions(url,
- await chat.complex_request_data(message, session.conversation_id,
- str(user_id), files=chat_request.get("files", []), inputs=inputs),
- await chat.get_headers(token)):
- if ans.get("event") == message_error:
- return res
- elif ans.get("event") == message_event:
- mindmap_query += ans.get("answer", "")
- else:
- continue
+ token = await get_chat_token(db, rg_api_token)
+ # print(token)
+ dialog_url = settings.fwr_base_url + RG_CHAT_DIALOG.format(session.chat_id)
+ dialog_chat = ChatDialog()
+ try:
+ async for ans in dialog_chat.chat_completions(dialog_url, await dialog_chat.complex_request_data(f"绠�瑕佹�荤粨锛歿message}",
+ chat_request["knowledgeId"],
+ session.conversation_id),
+ await dialog_chat.get_headers(token)):
+ if ans.get("code", None) == 102:
+ return res
+ else:
+ if isinstance(ans.get("data"), bool) and ans.get("data") is True:
+ break
+ else:
+ data = ans.get("data", {})
+ mindmap_query = data.get("answer", "")
+ except Exception as e:
+ logger.error(e)
+ else:
+ try:
+ async for ans in chat.chat_completions(url,
+ await chat.complex_request_data(message, session.conversation_id,
+ str(user_id), files=chat_request.get("files", []), inputs=inputs),
+ await chat.get_headers(token)):
+ if ans.get("event") == message_error:
+ return res
+ elif ans.get("event") == workflow_finished:
+ mindmap_query = ans.get("data", {}).get("outputs", {}).get("answer", "")
+ else:
+ continue
- except Exception as e:
- logger.error(e)
- return res
+ except Exception as e:
+ logger.error(e)
+ return res
else:
mindmap_query = session.content
-
+ # print("-----------------", mindmap_query)
try:
+ if chat_request.get("isDeep", 1) == 2:
+ mindmap_query = mindmap_query.split("</think>")[-1]
mindmap_str = ""
+ # print("mindmap_query", mindmap_query)
token = await get_chat_token(db, mindmap_chat_id)
async for ans in chat.chat_completions(url,
await chat.complex_request_data(mindmap_query, "",
str(user_id)),
await chat.get_headers(token)):
+ # print(ans)
if ans.get("event") == message_error:
return res
elif ans.get("event") == message_event:
@@ -114,6 +137,7 @@
except Exception as e:
logger.error(e)
return res
+ # print(mindmap_str)
if "```json" in mindmap_str:
mindmap_list = mindmap_str.split("```")
mindmap_str = mindmap_list[1].lstrip("json")
@@ -191,6 +215,19 @@
return parent_list[:index]+new_node_list+parent_list[index+1:]
+async def service_message_mindmap_parse(db, message_id, user_id):
+ res = {}
+ complex_log = ComplexChatSessionDao(db)
+ session = await complex_log.get_session_by_id(message_id)
+
+ if session.mindmap:
+ try:
+ res_str = await mindmap_join_str(session.mindmap)
+ res["mindmap"] = res_str
+ except Exception as e:
+ logger.error(e)
+ return res
+
if __name__ == '__main__':
a = '{ "title": "鍏ㄧ敓鍛藉懆鏈熺鐞�", "items": [ { "title": "璁惧瑙勫垝涓庨噰璐�", "items": [ { "title": "闇�姹傚垎鏋愪笌閫夊瀷" ,"items": [{"title": "rererer"}, {"title": "trtrtrtrt"}] }, { "title": "渚涘簲鍟嗛�夋嫨涓庡悎鍚岀鐞�" } ] }, { "title": "璁惧瀹夎涓庤皟璇�", "items": [ { "title": "瀹夎瑙勮寖" }, { "title": "璋冭瘯娴嬭瘯" } ] }, { "title": "璁惧浣跨敤", "items": [ { "title": "鎿嶄綔鍩硅" }, { "title": "鎿嶄綔瑙勭▼涓庤褰�" } ] }, { "title": "璁惧缁存姢涓庣淮淇�", "items": [ { "title": "瀹氭湡缁存姢" }, { "title": "鏁呴殰璇婃柇" }, { "title": "澶囦欢绠$悊" } ] }, { "title": "璁惧鏇存柊涓庢敼閫�", "items": [ { "title": "鎶�鏈瘎浼�" }, { "title": "鏇存柊璁″垝" }, { "title": "鏀归�犳柟妗�" } ] }, { "title": "璁惧鎶ュ簾", "items": [ { "title": "鎶ュ簾璇勪及" }, { "title": "鎶ュ簾澶勭悊" } ] }, { "title": "淇℃伅鍖栫鐞�", "items": [ { "title": "璁惧绠$悊绯荤粺" }, { "title": "鏁版嵁鍒嗘瀽" }, { "title": "杩滅▼鐩戞帶" } ] }, { "title": "瀹夊叏绠$悊", "items": [ { "title": "瀹夊叏鍩硅" }, { "title": "瀹夊叏妫�鏌�" }, { "title": "搴旀�ラ妗�" } ] }, { "title": "鐜淇濇姢", "items": [ { "title": "鐜繚璁惧" }, { "title": "搴熺墿澶勭悊" }, { "title": "鑺傝兘鍑忔帓" } ] }, { "title": "鍏蜂綋瀹炶返妗堜緥", "items": [ { "title": "楂樺帇寮�鍏宠澶囨鼎婊戣剛閫夌敤鐮旂┒" }, { "title": "鐜繚鍨� C4 娣锋皵 GIS 璁惧杩愮淮鎶�鏈爺绌�" } ] }, { "title": "鎬荤粨", "items": [ { "title": "鎻愰珮杩愯惀鏁堢巼鍜岀珵浜夊姏" } ] } ]}'
--
Gitblit v1.8.0