From 67626f1c71d76c5e3d1646259024cb4a452c2890 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期三, 20 十一月 2024 15:59:11 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.5.5:10010/r/rag-gateway --- app/api/chat.py | 26 +++++++++++++++++++------- 1 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/api/chat.py b/app/api/chat.py index b5bfd6a..e0abd8d 100644 --- a/app/api/chat.py +++ b/app/api/chat.py @@ -14,6 +14,7 @@ from app.service.basic import BasicService from app.service.ragflow import RagflowService from app.service.service_token import get_bisheng_token, get_ragflow_token +from app.service.session import SessionService router = APIRouter() @@ -203,12 +204,17 @@ # 鎺ユ敹鍓嶇娑堟伅 message = await websocket.receive_json() question = message.get("message") + SessionService(db).create_session( + session_id=chat_id, + name=question, + agent_id=agent_id, + agent_type=AgentType.BASIC + ) if not question: await websocket.send_json({"message": "Invalid request", "type": "error"}) continue service = BasicService(base_url=settings.basic_base_url) - complete_response = "" async for result in service.excel_talk(question, chat_id): try: if result[:5] == "data:": @@ -217,13 +223,19 @@ else: # 鍚﹀垯锛屼繚鎸佸師鏍� text = result - complete_response += text try: - json_data = json.loads(complete_response) - output = json_data.get("output", "") - result = {"message": output, "type": "message"} - await websocket.send_json(result | json_data) - complete_response = "" + data = json.loads(text) + output = data.get("output", "") + excel_name = data.get("excel_name", "") + image_name = data.get("excel_name", "") + excel_url = None + image_url = None + if excel_name: + excel_url = f"/api/files/download/?agent_id=basic_excel_talk&file_id={excel_name}&file_type=excel" + if image_name: + image_url = f"/api/files/download/?agent_id=basic_excel_talk&file_id={image_name}&file_type=image" + result = {"message": output, "type": "message", "excel_url": excel_url, "image_url": image_url} + await websocket.send_json(result | data) except json.JSONDecodeError as e: print(f"Error decoding JSON: {e}") print(f"Response text: {text}") -- Gitblit v1.8.0