| | |
| | | tmp_data["question"] = i.get("content") |
| | | elif i.get("role") == "assistant": |
| | | if isinstance(i.get("content"), dict): |
| | | content = i.get("content", {}) |
| | | tmp_data["answer"] = i.get("content", {}).get("answer") |
| | | if "file_name" in i.get("content", {}): |
| | | tmp_data["files"] = [{"file_name": i.get("content", {}).get("file_name"), |
| | |
| | | |
| | | if "download_url" in i.get("content", {}): |
| | | tmp_data["download_url"] = i.get("content", {}).get("download_url") |
| | | if "node_list" in content: |
| | | node_dict = { |
| | | "node_data": [], |
| | | # {"title": "去除冗余", # 节点名称 "status": "succeeded", # 节点状态"created_at": 1735817337, # 开始时间"finished_at": 1735817337, # 结束时间"error": "" # 错误日志} |
| | | "total_tokens": 0, # 花费token数 |
| | | "created_at": 0, # 开始时间 |
| | | "finished_at": 0, # 结束时间 |
| | | "elapsed_time": 0, # 结束时间 |
| | | "status": "succeeded", # 工作流状态 |
| | | "error": "", # 错误日志 |
| | | } |
| | | for node in content["node_list"]: |
| | | if node.get("event") == "node_finished": |
| | | node_dict["node_data"].append({ |
| | | "title": node.get("data", {}).get("title", ""), |
| | | "status": node.get("data", {}).get("status", ""), |
| | | "created_at": node.get("data", {}).get("created_at", 0), |
| | | "finished_at": node.get("data", {}).get("finished_at", 0), |
| | | "node_type": node.get("data", {}).get("node_type", 0), |
| | | "elapsed_time": node.get("data", {}).get("elapsed_time", 0), |
| | | "error": node.get("data", {}).get("error", ""), |
| | | }) |
| | | elif node.get("event") == "workflow_finished": |
| | | node_dict["total_tokens"] = node.get("data", {}).get("total_tokens", 0) |
| | | node_dict["created_at"] = node.get("data", {}).get("created_at", 0) |
| | | node_dict["finished_at"] = node.get("data", {}).get("finished_at", 0) |
| | | node_dict["status"] = node.get("data", {}).get("status", "") |
| | | node_dict["error"] = node.get("data", {}).get("error", "") |
| | | node_dict["elapsed_time"] = node.get("data", {}).get("elapsed_time", 0) |
| | | tmp_data["workflow"] = node_dict |
| | | else: |
| | | tmp_data["answer"] = i.get("content") |
| | | data.append(tmp_data) |
| | |
| | | continue |
| | | try: |
| | | name = login_data.username |
| | | email = "" |
| | | app_password = login_data.password |
| | | user_app = await UserAppDao(db).get_data_by_id(user.id, app["id"]) |
| | | if user_app: |
| | | name = user_app.username |
| | | email = user_app.email |
| | | app_password = user_app.decrypted_password(user_app.password) |
| | | else: |
| | | await update_user_info(db, user.id) |
| | | token = await service.login(name, app_password) |
| | | token = await service.login(name, app_password,email=email) |
| | | token_dict[app["id"]] = token |
| | | except Exception as e: |
| | | return Response(code=500, msg=f"Failed to login with {app['id']}: {str(e)}") |
| | |
| | | import json |
| | | import re |
| | | import uuid |
| | | from copy import deepcopy |
| | | |
| | | from fastapi import WebSocket, WebSocketDisconnect, APIRouter, Depends |
| | |
| | | question, |
| | | agent_id, |
| | | AgentType.BASIC, |
| | | current_user.id |
| | | current_user.id, |
| | | {"role": "user", "content": question} |
| | | ) |
| | | except Exception as e: |
| | | logger.error(e) |
| | |
| | | question, |
| | | agent_id, |
| | | AgentType.DIFY, |
| | | current_user.id |
| | | current_user.id, |
| | | {"role": "user", "content": question} |
| | | ) |
| | | conversation_id = session.conversation_id |
| | | except Exception as e: |
| | |
| | | result = {"message": f"内部错误: {e2}", "type": "close"} |
| | | await websocket.send_json(result) |
| | | print(f"Error process message of ragflow: {e2}") |
| | | elif agent.type == "documentIa": |
| | | elif chat_type == "documentIa": |
| | | token = DfTokenDao(db).get_token_by_id(DOCUMENT_IA_QUESTIONS) |
| | | # print(token) |
| | | if not token: |
| | |
| | | question, |
| | | agent_id, |
| | | AgentType.DIFY, |
| | | current_user.id |
| | | current_user.id, |
| | | {"role": "user", "content": question} |
| | | ) |
| | | conversation_id = session.conversation_id |
| | | except Exception as e: |
| | |
| | | result = {"message": f"内部错误: {e2}", "type": "close"} |
| | | await websocket.send_json(result) |
| | | print(f"Error process message of ragflow: {e2}") |
| | | |
| | | |
| | | # 启动任务处理客户端消息 |
| | | tasks = [ |
| | |
| | | raise HTTPException(status_code=500, detail=str(e)) |
| | | elif agent.chat_type == "reportWorkflow" or agent.chat_type == "documentIa" or agent.chat_type == "paperTalk": |
| | | token_dict = { |
| | | "reportWorkflow": DOCUMENT_TO_REPORT, |
| | | "reportWorkflow": DOCUMENT_TO_REPORT_TITLE, |
| | | "documentIa": DOCUMENT_IA_QUESTIONS, |
| | | "paperTalk": DOCUMENT_TO_PAPER, |
| | | } |
New file |
| | |
| | | smart_server: |
| | | account: administer |
| | | password: basic@2025 |
| | | |
| | | ragflow_app: |
| | | id: 2c039666c29d11efa4670242ac1b0006 |
| | | account: admin@example.com |
| | | password: basic@2025 |
| | | |
| | | dify_app: |
| | | account: admin@mail.com |
| | | password: basic@2025 |
| | |
| | | { |
| | | "data": [ |
| | | { |
| | | "id": 10, |
| | | "title": "报告生成", |
| | | "icon": "2", |
| | | "img": "/src/assets/index/2.png", |
| | | "desc": "基于您创建的报告格式和知识库中的文档内容,快速生成定制报告,并支持一键下载。", |
| | | "describe": "基于您创建的报告格式和知识库中的文档内容,快速生成定制报告,并支持一键下载。", |
| | | "rank": 100, |
| | | "dialog": [ |
| | | { |
| | | "id": "80ee430a-e396-48c4-a12c-7c7cdf5eda51", |
| | | "chat_id": "80ee430a-e396-48c4-a12c-7c7cdf5eda51", |
| | | "chat_type": "report", |
| | | "agentType": 2 |
| | | } |
| | | ] |
| | | }, |
| | | { |
| | | "id": 1, |
| | | "title": "报表合并", |
| | | "icon": "6", |
| | |
| | | }, |
| | | { |
| | | "id": 9, |
| | | "title": "文档报告", |
| | | "title": "报告生成", |
| | | "icon": "2", |
| | | "img": "/src/assets/index/2.png", |
| | | "desc": "基于您创建的报告格式和上传的文档内容,快速生成定制报告,并支持一键下载。", |
| | |
| | | "rank": 91, |
| | | "dialog": [ |
| | | { |
| | | "id": "72a69e47-458d-47f9-b534-1859e5da244f", |
| | | "id": "87b8e17c-594d-424f-b9f8-0b56036904c9", |
| | | "chat_id": "basic_report_clean", |
| | | "chat_type": "reportWorkflow", |
| | | "agentType": 4 |
| | | }, |
| | | { |
| | | "id": "6eda0700-6273-488d-a97c-88d315bd9d8f", |
| | | "id": "61d26deb-9371-4f9c-b61b-b9f9a24a9188", |
| | | "chat_id": "basic_report_clean", |
| | | "chat_type": "reportWorkflow", |
| | | "agentType": 4 |
| | | }, |
| | | { |
| | | "id": "d6eea92d-444a-4658-b9e7-9ab7bd5cb19d", |
| | | "chat_id": "basic_report_clean", |
| | | "chat_type": "reportWorkflow", |
| | | "agentType": 4 |
| | |
| | | [ |
| | | { |
| | | "id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "created_at": "8/8/2024 19:21:42", |
| | | "updated_at": "8/8/2024 19:21:42", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "root", |
| | | "url": "root", |
| | | "path": null, |
| | |
| | | "resource_type_id": "3", |
| | | "resource_id": null, |
| | | "status": "1", |
| | | "hidden": null, |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "76e81844-c3a6-4ea0-882f-150be2987d9d", |
| | | "created_at": "23/12/2024 09:50:31", |
| | | "updated_at": "23/12/2024 09:50:31", |
| | | "id": "8eadbabd-cf55-469b-ad74-4f9fc80631a1", |
| | | "created_at": "10/1/2025 18:48:05", |
| | | "updated_at": "10/1/2025 18:48:05", |
| | | "name": "智能体详情", |
| | | "url": "/intelligent/detail", |
| | | "url": "DifyDetail", |
| | | "path": "/intelligent/detail", |
| | | "perms": "system:intelligent:detail", |
| | | "description": "", |
| | |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "3", |
| | | "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "status": "2", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "21e90633-bb76-4419-8925-c20b9ccd33f1", |
| | | "created_at": "10/1/2025 18:48:05", |
| | | "updated_at": "10/1/2025 18:48:05", |
| | | "name": "知识库详情", |
| | | "url": "KnowledgeDetail", |
| | | "path": "/knowledge/detail", |
| | | "perms": "system:knowledge:detail", |
| | | "description": "", |
| | | "icon": "", |
| | | "seq": 0, |
| | | "target": null, |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "3", |
| | | "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "3750795c-404b-488b-8080-89c037b4a187", |
| | | "created_at": "18/12/2024 19:20:09", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "小数", |
| | | "url": "Xiaoshu", |
| | | "path": "/xiaoshu", |
| | |
| | | }, |
| | | { |
| | | "id": "3ea0f0b8-5160-4005-91d6-7c6650a5934c", |
| | | "created_at": "20/12/2024 11:38:54", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "会话历史", |
| | | "url": "ConversationHistory", |
| | | "path": "/chat/history", |
| | |
| | | }, |
| | | { |
| | | "id": "6469b565-908a-4771-a9e3-1cf8651b26f4", |
| | | "created_at": "12/9/2024 08:01:13", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "会话", |
| | | "url": "ConversationQA", |
| | | "path": "/chat/qa", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "6b3640d2-6142-4dce-b09b-ce11f9e6c89c", |
| | | "created_at": "20/12/2024 11:38:54", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "会话进行中", |
| | | "url": "ConversationQA", |
| | | "path": "/chat/qa", |
| | |
| | | }, |
| | | { |
| | | "id": "6da7445a-5980-4380-ab1d-75021c1dd269", |
| | | "created_at": "18/12/2024 19:20:09", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "智能体", |
| | | "url": "Intelligent", |
| | | "path": "/intelligent", |
| | |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "a4931c80-c890-4142-a698-87940c937b57", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "会话面板", |
| | | "url": "ConversationBoard", |
| | | "path": "/chat/board", |
| | | "perms": "system:conversation:board", |
| | | "description": "", |
| | | "icon": "", |
| | | "seq": 0, |
| | | "target": null, |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "3", |
| | | "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "9fb9456c-1000-485e-9cbb-905d951b86c1", |
| | | "created_at": "18/12/2024 19:20:09", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "知识库管理", |
| | | "url": "Knowledge", |
| | | "path": "/knowledge", |
| | |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "2d1c2831-79f4-4817-b79f-be4e49687bd1", |
| | | "created_at": "19/12/2024 10:08:40", |
| | | "updated_at": "24/12/2024 19:15:20", |
| | | "name": "知识库详情", |
| | | "url": "KnowledgeDetail", |
| | | "path": "detail", |
| | | "perms": "system:knowledge:detail", |
| | | "description": "", |
| | | "icon": "", |
| | | "seq": 0, |
| | | "target": null, |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "3", |
| | | "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "242060f6-741e-423a-8634-2f7ece1f0c6d", |
| | | "created_at": "19/12/2024 10:08:40", |
| | | "updated_at": "24/12/2024 19:15:20", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "知识库删除", |
| | | "url": "-", |
| | | "path": "-", |
| | |
| | | }, |
| | | { |
| | | "id": "25722c9e-63fe-4c80-8c05-5fcb9fb58d01", |
| | | "created_at": "19/12/2024 10:08:40", |
| | | "updated_at": "24/12/2024 19:15:20", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "知识库新增", |
| | | "url": "-", |
| | | "path": "-", |
| | |
| | | "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1", |
| | | "status": "0", |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "91be8704-d6ac-4941-ab9b-02ebfd9c56a3", |
| | | "created_at": "10/1/2025 17:51:51", |
| | | "updated_at": "10/1/2025 18:48:05", |
| | | "name": "文档上传", |
| | | "url": "-", |
| | | "path": "-", |
| | | "perms": "system:knowledgeLib:upload", |
| | | "description": "", |
| | | "icon": "", |
| | | "seq": 0, |
| | | "target": null, |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "1", |
| | | "resource_id": "9fb9456c-1000-485e-9cbb-905d951b86c1", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | } |
| | | ] |
| | | }, |
| | | { |
| | | "id": "a4931c80-c890-4142-a698-87940c937b57", |
| | | "created_at": "20/12/2024 11:38:54", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "name": "会话面板", |
| | | "url": "ConversationBoard", |
| | | "path": "/chat/board", |
| | | "perms": "system:conversation:board", |
| | | "description": "", |
| | | "icon": "", |
| | | "seq": 0, |
| | | "target": null, |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "3", |
| | | "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "online", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "模型管理", |
| | | "url": "Model", |
| | | "path": "/model", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "xtgl", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "20/12/2024 11:38:54", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "权限管理", |
| | | "url": "layout/LayoutPermission", |
| | | "path": "/permission", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "1eed48e2-d510-42f2-9495-bc299bae237b", |
| | | "status": "1", |
| | | "hidden": null, |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed", |
| | | "created_at": "28/10/2024 07:38:41", |
| | | "updated_at": "18/12/2024 20:05:23", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "用户组管理", |
| | | "url": "PermissionGroup", |
| | | "path": "/permission/group", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "xtgl", |
| | | "status": "1", |
| | | "hidden": null, |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "0bcb1f37-f87e-4f47-ba72-a2e194884b8f", |
| | | "created_at": "28/10/2024 07:41:16", |
| | | "updated_at": "18/12/2024 15:09:28", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "编辑用户组", |
| | | "url": "/base/syuser!update", |
| | | "path": "", |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "2648f4bd-b5d5-4a34-8b9c-128fd970b014", |
| | | "created_at": "18/12/2024 15:09:28", |
| | | "updated_at": "18/12/2024 15:09:28", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "用户组成员管理", |
| | | "url": "-", |
| | | "path": "", |
| | |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "3daf1a03-c0c9-4ebd-935d-fe46561971fb", |
| | | "created_at": "28/10/2024 07:46:14", |
| | | "updated_at": "28/10/2024 07:46:41", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "用户组列表", |
| | | "url": "/base/syuser!grid", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed", |
| | | "status": "1", |
| | | "hidden": null |
| | | }, |
| | | |
| | | { |
| | | "id": "72fe917f-70ee-4cbf-8c21-f1852f3ef037", |
| | | "created_at": "18/12/2024 15:09:28", |
| | | "updated_at": "19/12/2024 16:08:38", |
| | | "name": "用户组权限管理", |
| | | "url": "-", |
| | | "path": "", |
| | | "perms": "system:group:permissionConfig", |
| | | "description": "", |
| | | "icon": "", |
| | | "seq": 0, |
| | | "target": null, |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "1", |
| | | "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "5d9ab44e-488c-4dd8-8688-56650393fab1", |
| | | "created_at": "18/12/2024 11:35:02", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "删除用户组", |
| | | "url": "-", |
| | | "path": "", |
| | |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "72fe917f-70ee-4cbf-8c21-f1852f3ef037", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "10/1/2025 18:48:05", |
| | | "name": "用户组权限管理", |
| | | "url": "-", |
| | | "path": "-", |
| | | "perms": "system:group:permissionConfig", |
| | | "description": "", |
| | | "icon": "", |
| | | "seq": 0, |
| | | "target": null, |
| | | "canbdeeleted": null, |
| | | "resource_type_id": "1", |
| | | "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed", |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "f2b2c9be-1c39-4416-b3c7-21891fc28f84", |
| | | "created_at": "28/10/2024 07:56:04", |
| | | "updated_at": "28/10/2024 07:56:04", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "添加用户组", |
| | | "url": "/base/sygroup!save", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "0642e4a6-3d48-4635-ba2a-bf4e39c351ed", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | } |
| | | ] |
| | | }, |
| | | { |
| | | "id": "jggl", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 20:05:23", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "机构管理", |
| | | "url": "PermissionOrganization", |
| | | "path": "/permission/org", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "xtgl", |
| | | "status": "1", |
| | | "hidden": null, |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "jgbj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/5/2022 00:39:56", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "编辑机构", |
| | | "url": "/base/syorganization!update", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jggl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "jglb", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "28/11/2016 14:09:52", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "机构列表", |
| | | "url": "/base/syorganization!treeGrid", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jggl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "jgsc", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "删除机构", |
| | | "url": "/base/syorganization!delete", |
| | | "path": "", |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jggl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "jgtj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "添加机构", |
| | | "url": "/base/syorganization!save", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jggl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | } |
| | | ] |
| | | }, |
| | | { |
| | | "id": "jsgl", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 20:05:23", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "角色管理", |
| | | "url": "PermissionRole", |
| | | "path": "/permission/role", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "xtgl", |
| | | "status": "1", |
| | | "hidden": null, |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "00b61433-a5cd-46e9-a867-2e249dd310f4", |
| | | "created_at": "18/12/2024 11:35:02", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "角色权限配置", |
| | | "url": "-", |
| | | "path": "", |
| | |
| | | }, |
| | | { |
| | | "id": "f9947112-c8e4-42cd-ba3a-2612eb373564", |
| | | "created_at": "18/12/2024 11:35:02", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "角色部门配置", |
| | | "url": "-", |
| | | "path": "", |
| | |
| | | }, |
| | | { |
| | | "id": "jsbj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "编辑角色", |
| | | "url": "/base/syrole!update", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jsgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "jslb", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "角色列表", |
| | | "url": "/base/syrole!grid", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jsgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "jssc", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "删除角色", |
| | | "url": "/base/syrole!delete", |
| | | "path": "", |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jsgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | { |
| | | "id": "jstj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "添加角色", |
| | | "url": "/base/syrole!save", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "jsgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | } |
| | | ] |
| | | }, |
| | | |
| | | { |
| | | "id": "yhgl", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 20:05:23", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "用户管理", |
| | | "url": "PermissionAccount", |
| | | "path": "/permission/account", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "xtgl", |
| | | "status": "1", |
| | | "hidden": null, |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "07417a54-4afc-45ec-84ee-c59baf7d45b4", |
| | | "created_at": "18/12/2024 11:35:02", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "用户角色", |
| | | "url": "-", |
| | | "path": "", |
| | |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "a06316f1-b7e4-48b8-80c8-49b1dbb79c4a", |
| | | "created_at": "18/12/2024 11:35:02", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "重制密码", |
| | | "url": "-", |
| | | "path": "", |
| | |
| | | "status": "0", |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "e368cae2-96b6-46e5-b537-946a8dc5ede6", |
| | | "created_at": "18/12/2024 11:35:02", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "部门配置", |
| | | "url": "-", |
| | | "path": "", |
| | |
| | | "status": "1", |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "yhbj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "编辑用户", |
| | | "url": "/base/syuser!update", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "yhgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "yhlb", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "用户列表", |
| | | "url": "/base/syuser!grid", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "yhgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "yhsc", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "删除用户", |
| | | "url": "/base/syuser!delete", |
| | | "path": "", |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "yhgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "yhtj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "添加用户", |
| | | "url": "/base/syuser!save", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "yhgl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | } |
| | | ] |
| | | }, |
| | | { |
| | | "id": "zygl", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 20:05:23", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "资源管理", |
| | | "url": "PermissionResource", |
| | | "path": "/permission/resource", |
| | |
| | | "resource_type_id": "0", |
| | | "resource_id": "xtgl", |
| | | "status": "1", |
| | | "hidden": null, |
| | | "hidden": 0, |
| | | "children": [ |
| | | { |
| | | "id": "zybj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "5/9/2024 03:14:57", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "编辑资源", |
| | | "url": "/base/syresource!update", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "zygl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "zylb", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "资源列表", |
| | | "url": "/base/syresource!treeGrid", |
| | | "path": "", |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "zygl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "zysc", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "18/12/2024 11:35:02", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "删除资源", |
| | | "url": "/base/syresource!delete", |
| | | "path": "", |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "zygl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | }, |
| | | |
| | | { |
| | | "id": "zytj", |
| | | "created_at": "25/8/2015 10:34:53", |
| | | "updated_at": "25/8/2015 10:34:53", |
| | | "created_at": "26/12/2024 18:45:57", |
| | | "updated_at": "26/12/2024 18:45:57", |
| | | "name": "添加资源", |
| | | "url": "/base/syresource!save", |
| | | "path": null, |
| | |
| | | "resource_type_id": "1", |
| | | "resource_id": "zygl", |
| | | "status": "1", |
| | | "hidden": null |
| | | "hidden": 0 |
| | | } |
| | | ] |
| | | } |
| | |
| | | } |
| | | ] |
| | | } |
| | | ] |
| | | ] |
| | |
| | | from app.models.base_model import SessionLocal |
| | | from app.service.v2.initialize_data import dialog_menu_sync, default_group_sync, default_role_sync, app_register_sync, \ |
| | | basic_agent_sync, admin_account_sync |
| | | from app.task.fetch_agent import sync_resources_from_json |
| | | basic_agent_sync, admin_account_sync, admin_user_sync |
| | | |
| | | |
| | | async def sync_default_data(): |
| | | db = SessionLocal() |
| | | await dialog_menu_sync(db) # 小数 |
| | | await default_group_sync(db) # 默认组 |
| | | await default_role_sync(db) # 默认角色 |
| | | await app_register_sync(db) # 注册的应用 |
| | | await basic_agent_sync(db) # 开发的agent |
| | | await admin_account_sync(db) # 超管账号 |
| | | try: |
| | | await dialog_menu_sync(db) # 小数 |
| | | await default_group_sync(db) # 默认组 |
| | | await default_role_sync(db) # 默认角色 |
| | | await app_register_sync(db) # 注册的应用 |
| | | await basic_agent_sync(db) # 开发的agent |
| | | await admin_account_sync(db) # |
| | | await admin_user_sync(db) # |
| | | except Exception as e: |
| | | print(e) |
| | | finally: |
| | | db.close() |
| | | # await default_role_sync(db) # 页面资源配置信息 |
| | | # await default_role_sync(db) # 默认的角色资源 |
| | | |
| | |
| | | 'name': self.name, |
| | | 'agent_type': self.agent_type, |
| | | 'agent_id': self.agent_id, |
| | | 'workflow': self.workflow if self.workflow else 0, |
| | | 'create_date': self.create_date.strftime("%Y-%m-%d %H:%M:%S"), |
| | | 'update_date': self.update_date.strftime("%Y-%m-%d %H:%M:%S"), |
| | | } |
| | |
| | | # print(response.text) |
| | | return self._handle_response(response) |
| | | |
| | | async def login(self, username: str, password: str, remember_me=True, invite_token:str="") -> str: |
| | | async def login(self, username: str, password: str, remember_me=True, invite_token:str="", email="") -> str: |
| | | # password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password) |
| | | data = {"email": f"{username}@basic.com", "password": password, "remember_me": remember_me, "invite_token": invite_token, |
| | | data = {"email":email if email else f"{username}@basic.com", "password": password, "remember_me": remember_me, "invite_token": invite_token, |
| | | "language": "zh-Hans"} |
| | | |
| | | async with httpx.AsyncClient() as client: |
| | |
| | | raise Exception(f"Ragflow registration failed: {response.text}") |
| | | return self._handle_response(response) |
| | | |
| | | async def login(self, username: str, password: str) -> str: |
| | | async def login(self, username: str, password: str, email="") -> str: |
| | | password = RagflowCrypto(settings.PUBLIC_KEY, settings.PRIVATE_KEY).encrypt(password) |
| | | async with httpx.AsyncClient() as client: |
| | | response = await client.post( |
| | | f"{self.base_url}/v1/user/login", |
| | | headers={'Content-Type': 'application/json'}, |
| | | json={"email": f"{username}@example.com", "password": password} |
| | | json={"email": email if email else f"{username}@example.com", "password": password} |
| | | ) |
| | | if response.status_code != 200: |
| | | raise Exception(f"Ragflow login failed: {response.text}") |
| | |
| | | def __init__(self, db: Session): |
| | | self.db = db |
| | | |
| | | def create_session(self, session_id: str, name: str, agent_id: str, agent_type: AgentType, user_id: int, |
| | | message: dict = None, workflow_type: int = 0) -> Type[SessionModel] | SessionModel: |
| | | |
| | | def create_session(self, session_id: str, name: str, agent_id: str, agent_type: AgentType, user_id: int, message: dict = None, workflow_type: int = 0) -> Type[ |
| | | SessionModel] | SessionModel: |
| | | |
| | | """ |
| | | 创建一个新的会话记录。 |
| | | |
| | |
| | | message = {"role": "user", "content": name} |
| | | existing_session = self.get_session_by_id(session_id) |
| | | if existing_session: |
| | | # existing_session.add_message({"role": "user", "content": name}) |
| | | existing_session.add_message(message) |
| | | existing_session.update_date = current_time() |
| | | self.db.commit() |
| | |
| | | agent_type=agent_type, |
| | | tenant_id=user_id, |
| | | workflow=workflow_type, |
| | | message=json.dumps([message]) |
| | | message = json.dumps([message]) |
| | | ) |
| | | self.db.add(new_session) |
| | | self.db.commit() |
| | |
| | | import os |
| | | |
| | | import yaml |
| | | from passlib.context import CryptContext |
| | | |
| | | |
| | | from Log import logger |
| | | from app.config.const import DIFY, ENV_CONF_PATH |
| | | # from app.api import pwd_context |
| | | from app.config.const import DIFY, ENV_CONF_PATH, RAGFLOW |
| | | from app.models import MenuCapacityModel, WebMenuModel, GroupModel, RoleModel, DialogModel, UserModel, UserAppModel, \ |
| | | cipher_suite, UserTokenModel |
| | | from app.service.auth import UserAppDao |
| | |
| | | from app.service.v2.app_register import AppRegisterDao |
| | | from app.config.config import settings |
| | | from app.utils.password_handle import generate_password |
| | | |
| | | pwd_context = CryptContext(schemes=["bcrypt"], deprecated="auto") |
| | | |
| | | |
| | | async def dialog_menu_sync(db): |
| | |
| | | db.commit() |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |
| | | async def admin_user_sync(db): |
| | | try: |
| | | config = {} |
| | | with open(os.path.join(ENV_CONF_PATH, "admin.yaml"), 'r', encoding='utf-8') as file: |
| | | # 加载JSON数据 |
| | | config = yaml.safe_load(file) |
| | | # print(config) |
| | | db_user = db.query(UserModel).filter(UserModel.username == config["smart_server"]["account"]).first() |
| | | if db_user: |
| | | print("admin_user_sync: 用户已经存在!") |
| | | return |
| | | register_dict = {} |
| | | |
| | | for app in [RAGFLOW, DIFY]: |
| | | register_dict[app] = {"id": config[app].get("id", "123"), "name": config[app]["account"], |
| | | "pwd":config[app]["password"], |
| | | "email": config[app]["account"]} |
| | | |
| | | # 存储用户信息 |
| | | hashed_password = pwd_context.hash(config["smart_server"]["password"]) |
| | | user_model = UserModel(username=config["smart_server"]["account"], hashed_password=hashed_password, email="", |
| | | phone="", login_name="", sync_flag="", creator=0, permission="admin") |
| | | db.add(user_model) |
| | | db.commit() |
| | | db.refresh(user_model) |
| | | u_id = user_model.id |
| | | user_app_dao = UserAppDao(db) |
| | | for k, v in register_dict.items(): |
| | | await user_app_dao.update_and_insert_data(v.get("name"), user_model.encrypted_password(v.get("pwd")), v.get("email"), u_id, str(v.get("id")), k) |
| | | except Exception as e: |
| | | print(e) |
| | | db.rollback() |