From 5986fc4dfa9a42dc6968df92fe17f542065ffafb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=8D=9A?= <1016318004@qq.com> Date: Thu, 20 Feb 2025 16:24:35 +0800 Subject: [PATCH 1/6] =?UTF-8?q?flow=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/manager/flow.py | 1 - apps/routers/flow.py | 1 + apps/routers/user.py | 1 + apps/scheduler/executor/flow.py | 14 +++++++------- 4 files changed, 9 insertions(+), 8 deletions(-) create mode 100644 apps/routers/user.py diff --git a/apps/manager/flow.py b/apps/manager/flow.py index d2b302a8..b748650e 100644 --- a/apps/manager/flow.py +++ b/apps/manager/flow.py @@ -111,7 +111,6 @@ class FlowManager: }, ] query = {"$or": match_conditions} - service_records_cursor = service_collection.find( query, sort=[("created_at", ASCENDING)], diff --git a/apps/routers/flow.py b/apps/routers/flow.py index 7ed4d5b8..c68d4815 100644 --- a/apps/routers/flow.py +++ b/apps/routers/flow.py @@ -34,6 +34,7 @@ async def get_services( ): """获取用户可访问的节点元数据所在服务的信息""" services = await FlowManager.get_service_by_user_id(user_sub) + print(services) if services is None: return NodeServiceListRsp( code=status.HTTP_404_NOT_FOUND, diff --git a/apps/routers/user.py b/apps/routers/user.py new file mode 100644 index 00000000..1187c5ab --- /dev/null +++ b/apps/routers/user.py @@ -0,0 +1 @@ +from apps.manager.user import User diff --git a/apps/scheduler/executor/flow.py b/apps/scheduler/executor/flow.py index c663ffde..97d9795e 100644 --- a/apps/scheduler/executor/flow.py +++ b/apps/scheduler/executor/flow.py @@ -8,7 +8,7 @@ from typing import Optional from apps.constants import LOGGER, MAX_SCHEDULER_HISTORY_SIZE from apps.entities.enum_var import StepStatus from apps.entities.flow import Step -from apps.entities.plugin import ( +from apps.entities.app import ( SysCallVars, SysExecVars, ) @@ -45,7 +45,7 @@ class Executor: raise ValueError(err) # 加载Flow信息 - flow, flow_data = Pool().get_flow(sysexec_vars.plugin_data.flow_id, sysexec_vars.plugin_data.plugin_id) + flow, flow_data = Pool().get_flow(sysexec_vars.app_data.flow_id, sysexec_vars.app_data.app_id) # Flow不合法,拒绝执行 if flow is None or flow_data is None: err = "Flow不合法!" @@ -73,10 +73,10 @@ class Executor: name=str(flow.name), description=str(flow.description), status=StepStatus.RUNNING, - plugin_id=str(sysexec_vars.plugin_data.plugin_id), + app_id=str(sysexec_vars.app_data.app_id), step_id="start", thought="", - slot_data=sysexec_vars.plugin_data.params, + slot_data=sysexec_vars.app_data.params, ) # 是否结束运行 self._stop = False @@ -114,7 +114,7 @@ class Executor: ) # 从Pool中获取对应的Call - call_data, call_cls = Pool().get_call(call_type, self.flow_state.plugin_id) + call_data, call_cls = Pool().get_call(call_type, self.flow_state.app_id) if call_data is None or call_cls is None: err = f"[FlowExecutor] 尝试执行工具{call_type}时发生错误:找不到该工具。\n{traceback.format_exc()}" LOGGER.error(err) @@ -137,7 +137,7 @@ class Executor: task_id=self._vars.task_id, session_id=self._vars.session_id, extra={ - "plugin_id": self.flow_state.plugin_id, + "app_id": self.flow_state.app_id, "flow_id": self.flow_state.name, }, history=history, @@ -172,7 +172,7 @@ class Executor: # 处理参数 remaining_schema, slot_data = await slot_processor.process( self.flow_state.slot_data, - self._vars.plugin_data.params, + self._vars.app_data.params, { "task_id": self._vars.task_id, "question": self._vars.question, -- Gitee From 3f5502850fd323418677ade5aacac73bc80e6cf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=8D=9A?= <1016318004@qq.com> Date: Thu, 20 Feb 2025 16:24:49 +0800 Subject: [PATCH 2/6] mock --- apps/routers/mock.py | 4 ++-- mock/make_data.py | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/routers/mock.py b/apps/routers/mock.py index 189ef0f8..5f7cb516 100644 --- a/apps/routers/mock.py +++ b/apps/routers/mock.py @@ -190,7 +190,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "8841e328-da5b-45c7-8839-5b8054a92de7", + "stepId": "d60a0fde-cd75-48ee-ba6c-b861b0a94f81", "stepName": "【CHOICE】判断任务类型", "stepStatus": "running", }, @@ -225,7 +225,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "8841e328-da5b-45c7-8839-5b8054a92de7", + "stepId": "d60a0fde-cd75-48ee-ba6c-b861b0a94f81", "stepName": "【CHOICE】判断任务类型", "stepStatus": "error", }, diff --git a/mock/make_data.py b/mock/make_data.py index 5b8aa075..18bfbbe0 100644 --- a/mock/make_data.py +++ b/mock/make_data.py @@ -54,14 +54,15 @@ class ServicePool(PoolBase): # } # MongoDB配置 config = { - "MONGODB_USER": "euler_copilot", - "MONGODB_PWD": "8URM%HtCHQPxKe$u", - "MONGODB_HOST": "10.43.208.180", - "MONGODB_PORT": "27017", - "MONGODB_DATABASE": "euler_copilot", + 'MONGODB_USER': 'euler_copilot', + 'MONGODB_PWD': 'ZYd0Z3SpcDifcgnt5EOK', + 'MONGODB_HOST': '10.43.188.157', + 'MONGODB_PORT': '27017', + 'MONGODB_DATABASE': 'euler_copilot' } + class MongoDB: _client = MongoClient( f"mongodb://{urllib.parse.quote_plus(config['MONGODB_USER'])}:{urllib.parse.quote_plus(config['MONGODB_PWD'])}@{config['MONGODB_HOST']}:{config['MONGODB_PORT']}/?directConnection=true", @@ -89,7 +90,7 @@ async def insert_service_pool(): author="test", api=[api_info_1, api_info_2, api_info_3], permissions=Permission(type=PermissionType.PUBLIC, users=["user1", "user2"]), - favorites=["user1", "test"], + favorites=["user1", "test","42497","53580"], hashes={"file1": "hash1", "file2": "hash2"}, ) aops_id = "1137ab09-20ae-4278-8346-524d4ce81d2f" @@ -100,7 +101,7 @@ async def insert_service_pool(): author="test", api=[api_info_1, api_info_2, api_info_3], permissions=Permission(type=PermissionType.PUBLIC, users=["user1", "user2"]), - favorites=["user1"], + favorites=["user1","42497","53580","test"], hashes={"file1": "hash1", "file2": "hash2"}, ) """插入ServicePool实例到MongoDB""" @@ -718,4 +719,4 @@ def query_all_target(tag: str): if __name__ == "__main__": asyncio.run(insert_service_pool()) asyncio.run(insert_node_pool()) - query_all_target("node") + query_all_target("service") -- Gitee From 5dfa16376b80bf3bda81a12f525ace6b405b628d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=8D=9A?= <1016318004@qq.com> Date: Thu, 20 Feb 2025 21:04:40 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0api/user=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/entities/response_data.py | 11 +++++++ apps/entities/user.py | 13 +++++++++ apps/routers/user.py | 52 +++++++++++++++++++++++++++++++++- 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 apps/entities/user.py diff --git a/apps/entities/response_data.py b/apps/entities/response_data.py index f7eff33b..4800d76e 100644 --- a/apps/entities/response_data.py +++ b/apps/entities/response_data.py @@ -17,6 +17,7 @@ from apps.entities.flow_topology import ( PositionItem, ) from apps.entities.record import RecordData +from apps.entities.user import UserInfo class ResponseData(BaseModel): @@ -464,3 +465,13 @@ class FlowStructureDeleteRsp(ResponseData): """DELETE /api/flow/ 返回数据结构""" result: FlowStructureDeleteMsg + +class UserGetMsp(BaseModel): + """GET /api/user result""" + + user_info_list : list[UserInfo] = Field(alias="userInfoList", default=[]) + +class UserGetRsp(ResponseData): + """GET /api/user 返回数据结构""" + + result: UserGetMsp diff --git a/apps/entities/user.py b/apps/entities/user.py new file mode 100644 index 00000000..c42e57ff --- /dev/null +++ b/apps/entities/user.py @@ -0,0 +1,13 @@ +"""User用户信息数据结构 + +Copyright (c) Huawei Technologies Co., Ltd. 2024-2025. All rights reserved. +""" + +from pydantic import BaseModel, Field + + +class UserInfo(BaseModel): + """用户信息数据结构""" + + user_sub: str = Field(alias="userSub", default="") + user_name: str = Field(alias="userName", default="") \ No newline at end of file diff --git a/apps/routers/user.py b/apps/routers/user.py index 1187c5ab..9413f5f3 100644 --- a/apps/routers/user.py +++ b/apps/routers/user.py @@ -1 +1,51 @@ -from apps.manager.user import User + +from typing import Annotated + +from fastapi import APIRouter, Depends, HTTPException, status +from fastapi.responses import JSONResponse, StreamingResponse + +from apps.common.queue import MessageQueue +from apps.common.wordscheck import WordsCheck +from apps.constants import LOGGER +from apps.dependency import ( + get_session, + get_user, + verify_csrf_token, + verify_user, +) +from apps.entities.request_data import RequestData +from apps.entities.response_data import ResponseData, UserGetMsp, UserGetRsp +from apps.entities.user import UserInfo +from apps.manager.appcenter import AppCenterManager +from apps.scheduler.scheduler import Scheduler +from apps.service.activity import Activity +from apps.manager.user import UserManager + +router = APIRouter( + prefix="/api/user", + tags=["user"], +) + +@router.get("", dependencies=[Depends(verify_csrf_token), Depends(verify_user)]) +async def chat( + user_sub: Annotated[str, Depends(get_user)], + session_id: Annotated[str, Depends(get_session)], +) -> JSONResponse: + """查询所有用户接口""" + user_list = await UserManager.get_all_user_sub() + user_info_list = [] + for user in user_list: + # user_info = await UserManager.get_userinfo_by_user_sub(user) 暂时不需要查询user_name + if user == user_sub: + continue + info = UserInfo( + userName=user, + userSub=user, + ) + user_info_list.append(info) + + return JSONResponse(status_code=status.HTTP_200_OK, content=UserGetRsp( + code=status.HTTP_200_OK, + message="节点元数据详细信息获取成功", + result=UserGetMsp(userInfoList=user_info_list), + ).model_dump(exclude_none=True, by_alias=True)) -- Gitee From 09b49f919806f9233f90f3cd7e86e04b7af426e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=8D=9A?= <1016318004@qq.com> Date: Fri, 21 Feb 2025 11:13:00 +0800 Subject: [PATCH 4/6] =?UTF-8?q?mock=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/routers/mock.py | 97 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/apps/routers/mock.py b/apps/routers/mock.py index 5f7cb516..d1271622 100644 --- a/apps/routers/mock.py +++ b/apps/routers/mock.py @@ -22,6 +22,7 @@ def mock_data(question): conversationId="eccb08c3-0621-4602-a4d2-4eaada892557" appId="68dd3d90-6a97-4da0-aa62-d38a81c7d2f5" flowId="966c7964-e1c1-4bd8-9333-ed099cf25908" + stepIds = ["node1","b7607efc-0dc7-4f7a-a2b2-dba60013b3b5","d60a0fde-cd75-48ee-ba6c-b861b0a94f81"] messages = [{ "event": "init", "id": "0f9d3e6b-7845-44ab-b247-35c522d38f13", @@ -51,7 +52,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId": flowId, - "stepId": "eccb08c3-a892-4602-b247-35c522d38f13", + "stepId": stepIds[0], "stepStatus": "pending", }, "content": { @@ -76,7 +77,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "node1", + "stepId": stepIds[0], "stepName": "开始", "stepStatus": "running", }, @@ -97,7 +98,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "node1", + "stepId": stepIds[0], "stepName": "开始", "stepStatus": "success", }, @@ -118,7 +119,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "b7607efc-0dc7-4f7a-a2b2-dba60013b3b5", + "stepId": stepIds[1], "stepName": "【API】获取任务简介", "stepStatus": "running", }, @@ -156,7 +157,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "b7607efc-0dc7-4f7a-a2b2-dba60013b3b5", + "stepId": stepIds[1], "stepName": "【API】获取任务简介", "stepStatus": "success", }, @@ -190,7 +191,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "d60a0fde-cd75-48ee-ba6c-b861b0a94f81", + "stepId": stepIds[2], "stepName": "【CHOICE】判断任务类型", "stepStatus": "running", }, @@ -225,7 +226,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "d60a0fde-cd75-48ee-ba6c-b861b0a94f81", + "stepId": stepIds[2], "stepName": "【CHOICE】判断任务类型", "stepStatus": "error", }, @@ -247,7 +248,7 @@ def mock_data(question): "flow": { "appId": appId, "flowId":flowId, - "stepId": "8841e328-da5b-45c7-8839-5b8054a92de7", + "stepId": stepIds[2], "stepName": "【CHOICE】判断任务类型", "stepStatus": "error", }, @@ -301,7 +302,7 @@ def mock_data(question): "conversationId": conversationId, "taskId": "eb717bc7-3435-4172-82d1-6b69e62f3fd6", "content": { - "text": "语句" + "text": "语句\n" }, "metadata": { "inputTokens": 200, @@ -309,7 +310,81 @@ def mock_data(question): "time": 0.5 } }, - + { + "event": "text.add", + "id": "0f9d3e6b-7845-44ab-b247-35c522d38f13-1", + "groupId": "8b9d3e6b-a892-4602-b247-35c522d38f13", + "conversationId": conversationId, + "taskId": "eb717bc7-3435-4172-82d1-6b69e62f3fd6", + "content": { + "text": "| Header1 | Header2 | Header3 |\n|---------|---------|---------|\n| Row1Col1| Row1Col2| Row1Col3|\n" + }, + "metadata": { + "inputTokens": 200, + "outputTokens": 50, + "time": 0.5 + } + }, + { + "event": "text.add", + "id": "0f9d3e6b-7845-44ab-b247-35c522d38f13-2", + "groupId": "8b9d3e6b-a892-4602-b247-35c522d38f13", + "conversationId": conversationId, + "taskId": "eb717bc7-3435-4172-82d1-6b69e62f3fd6", + "content": { + "text": "| Row2Col1| Row2Col2| Row2Col3|\n" + }, + "metadata": { + "inputTokens": 200, + "outputTokens": 50, + "time": 0.5 + } + }, + { + "event": "text.add", + "id": "0f9d3e6b-7845-44ab-b247-35c522d38f13-3", + "groupId": "8b9d3e6b-a892-4602-b247-35c522d38f13", + "conversationId": "conversationId", + "taskId": "eb717bc7-3435-4172-82d1-6b69e62f3fd6", + "content": { + "text": "| Row3Col1| Row3Col2| Row3Col3|\n" + }, + "metadata": { + "inputTokens": 200, + "outputTokens": 50, + "time": 0.5 + } + }, + { + "event": "text.add", + "id": "0f9d3e6b-7845-44ab-b247-35c522d38f13-4", + "groupId": "8b9d3e6b-a892-4602-b247-35c522d38f13", + "conversationId": conversationId, + "taskId": "eb717bc7-3435-4172-82d1-6b69e62f3fd6", + "content": { + "text": "| Row4Col1| Row4Col2| Row4Col3|\n" + }, + "metadata": { + "inputTokens": 200, + "outputTokens": 50, + "time": 0.5 + } + }, + { + "event": "text.add", + "id": "0f9d3e6b-7845-44ab-b247-35c522d38f13-5", + "groupId": "8b9d3e6b-a892-4602-b247-35c522d38f13", + "conversationId": conversationId, + "taskId": "eb717bc7-3435-4172-82d1-6b69e62f3fd6", + "content": { + "text": "| Row5Col1| Row5Col2| Row5Col3|\n" + }, + "metadata": { + "inputTokens": 200, + "outputTokens": 50, + "time": 0.5 + } + }, { "event": "text.stop", "id": "0f9d3e6b-7845-44ab-b247-35c522d38f13", @@ -331,7 +406,7 @@ def mock_data(question): import random for message in messages: if message['event']=='step.output': - t=random.uniform(1, 1.5) + t=random.uniform(3, 5.5) time.sleep(t) message['time_cost']=t elif message['event']=='text.add': -- Gitee From 39645629980654560569ccf79c2028b544f42d07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=8D=9A?= <1016318004@qq.com> Date: Fri, 21 Feb 2025 11:13:36 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=88=A0=E5=8E=BB=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/routers/flow.py | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/routers/flow.py b/apps/routers/flow.py index c68d4815..7ed4d5b8 100644 --- a/apps/routers/flow.py +++ b/apps/routers/flow.py @@ -34,7 +34,6 @@ async def get_services( ): """获取用户可访问的节点元数据所在服务的信息""" services = await FlowManager.get_service_by_user_id(user_sub) - print(services) if services is None: return NodeServiceListRsp( code=status.HTTP_404_NOT_FOUND, -- Gitee From 2a88d25367b51c2bde7b15261bd1856d30ba94ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=B9=E5=8D=9A?= <1016318004@qq.com> Date: Fri, 21 Feb 2025 11:14:44 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mock/make_data.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mock/make_data.py b/mock/make_data.py index 2f1b2aa7..a84c1203 100644 --- a/mock/make_data.py +++ b/mock/make_data.py @@ -51,11 +51,11 @@ class ServicePool(PoolBase): # MongoDB配置 config = { - 'MONGODB_USER': 'euler_copilot', - 'MONGODB_PWD': 'ZYd0Z3SpcDifcgnt5EOK', - 'MONGODB_HOST': '10.43.188.157', - 'MONGODB_PORT': '27017', - 'MONGODB_DATABASE': 'euler_copilot' + 'MONGODB_USER': '', + 'MONGODB_PWD': '', + 'MONGODB_HOST': '', + 'MONGODB_PORT': '', + 'MONGODB_DATABASE': '' } -- Gitee