zhangqian
2024-11-19 69c77e307999f437f6e5a1b28f34eba42e3576d6
审计结果增加文件下载地址
1个文件已修改
19 ■■■■■ 已修改文件
app/api/chat.py 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/api/chat.py
@@ -208,7 +208,6 @@
                    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 +216,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}")