From 955cf1e5bb540d6d11e389e6a0cb82e5821fc07e Mon Sep 17 00:00:00 2001 From: zxstty Date: Tue, 29 Apr 2025 09:29:33 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=9B=A2?= =?UTF-8?q?=E9=98=9F=E3=80=81=E8=BA=AB=E4=BB=BD=E3=80=81=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E5=92=8C=E5=87=86=E7=A1=AE=E7=8E=87=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_chain/apps/router/acc_testing.py | 99 +++++++++++++++++++++++ data_chain/apps/router/other.py | 47 ++++++----- data_chain/apps/router/role.py | 50 ++++++++++++ data_chain/apps/router/team.py | 111 ++++++++++++++++++++++++++ 4 files changed, 289 insertions(+), 18 deletions(-) create mode 100644 data_chain/apps/router/acc_testing.py create mode 100644 data_chain/apps/router/role.py create mode 100644 data_chain/apps/router/team.py diff --git a/data_chain/apps/router/acc_testing.py b/data_chain/apps/router/acc_testing.py new file mode 100644 index 0000000..f7a6c7c --- /dev/null +++ b/data_chain/apps/router/acc_testing.py @@ -0,0 +1,99 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. +from fastapi import APIRouter, Depends, Query, Body +from typing import Annotated +from uuid import UUID +from data_chain.entities.request_data import ( + ListTestingRequest, + CreateTestingRequest, + UpdateTestingRequest +) +from data_chain.entities.response_data import ( + ListTestingResponse, + ListTestCaseResponse, + CreateTestingResponsing, + RunTestingResponse, + UpdateTestingResponse, + DeleteTestingResponse +) +from data_chain.apps.service.session_service import get_user_sub, verify_user + +router = APIRouter(prefix='/testing', tags=['Testing']) + + +@router.get('', response_model=ListTestingResponse, dependencies=[Depends(verify_user)]) +async def list_testing_by_dataset_id( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListTestingRequest, Body()], +): + return ListTestingResponse() + + +@router.get('/testcase', response_model=ListTestCaseResponse, + dependencies=[Depends(verify_user)]) +async def list_test_case_by_testing_id( + user_sub: Annotated[str, Depends(get_user_sub)], + testing_id: Annotated[UUID, Query(alias="testingId")]): + return ListTestCaseResponse() + + +@router.get('/download', dependencies=[Depends(verify_user)]) +async def download_testing_report_by_testing_id( + user_sub: Annotated[str, Depends(get_user_sub)], + testing_id: Annotated[UUID, Query(alias="testingId")]): + # try: + # await _validate_doucument_belong_to_user(user_id, id) + # document_link_url = await generate_document_download_link(id) + # document_name, extension = await get_file_name_and_extension(id) + # async with AsyncClient() as async_client: + # response = await async_client.get(document_link_url) + # if response.status_code == 200: + # content_disposition = f"attachment; filename={urllib.parse.quote(document_name.encode('utf-8'))}" + + # async def stream_generator(): + # async for chunk in response.aiter_bytes(chunk_size=8192): + # yield chunk + + # return StreamingResponse(stream_generator(), headers={ + # "Content-Disposition": content_disposition, + # "Content-Length": str(response.headers.get('content-length')) + # }, media_type="application/" + extension) + # else: + # return BaseResponse( + # retcode=ErrorCode.EXPORT_KNOWLEDGE_BASE_ERROR, retmsg="Failed to retrieve the file.", data=None) + # except Exception as e: + # return BaseResponse(retcode=ErrorCode.DOWNLOAD_DOCUMENT_ERROR, retmsg=str(e.args[0]), data=None) + pass + + +@router.post( + '', response_model=CreateTestingResponsing, dependencies=[Depends(verify_user)]) +async def create_testing( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[CreateTestingRequest, Body()]): + return CreateTestingResponsing() + + +@router.post('/run', response_model=RunTestingResponse, + dependencies=[Depends(verify_user)]) +async def run_testing_by_testing_id( + user_sub: Annotated[str, Depends(get_user_sub)], + testing_id: Annotated[UUID, Query(alias="testingId")], + run: Annotated[bool, Query()]): + return RunTestingResponse() + + +@router.put('', response_model=UpdateTestingResponse, + dependencies=[Depends(verify_user)]) +async def update_testing_by_testing_id( + user_sub: Annotated[str, Depends(get_user_sub)], + testing_id: Annotated[UUID, Query(alias="testingId")], + req: Annotated[UpdateTestingRequest, Body(...)]): + return UpdateTestingResponse() + + +@router.delete('', response_model=DeleteTestingResponse, + dependencies=[Depends(verify_user)]) +async def delete_testing_by_testing_ids( + user_sub: Annotated[str, Depends(get_user_sub)], + testing_ids: Annotated[list[UUID], Query(alias="testingId")]): + return DeleteTestingResponse() diff --git a/data_chain/apps/router/other.py b/data_chain/apps/router/other.py index 70eb786..cb28731 100644 --- a/data_chain/apps/router/other.py +++ b/data_chain/apps/router/other.py @@ -1,26 +1,37 @@ -# Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. -from typing import List +# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. -from data_chain.apps.service.user_service import verify_csrf_token, get_user_id, verify_user -from data_chain.models.api import BaseResponse -from data_chain.models.constant import EmbeddingModelEnum, ParseMethodEnum +from fastapi import APIRouter, Depends, Query, Body +from typing import Annotated +from uuid import UUID +from data_chain.entities.enum import ParseMethod +from data_chain.entities.response_data import ( + ListLLMResponse, + ListEmbeddingResponse, + ListTokenizerResponse, + ListParserMethodResponse +) +from data_chain.apps.service.session_service import get_user_sub, verify_user -from fastapi import APIRouter -from fastapi import Depends +router = APIRouter(prefix='/other', tags=['Other']) -router = APIRouter(prefix='/other', tags=['Other Api']) +@router.get('/llm', response_model=ListLLMResponse, dependencies=[Depends(verify_user)]) +async def list_llms_by_user_sub( + user_sub: Annotated[str, Depends(get_user_sub)], +): + return ListLLMResponse() -@router.get('/embedding_model', response_model=BaseResponse[List[str]], - dependencies=[Depends(verify_user), - Depends(verify_csrf_token)]) -async def embedding_model(): - return BaseResponse(data=EmbeddingModelEnum.get_all_values()) +@router.get('/embedding', response_model=ListEmbeddingResponse, dependencies=[Depends(verify_user)]) +async def list_embeddings(): + return ListEmbeddingResponse() -@router.get('/parse_method', response_model=BaseResponse[List[str]], - dependencies=[Depends(verify_user), - Depends(verify_csrf_token)]) -async def parse_method(): - return BaseResponse(data=ParseMethodEnum.get_all_values()) +@router.get('/tokenizer', response_model=ListTokenizerResponse, dependencies=[Depends(verify_user)]) +async def list_tokenizers(): + return ListTokenizerResponse() + + +@router.get('parser_method', response_model=ListParserMethodResponse, dependencies=[Depends(verify_user)]) +async def list_parser_method(): + return ListParserMethodResponse() diff --git a/data_chain/apps/router/role.py b/data_chain/apps/router/role.py new file mode 100644 index 0000000..1d60593 --- /dev/null +++ b/data_chain/apps/router/role.py @@ -0,0 +1,50 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + +from fastapi import APIRouter, Depends, Query, Body +from typing import Annotated +from uuid import UUID +from data_chain.entities.request_data import ( + ListRoleRequest, + CreateRoleRequest, + UpdateRoleRequest +) + +from data_chain.entities.response_data import ( + ListRoleResponse, + CreateRoleResponse, + UpdateRoleResponse, + DeleteRoleResponse +) +from data_chain.apps.service.session_service import get_user_sub, verify_user + +router = APIRouter(prefix='/role', tags=['Role']) + + +@router.get('', response_model=ListRoleResponse, dependencies=[Depends(verify_user)]) +async def list_role_by_team_id( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListRoleRequest, Body()], +): + return ListRoleResponse() + + +@router.post('', response_model=CreateRoleResponse, dependencies=[Depends(verify_user)]) +async def create_role(user_sub: Annotated[str, Depends(get_user_sub)], + team_id: Annotated[UUID, Query(alias="TeamId")], + req: Annotated[CreateRoleRequest, Body()]): + return CreateRoleResponse() + + +@router.put('', response_model=UpdateRoleResponse, dependencies=[Depends(verify_user)]) +async def update_role_by_role_id( + user_sub: Annotated[str, Depends(get_user_sub)], + role_id: Annotated[UUID, Query(alias="roleId")], + req: Annotated[UpdateRoleRequest, Body()]): + return UpdateRoleResponse() + + +@router.delete('', response_model=DeleteRoleResponse, dependencies=[Depends(verify_user)]) +async def delete_role_by_role_ids( + user_sub: Annotated[str, Depends(get_user_sub)], + role_ids: Annotated[list[UUID], Query(alias="roleId")]): + return DeleteRoleResponse() diff --git a/data_chain/apps/router/team.py b/data_chain/apps/router/team.py new file mode 100644 index 0000000..4f4a62f --- /dev/null +++ b/data_chain/apps/router/team.py @@ -0,0 +1,111 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. + +from fastapi import APIRouter, Depends, Query, Body +from typing import Annotated +from uuid import UUID +from data_chain.entities.request_data import ( + ListTeamRequest, + ListTeamMsgRequest, + ListTeamUserRequest, + CreateTeamRequest, + UpdateTeamRequest, +) + +from data_chain.entities.response_data import ( + ListTeamResponse, + ListTeamMsgResponse, + ListTeamUserResponse, + CreateTeamResponse, + UpdateTeamResponse, + DeleteTeamResponse, + UpdateTeamUserRoleResponse, + UpdateTeamAuthorResponse, + DeleteTeamUserResponse, + JoinTeamResponse, + InviteTeamUserResponse +) +from data_chain.apps.service.session_service import get_user_sub, verify_user + +router = APIRouter(prefix='/team', tags=['Team']) + + +@router.get('', response_model=ListTeamResponse, dependencies=[Depends(verify_user)]) +async def list_teams( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListTeamRequest, Body()] +): + return ListTeamResponse() + + +@router.get('/usr', response_model=ListTeamUserResponse, dependencies=[Depends(verify_user)]) +async def list_team_user_by_team_id( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListTeamUserRequest, Body()]): + return ListTeamUserResponse() + + +@router.get('/msg', response_model=ListTeamMsgResponse, dependencies=[Depends(verify_user)]) +async def list_team_msg_by_team_id( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListTeamMsgRequest, Body()]): + return ListTeamMsgResponse() + + +@router.post('', response_model=CreateTeamResponse, dependencies=[Depends(verify_user)]) +async def create_team(user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[CreateTeamRequest, Body()]): + return CreateTeamResponse() + + +@router.post('/invitation', response_model=InviteTeamUserResponse, dependencies=[Depends(verify_user)]) +async def invite_team_user_by_user_sub( + user_sub: Annotated[str, Depends(get_user_sub)], + team_id: Annotated[UUID, Query(alias="teamId")], + user_sub_invite: Annotated[str, Query(alias="userSubInvite")]): + return InviteTeamUserResponse() + + +@router.post('/application', response_model=JoinTeamResponse, dependencies=[Depends(verify_user)]) +async def join_team( + user_sub: Annotated[str, Depends(get_user_sub)], + team_id: Annotated[UUID, Query(alias="teamId")]): + return JoinTeamResponse() + + +@router.put('', response_model=UpdateTeamResponse, dependencies=[Depends(verify_user)]) +async def update_team_by_team_id( + user_sub: Annotated[str, Depends(get_user_sub)], + team_id: Annotated[UUID, Query(alias="teamId")], + req: Annotated[UpdateTeamRequest, Body()]): + return UpdateTeamResponse() + + +@router.put('/usr', response_model=UpdateTeamUserRoleResponse, dependencies=[Depends(verify_user)]) +async def update_team_by_team_id( + user_sub: Annotated[str, Depends(get_user_sub)], + team_id: Annotated[UUID, Query(alias="teamId")], + role_id: Annotated[UUID, Query(alias="roleId")]): + return UpdateTeamUserRoleResponse() + + +@router.put('/author', response_model=UpdateTeamAuthorResponse, dependencies=[Depends(verify_user)]) +async def update_team_author_by_team_id( + user_sub: Annotated[str, Depends(get_user_sub)], + recriver_sub: Annotated[str, Query(alias="recriverSub")], + team_id: Annotated[UUID, Query(alias="teamId")]): + return UpdateTeamAuthorResponse() + + +@router.delete('', response_model=DeleteTeamResponse, dependencies=[Depends(verify_user)]) +async def delete_team_by_team_id( + user_sub: Annotated[str, Depends(get_user_sub)], + team_id: Annotated[UUID, Query(alias="teamId")]): + return DeleteTeamResponse() + + +@router.delete('/usr', response_model=DeleteTeamUserResponse, dependencies=[Depends(verify_user)]) +async def delete_team_user_by_team_id_and_user_subs( + user_sub: Annotated[str, Depends(get_user_sub)], + team_id: Annotated[UUID, Query(alias="teamId")], + user_subs: Annotated[list[str], Query(alias="userSub")]): + return DeleteTeamUserResponse() -- Gitee From 28f956ee2e59ea7317f3822855a574c61a5a7e15 Mon Sep 17 00:00:00 2001 From: zxstty Date: Tue, 29 Apr 2025 09:34:29 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E3=80=81=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E3=80=81=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_chain/apps/router/dataset.py | 110 ++++++++++++++++++++++++++ data_chain/apps/router/task.py | 41 ++++++++++ data_chain/apps/router/usr_message.py | 37 +++++++++ 3 files changed, 188 insertions(+) create mode 100644 data_chain/apps/router/dataset.py create mode 100644 data_chain/apps/router/task.py create mode 100644 data_chain/apps/router/usr_message.py diff --git a/data_chain/apps/router/dataset.py b/data_chain/apps/router/dataset.py new file mode 100644 index 0000000..6ee2461 --- /dev/null +++ b/data_chain/apps/router/dataset.py @@ -0,0 +1,110 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. +from fastapi import APIRouter, Depends, Query, Body, File, UploadFile +from typing import Annotated +from uuid import UUID +from data_chain.entities.request_data import ( + ListDatasetRequest, + ListDataInDatasetRequest, + CreateDatasetRequest, + UpdateDatasetRequest, +) + +from data_chain.entities.response_data import ( + ListDatasetResponse, + ListDataInDatasetResponse, + CreateDatasetResponse, + ImportDatasetResponse, + ExportDatasetResponse, + GenerateDatasetResponse, + UpdateDatasetResponse, + DeleteDatasetResponse, +) +from data_chain.apps.service.session_service import get_user_sub, verify_user + +router = APIRouter(prefix='/dataset', tags=['Dataset']) + + +@router.get('', response_model=ListDatasetResponse, dependencies=[Depends(verify_user)]) +async def list_datasets_by_kb_id( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListDatasetRequest, Body()], +): + return ListDatasetResponse() + + +@router.get('/data', response_model=ListDataInDatasetResponse, dependencies=[Depends(verify_user)]) +async def list_data_in_dataset_by_dataset_id( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListDataInDatasetRequest, Body()]): + return ListDataInDatasetResponse() + + +@router.get('/download', dependencies=[Depends(verify_user)]) +async def download_dataset_by_task_id( + user_sub: Annotated[str, Depends(get_user_sub)], + task_id: Annotated[UUID, Query(alias="taskId")]): + # try: + # await _validate_doucument_belong_to_user(user_id, id) + # document_link_url = await generate_document_download_link(id) + # document_name, extension = await get_file_name_and_extension(id) + # async with AsyncClient() as async_client: + # response = await async_client.get(document_link_url) + # if response.status_code == 200: + # content_disposition = f"attachment; filename={urllib.parse.quote(document_name.encode('utf-8'))}" + + # async def stream_generator(): + # async for chunk in response.aiter_bytes(chunk_size=8192): + # yield chunk + + # return StreamingResponse(stream_generator(), headers={ + # "Content-Disposition": content_disposition, + # "Content-Length": str(response.headers.get('content-length')) + # }, media_type="application/" + extension) + # else: + # return BaseResponse( + # retcode=ErrorCode.EXPORT_KNOWLEDGE_BASE_ERROR, retmsg="Failed to retrieve the file.", data=None) + # except Exception as e: + # return BaseResponse(retcode=ErrorCode.DOWNLOAD_DOCUMENT_ERROR, retmsg=str(e.args[0]), data=None) + pass + + +@router.post('', response_model=CreateDatasetResponse, dependencies=[Depends(verify_user)]) +async def create_dataset(user_sub: Annotated[str, Depends(get_user_sub)], req: Annotated[CreateDatasetRequest, Body()]): + return CreateDatasetResponse() + + +@router.post('/import', response_model=ImportDatasetResponse, dependencies=[Depends(verify_user)]) +async def import_dataset(user_sub: Annotated[str, Depends(get_user_sub)], + kb_id: Annotated[UUID, Query(alias="kbId")], + dataset_packages: list[UploadFile] = File(...)): + return ImportDatasetResponse() + + +@router.post('/export', response_model=ExportDatasetResponse, dependencies=[Depends(verify_user)]) +async def export_dataset_by_dataset_ids( + user_sub: Annotated[str, Depends(get_user_sub)], + dataset_ids: Annotated[list[UUID], Query(alias="datasetIds")]): + return ExportDatasetResponse() + + +@router.post('/generate', response_model=GenerateDatasetResponse, dependencies=[Depends(verify_user)]) +async def generate_dataset_by_id( + user_sub: Annotated[str, Depends(get_user_sub)], + dataset_id: Annotated[UUID, Query(alias="datasetId")], + generate: Annotated[bool, Query()]): + return GenerateDatasetResponse() + + +@router.put('', response_model=UpdateDatasetResponse, dependencies=[Depends(verify_user)]) +async def update_dataset_by_dataset_id( + user_sub: Annotated[str, Depends(get_user_sub)], + database_id: Annotated[UUID, Query(alias="databaseId")], + req: Annotated[UpdateDatasetRequest, Body(...)]): + return UpdateDatasetResponse() + + +@router.delete('', response_model=DeleteDatasetResponse, dependencies=[Depends(verify_user)]) +async def delete_dataset_by_dataset_ids( + user_sub: Annotated[str, Depends(get_user_sub)], + database_id: Annotated[UUID, Query(alias="databaseId")]): + return DeleteDatasetResponse() diff --git a/data_chain/apps/router/task.py b/data_chain/apps/router/task.py new file mode 100644 index 0000000..ae3260c --- /dev/null +++ b/data_chain/apps/router/task.py @@ -0,0 +1,41 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2023-2025. All rights reserved. +from data_chain.apps.service.session_service import get_user_sub, verify_user +from fastapi import APIRouter, Depends, Query, Body +from typing import Annotated +from uuid import UUID +from data_chain.entities.request_data import ( + ListTaskRequest +) + +from data_chain.entities.response_data import ( + ListTaskResponse, + GetTaskReportResponse, + DeleteTaskResponse +) +from data_chain.entities.enum import TaskType +router = APIRouter(prefix='/task', tags=['Task']) + + +@router.get('', response_model=ListTaskResponse, dependencies=[Depends(verify_user)]) +async def list_task( + user_sub: Annotated[str, Depends(get_user_sub)], + req: Annotated[ListTaskRequest, Body()] +): + return ListTaskResponse() + + +@router.get('/report', response_model=GetTaskReportResponse, dependencies=[Depends(verify_user)]) +async def get_task_report_by_task_id( + user_sub: Annotated[str, Depends(get_user_sub)], + task_id: Annotated[UUID, Query(alias="taskId")], +): + return GetTaskReportResponse() + + +@router.delete('', response_model=DeleteTaskResponse, dependencies=[Depends(verify_user)]) +async def delete_task_by_task_ids_or_task_type( + user_sub: Annotated[str, Depends(get_user_sub)], + task_type: Annotated[TaskType, Query(alias="taskType")], + task_ids: Annotated[list[UUID], Query(alias="taskId")], +): + return DeleteTaskResponse() diff --git a/data_chain/apps/router/usr_message.py b/data_chain/apps/router/usr_message.py new file mode 100644 index 0000000..9c76316 --- /dev/null +++ b/data_chain/apps/router/usr_message.py @@ -0,0 +1,37 @@ +# Copyright (c) Huawei Technologies Co., Ltd. 2023-2024. All rights reserved. + +from fastapi import APIRouter, Depends, Query, Body +from typing import Annotated +from uuid import UUID +from data_chain.entities.enum import UserMessageType, UserStatus +from data_chain.entities.response_data import ( + ListUserMessageResponse, + UpdateUserMessageResponse, + DeleteUserMessageResponse +) +from data_chain.apps.service.session_service import get_user_sub, verify_user + +router = APIRouter(prefix='/usr_msg', tags=['User Message']) + + +@router.get('', response_model=ListUserMessageResponse, dependencies=[Depends(verify_user)]) +async def list_user_msgs_by_user_sub( + user_sub: Annotated[str, Depends(get_user_sub)], + msg_type: Annotated[UserMessageType, Query(alias="msgType")], +): + return ListUserMessageResponse() + + +@router.put('', response_model=UpdateUserMessageResponse, dependencies=[Depends(verify_user)]) +async def update_user_msg_by_msg_id( + user_sub: Annotated[str, Depends(get_user_sub)], + msg_id: Annotated[UUID, Query(alias="msgId")], + msg_status: Annotated[UserStatus, Query(alias="msgStatus")]): + return UpdateUserMessageResponse() + + +@router.delete('', response_model=DeleteUserMessageResponse, dependencies=[Depends(verify_user)]) +async def delete_user_msg_by_msg_ids( + user_sub: Annotated[str, Depends(get_user_sub)], + msg_ids: Annotated[list[UUID], Query(alias="msgId")]): + return DeleteUserMessageResponse() -- Gitee