From 823f4b7ad11622e44202cc8c738f1dfa438809e1 Mon Sep 17 00:00:00 2001 From: Archer <545436317@qq.com> Date: Thu, 21 Sep 2023 14:49:56 +0800 Subject: [PATCH] Optimize the structure and naming of projects (#335) --- client/src/api/core/dataset/data.d.ts | 26 ++ client/src/api/core/dataset/data.ts | 72 +++++ client/src/api/core/dataset/file.ts | 7 +- client/src/api/core/dataset/index.d.ts | 34 +++ client/src/api/core/dataset/index.ts | 32 +++ client/src/api/plugins/kb.ts | 106 ------- client/src/api/request/kb.d.ts | 24 -- client/src/components/APIKeyModal/index.tsx | 3 +- client/src/components/ChatBox/QuoteModal.tsx | 8 +- .../src/components/ChatBox/SelectDataset.tsx | 2 +- client/src/components/ChatBox/index.tsx | 12 +- client/src/components/Language/index.tsx | 2 +- client/src/components/Markdown/CodeLight.tsx | 2 +- client/src/components/Markdown/chat/Quote.tsx | 2 +- .../components/core/dataset/SelectModal.tsx | 8 +- client/src/constants/{kb.ts => dataset.ts} | 4 +- client/src/hooks/useCopyData.tsx | 39 +++ client/src/pages/_app.tsx | 7 +- client/src/pages/_error.tsx | 2 +- client/src/pages/account/components/Info.tsx | 4 +- .../pages/account/components/Promotion.tsx | 2 +- client/src/pages/account/index.tsx | 2 +- client/src/pages/api/admin/initv44.ts | 2 +- .../kb => core/dataset}/allDataset.ts | 4 +- .../{plugins/kb => core/dataset}/create.ts | 4 +- .../kb => core/dataset/data}/delDataById.ts | 0 .../kb => core/dataset}/data/exportAll.ts | 0 .../kb => core/dataset}/data/getDataById.ts | 4 +- .../kb => core/dataset}/data/getDataList.ts | 6 +- .../kb => core/dataset}/data/getQueueLen.ts | 0 .../dataset}/data/getTrainingData.ts | 0 .../kb => core/dataset}/data/insertData.ts | 10 +- .../kb => core/dataset/data}/pushData.ts | 24 +- .../kb => core/dataset/data}/updateData.ts | 12 +- .../{plugins/kb => core/dataset}/delete.ts | 0 .../{plugins/kb => core/dataset}/detail.ts | 0 .../pages/api/core/dataset/file/delById.ts | 2 +- .../src/pages/api/core/dataset/file/detail.ts | 8 +- .../src/pages/api/core/dataset/file/list.ts | 2 +- .../api/{plugins/kb => core/dataset}/list.ts | 6 +- .../api/{plugins/kb => core/dataset}/paths.ts | 6 +- .../kb => core/dataset}/searchTest.ts | 14 +- .../{plugins/kb => core/dataset}/update.ts | 4 +- .../src/pages/app/detail/components/API.tsx | 2 +- .../AdEdit/components/Nodes/NodeKbSearch.tsx | 10 +- .../app/detail/components/AdEdit/index.tsx | 2 +- .../app/detail/components/BasicEdit/index.tsx | 6 +- ...SelectModal.tsx => DatasetSelectModal.tsx} | 22 +- .../pages/app/detail/components/InfoModal.tsx | 2 +- .../pages/app/detail/components/OutLink.tsx | 3 +- client/src/pages/app/detail/index.tsx | 2 +- .../pages/app/list/component/CreateModal.tsx | 2 +- client/src/pages/app/list/index.tsx | 2 +- client/src/pages/appStore/index.tsx | 2 +- client/src/pages/chat/index.tsx | 2 +- client/src/pages/chat/share.tsx | 2 +- client/src/pages/index.tsx | 46 +-- .../pages/kb/detail/components/DataCard.tsx | 14 +- .../pages/kb/detail/components/FileCard.tsx | 13 +- .../kb/detail/components/Import/Chunk.tsx | 26 +- .../pages/kb/detail/components/Import/Csv.tsx | 26 +- .../detail/components/Import/FileSelect.tsx | 16 +- .../kb/detail/components/Import/Manual.tsx | 4 +- .../pages/kb/detail/components/Import/QA.tsx | 28 +- .../src/pages/kb/detail/components/Info.tsx | 14 +- .../kb/detail/components/InputDataModal.tsx | 18 +- .../src/pages/kb/detail/components/Test.tsx | 11 +- client/src/pages/kb/detail/index.tsx | 8 +- .../pages/kb/list/component/CreateModal.tsx | 12 +- .../kb/list/component/EditFolderModal.tsx | 8 +- .../src/pages/kb/list/component/MoveModal.tsx | 11 +- client/src/pages/kb/list/index.tsx | 15 +- client/src/pages/login/index.tsx | 2 +- client/src/pages/login/provider.tsx | 2 +- client/src/pages/tools/index.tsx | 2 +- client/src/service/events/generateQA.ts | 2 +- client/src/service/events/generateVector.ts | 4 +- client/src/service/lib/gridfs.ts | 4 +- client/src/service/models/kb.ts | 2 +- .../src/service/moduleDispatch/kb/search.ts | 4 +- client/src/service/pg.ts | 8 +- client/src/store/dataset.ts | 38 +-- client/src/types/chat.d.ts | 4 +- client/src/types/common/file.d.ts | 8 + client/src/types/core/dataset/data.d.ts | 9 + client/src/types/core/dataset/file.d.ts | 10 + client/src/types/core/dataset/index.d.ts | 32 +++ client/src/types/mongoSchema.d.ts | 2 +- client/src/types/plugin.d.ts | 61 ---- client/src/utils/app.ts | 4 +- client/src/utils/common/file/index.tsx | 7 - client/src/utils/file.ts | 256 ----------------- client/src/utils/tools.ts | 68 ----- client/src/utils/web/core/dataset.ts | 48 ++++ client/src/utils/web/file.ts | 261 ++++++++++++++++++ client/src/utils/{ => web}/i18n.ts | 0 client/src/utils/web/voice.ts | 28 ++ 97 files changed, 882 insertions(+), 821 deletions(-) create mode 100644 client/src/api/core/dataset/data.d.ts create mode 100644 client/src/api/core/dataset/data.ts create mode 100644 client/src/api/core/dataset/index.d.ts create mode 100644 client/src/api/core/dataset/index.ts delete mode 100644 client/src/api/plugins/kb.ts delete mode 100644 client/src/api/request/kb.d.ts rename client/src/constants/{kb.ts => dataset.ts} (84%) create mode 100644 client/src/hooks/useCopyData.tsx rename client/src/pages/api/{plugins/kb => core/dataset}/allDataset.ts (88%) rename client/src/pages/api/{plugins/kb => core/dataset}/create.ts (88%) rename client/src/pages/api/{openapi/kb => core/dataset/data}/delDataById.ts (100%) rename client/src/pages/api/{plugins/kb => core/dataset}/data/exportAll.ts (100%) rename client/src/pages/api/{plugins/kb => core/dataset}/data/getDataById.ts (89%) rename client/src/pages/api/{plugins/kb => core/dataset}/data/getDataList.ts (91%) rename client/src/pages/api/{plugins/kb => core/dataset}/data/getQueueLen.ts (100%) rename client/src/pages/api/{plugins/kb => core/dataset}/data/getTrainingData.ts (100%) rename client/src/pages/api/{plugins/kb => core/dataset}/data/insertData.ts (88%) rename client/src/pages/api/{openapi/kb => core/dataset/data}/pushData.ts (90%) rename client/src/pages/api/{openapi/kb => core/dataset/data}/updateData.ts (88%) rename client/src/pages/api/{plugins/kb => core/dataset}/delete.ts (100%) rename client/src/pages/api/{plugins/kb => core/dataset}/detail.ts (100%) rename client/src/pages/api/{plugins/kb => core/dataset}/list.ts (87%) rename client/src/pages/api/{plugins/kb => core/dataset}/paths.ts (79%) rename client/src/pages/api/{openapi/kb => core/dataset}/searchTest.ts (83%) rename client/src/pages/api/{plugins/kb => core/dataset}/update.ts (86%) rename client/src/pages/app/detail/components/{KBSelectModal.tsx => DatasetSelectModal.tsx} (94%) create mode 100644 client/src/types/common/file.d.ts create mode 100644 client/src/types/core/dataset/data.d.ts create mode 100644 client/src/types/core/dataset/file.d.ts create mode 100644 client/src/types/core/dataset/index.d.ts delete mode 100644 client/src/utils/common/file/index.tsx create mode 100644 client/src/utils/web/core/dataset.ts create mode 100644 client/src/utils/web/file.ts rename client/src/utils/{ => web}/i18n.ts (100%) create mode 100644 client/src/utils/web/voice.ts diff --git a/client/src/api/core/dataset/data.d.ts b/client/src/api/core/dataset/data.d.ts new file mode 100644 index 00000000000..f0ed21cd463 --- /dev/null +++ b/client/src/api/core/dataset/data.d.ts @@ -0,0 +1,26 @@ +import { KbTypeEnum } from '@/constants/dataset'; +import type { RequestPaging } from '@/types'; +import { TrainingModeEnum } from '@/constants/plugin'; + +export type PushDataProps = { + kbId: string; + data: DatasetItemType[]; + mode: `${TrainingModeEnum}`; + prompt?: string; +}; +export type PushDataResponse = { + insertLen: number; +}; + +export type UpdateDataPrams = { + dataId: string; + kbId: string; + a?: string; + q?: string; +}; + +export type GetDatasetDataListProps = RequestPaging & { + kbId: string; + searchText: string; + fileId: string; +}; diff --git a/client/src/api/core/dataset/data.ts b/client/src/api/core/dataset/data.ts new file mode 100644 index 00000000000..e7b082fc920 --- /dev/null +++ b/client/src/api/core/dataset/data.ts @@ -0,0 +1,72 @@ +import { GET, POST, PUT, DELETE } from '@/api/request'; +import type { DatasetDataItemType } from '@/types/core/dataset/data'; +import type { + PushDataProps, + PushDataResponse, + UpdateDataPrams, + GetDatasetDataListProps +} from './data.d'; +import { QuoteItemType } from '@/types/chat'; +import { getToken } from '@/utils/user'; +import download from 'downloadjs'; + +/* kb data */ +export const getDatasetDataList = (data: GetDatasetDataListProps) => + POST(`/core/dataset/data/getDataList`, data); + +/** + * export and download data + */ +export const exportDatasetData = (data: { kbId: string }) => + fetch(`/api/core/dataset/data/exportAll?kbId=${data.kbId}`, { + method: 'GET', + headers: { + token: getToken() + } + }) + .then(async (res) => { + if (!res.ok) { + const data = await res.json(); + throw new Error(data?.message || 'Export failed'); + } + return res.blob(); + }) + .then((blob) => download(blob, 'dataset.csv', 'text/csv')); + +/** + * 获取模型正在拆分数据的数量 + */ +export const getTrainingData = (data: { kbId: string; init: boolean }) => + POST<{ + qaListLen: number; + vectorListLen: number; + }>(`/core/dataset/data/getTrainingData`, data); + +/* get length of system training queue */ +export const getTrainingQueueLen = () => GET(`/core/dataset/data/getQueueLen`); + +export const getDatasetDataItemById = (dataId: string) => + GET(`/core/dataset/data/getDataById`, { dataId }); + +/** + * push data to training queue + */ +export const postChunks2Dataset = (data: PushDataProps) => + POST(`/core/dataset/data/pushData`, data); + +/** + * insert one data to dataset (immediately insert) + */ +export const postData2Dataset = (data: { kbId: string; data: DatasetDataItemType }) => + POST(`/core/dataset/data/insertData`, data); + +/** + * 更新一条数据 + */ +export const putDatasetDataById = (data: UpdateDataPrams) => + PUT('/core/dataset/data/updateData', data); +/** + * 删除一条知识库数据 + */ +export const delOneDatasetDataById = (dataId: string) => + DELETE(`/core/dataset/data/delDataById?dataId=${dataId}`); diff --git a/client/src/api/core/dataset/file.ts b/client/src/api/core/dataset/file.ts index 6198ebf203f..6dacafb2cd8 100644 --- a/client/src/api/core/dataset/file.ts +++ b/client/src/api/core/dataset/file.ts @@ -1,14 +1,15 @@ import { GET, POST, PUT, DELETE } from '@/api/request'; -import type { FileInfo, KbFileItemType } from '@/types/plugin'; +import type { DatasetFileItemType } from '@/types/core/dataset/file'; +import type { GSFileInfoType } from '@/types/common/file'; import type { GetFileListProps, UpdateFileProps } from './file.d'; export const getDatasetFiles = (data: GetFileListProps) => - POST(`/core/dataset/file/list`, data); + POST(`/core/dataset/file/list`, data); export const delDatasetFileById = (params: { fileId: string; kbId: string }) => DELETE(`/core/dataset/file/delById`, params); export const getFileInfoById = (fileId: string) => - GET(`/core/dataset/file/detail`, { fileId }); + GET(`/core/dataset/file/detail`, { fileId }); export const delDatasetEmptyFiles = (kbId: string) => DELETE(`/core/dataset/file/delEmptyFiles`, { kbId }); diff --git a/client/src/api/core/dataset/index.d.ts b/client/src/api/core/dataset/index.d.ts new file mode 100644 index 00000000000..f007b4f1c35 --- /dev/null +++ b/client/src/api/core/dataset/index.d.ts @@ -0,0 +1,34 @@ +import { KbTypeEnum } from '@/constants/dataset'; +import type { RequestPaging } from '@/types'; +import { TrainingModeEnum } from '@/constants/plugin'; +import type { SearchTestItemType } from '@/types/core/dataset'; + +export type DatasetUpdateParams = { + id: string; + parentId?: string; + tags?: string; + name?: string; + avatar?: string; +}; +export type CreateDatasetParams = { + parentId?: string; + name: string; + tags: string[]; + avatar: string; + vectorModel?: string; + type: `${KbTypeEnum}`; +}; + +export type DatasetUpdateParams = { + id: string; + parentId?: string; + tags?: string; + name?: string; + avatar?: string; +}; + +export type SearchTestProps = { + kbId: string; + text: string; +}; +export type SearchTestResponseType = SearchTestItemType['results']; diff --git a/client/src/api/core/dataset/index.ts b/client/src/api/core/dataset/index.ts new file mode 100644 index 00000000000..ea24458c195 --- /dev/null +++ b/client/src/api/core/dataset/index.ts @@ -0,0 +1,32 @@ +import { GET, POST, PUT, DELETE } from '@/api/request'; +import type { DatasetItemType, DatasetsItemType, DatasetPathItemType } from '@/types/core/dataset'; +import type { + DatasetUpdateParams, + CreateDatasetParams, + SearchTestProps, + SearchTestResponseType +} from './index.d'; +import { KbTypeEnum } from '@/constants/dataset'; + +export const getDatasets = (data: { parentId?: string; type?: `${KbTypeEnum}` }) => + GET(`/core/dataset/list`, data); + +/** + * get type=dataset list + */ +export const getAllDataset = () => GET(`/core/dataset/allDataset`); + +export const getDatasetPaths = (parentId?: string) => + GET('/core/dataset/paths', { parentId }); + +export const getDatasetById = (id: string) => GET(`/core/dataset/detail?id=${id}`); + +export const postCreateDataset = (data: CreateDatasetParams) => + POST(`/core/dataset/create`, data); + +export const putDatasetById = (data: DatasetUpdateParams) => PUT(`/core/dataset/update`, data); + +export const delDatasetById = (id: string) => DELETE(`/core/dataset/delete?id=${id}`); + +export const postSearchText = (data: SearchTestProps) => + POST(`/core/dataset/searchTest`, data); diff --git a/client/src/api/plugins/kb.ts b/client/src/api/plugins/kb.ts deleted file mode 100644 index f92e741ec28..00000000000 --- a/client/src/api/plugins/kb.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { GET, POST, PUT, DELETE } from '../request'; -import type { DatasetItemType, KbItemType, KbListItemType, KbPathItemType } from '@/types/plugin'; -import { TrainingModeEnum } from '@/constants/plugin'; -import { - Props as PushDataProps, - Response as PushDateResponse -} from '@/pages/api/openapi/kb/pushData'; -import { - Props as SearchTestProps, - Response as SearchTestResponse -} from '@/pages/api/openapi/kb/searchTest'; -import { Props as UpdateDataProps } from '@/pages/api/openapi/kb/updateData'; -import type { KbUpdateParams, CreateKbParams, GetKbDataListProps } from '../request/kb'; -import { QuoteItemType } from '@/types/chat'; -import { KbTypeEnum } from '@/constants/kb'; -import { getToken } from '@/utils/user'; -import download from 'downloadjs'; - -/* knowledge base */ -export const getKbList = (data: { parentId?: string; type?: `${KbTypeEnum}` }) => - GET(`/plugins/kb/list`, data); -export const getAllDataset = () => GET(`/plugins/kb/allDataset`); - -export const getKbPaths = (parentId?: string) => - GET('/plugins/kb/paths', { parentId }); - -export const getKbById = (id: string) => GET(`/plugins/kb/detail?id=${id}`); - -export const postCreateKb = (data: CreateKbParams) => POST(`/plugins/kb/create`, data); - -export const putKbById = (data: KbUpdateParams) => PUT(`/plugins/kb/update`, data); - -export const delKbById = (id: string) => DELETE(`/plugins/kb/delete?id=${id}`); - -/* kb data */ -export const getKbDataList = (data: GetKbDataListProps) => - POST(`/plugins/kb/data/getDataList`, data); - -/** - * export and download data - */ -export const exportDataset = (data: { kbId: string }) => - fetch(`/api/plugins/kb/data/exportAll?kbId=${data.kbId}`, { - method: 'GET', - headers: { - token: getToken() - } - }) - .then(async (res) => { - if (!res.ok) { - const data = await res.json(); - throw new Error(data?.message || 'Export failed'); - } - return res.blob(); - }) - .then((blob) => download(blob, 'dataset.csv', 'text/csv')); - -/** - * 获取模型正在拆分数据的数量 - */ -export const getTrainingData = (data: { kbId: string; init: boolean }) => - POST<{ - qaListLen: number; - vectorListLen: number; - }>(`/plugins/kb/data/getTrainingData`, data); - -/* get length of system training queue */ -export const getTrainingQueueLen = () => GET(`/plugins/kb/data/getQueueLen`); - -export const getKbDataItemById = (dataId: string) => - GET(`/plugins/kb/data/getDataById`, { dataId }); - -/** - * 直接push数据 - */ -export const postKbDataFromList = (data: PushDataProps) => - POST(`/openapi/kb/pushData`, data); - -/** - * insert one data to dataset - */ -export const insertData2Kb = (data: { kbId: string; data: DatasetItemType }) => - POST(`/plugins/kb/data/insertData`, data); - -/** - * 更新一条数据 - */ -export const putKbDataById = (data: UpdateDataProps) => PUT('/openapi/kb/updateData', data); -/** - * 删除一条知识库数据 - */ -export const delOneKbDataByDataId = (dataId: string) => - DELETE(`/openapi/kb/delDataById?dataId=${dataId}`); - -/** - * 拆分数据 - */ -export const postSplitData = (data: { - kbId: string; - chunks: string[]; - prompt: string; - mode: `${TrainingModeEnum}`; -}) => POST(`/openapi/text/pushData`, data); - -export const searchText = (data: SearchTestProps) => - POST(`/openapi/kb/searchTest`, data); diff --git a/client/src/api/request/kb.d.ts b/client/src/api/request/kb.d.ts deleted file mode 100644 index b382a0e4982..00000000000 --- a/client/src/api/request/kb.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { KbTypeEnum } from '@/constants/kb'; -import type { RequestPaging } from '@/types'; - -export type KbUpdateParams = { - id: string; - parentId?: string; - tags?: string; - name?: string; - avatar?: string; -}; -export type CreateKbParams = { - parentId?: string; - name: string; - tags: string[]; - avatar: string; - vectorModel?: string; - type: `${KbTypeEnum}`; -}; - -export type GetKbDataListProps = RequestPaging & { - kbId: string; - searchText: string; - fileId: string; -}; diff --git a/client/src/components/APIKeyModal/index.tsx b/client/src/components/APIKeyModal/index.tsx index f99c0480b4c..c3d1dde8ddc 100644 --- a/client/src/components/APIKeyModal/index.tsx +++ b/client/src/components/APIKeyModal/index.tsx @@ -19,7 +19,8 @@ import { useQuery, useMutation } from '@tanstack/react-query'; import { useLoading } from '@/hooks/useLoading'; import dayjs from 'dayjs'; import { AddIcon, DeleteIcon } from '@chakra-ui/icons'; -import { getErrText, useCopyData } from '@/utils/tools'; +import { getErrText } from '@/utils/tools'; +import { useCopyData } from '@/hooks/useCopyData'; import { useToast } from '@/hooks/useToast'; import MyIcon from '../Icon'; import MyModal from '../MyModal'; diff --git a/client/src/components/ChatBox/QuoteModal.tsx b/client/src/components/ChatBox/QuoteModal.tsx index 45ae73bbbaa..12723e44f8b 100644 --- a/client/src/components/ChatBox/QuoteModal.tsx +++ b/client/src/components/ChatBox/QuoteModal.tsx @@ -1,6 +1,6 @@ import React, { useCallback, useMemo, useState } from 'react'; import { ModalBody, Box, useTheme } from '@chakra-ui/react'; -import { getKbDataItemById } from '@/api/plugins/kb'; +import { getDatasetDataItemById } from '@/api/core/dataset/data'; import { useLoading } from '@/hooks/useLoading'; import { useToast } from '@/hooks/useToast'; import { getErrText } from '@/utils/tools'; @@ -8,10 +8,10 @@ import { QuoteItemType } from '@/types/chat'; import MyIcon from '@/components/Icon'; import InputDataModal, { RawFileText } from '@/pages/kb/detail/components/InputDataModal'; import MyModal from '../MyModal'; -import { KbDataItemType } from '@/types/plugin'; +import type { PgDataItemType } from '@/types/core/dataset/data'; import { useRouter } from 'next/router'; -type SearchType = KbDataItemType & { +type SearchType = PgDataItemType & { kb_id?: string; }; @@ -40,7 +40,7 @@ const QuoteModal = ({ if (!item.id) return; try { setIsLoading(true); - const data = await getKbDataItemById(item.id); + const data = await getDatasetDataItemById(item.id); if (!data) { onUpdateQuote(item.id, '已删除'); diff --git a/client/src/components/ChatBox/SelectDataset.tsx b/client/src/components/ChatBox/SelectDataset.tsx index c9720e1c4c5..0ab3d497452 100644 --- a/client/src/components/ChatBox/SelectDataset.tsx +++ b/client/src/components/ChatBox/SelectDataset.tsx @@ -4,7 +4,7 @@ import { useTranslation } from 'next-i18next'; import { useToast } from '@/hooks/useToast'; import Avatar from '../Avatar'; import MyIcon from '@/components/Icon'; -import { KbTypeEnum } from '@/constants/kb'; +import { KbTypeEnum } from '@/constants/dataset'; import DatasetSelectModal, { useDatasetSelect } from '@/components/core/dataset/SelectModal'; const SelectDataset = ({ diff --git a/client/src/components/ChatBox/index.tsx b/client/src/components/ChatBox/index.tsx index 827b423249a..71fc2e2de91 100644 --- a/client/src/components/ChatBox/index.tsx +++ b/client/src/components/ChatBox/index.tsx @@ -16,13 +16,9 @@ import { ExportChatType } from '@/types/chat'; import { useToast } from '@/hooks/useToast'; -import { - useCopyData, - voiceBroadcast, - cancelBroadcast, - hasVoiceApi, - getErrText -} from '@/utils/tools'; +import { voiceBroadcast, cancelBroadcast, hasVoiceApi } from '@/utils/web/voice'; +import { getErrText } from '@/utils/tools'; +import { useCopyData } from '@/hooks/useCopyData'; import { Box, Card, Flex, Input, Textarea, Button, useTheme, BoxProps } from '@chakra-ui/react'; import { feConfigs } from '@/store/static'; import { event } from '@/utils/plugin/eventbus'; @@ -32,7 +28,7 @@ import { VariableItemType } from '@/types/app'; import { VariableInputEnum } from '@/constants/app'; import { useForm } from 'react-hook-form'; import { MessageItemType } from '@/pages/api/openapi/v1/chat/completions'; -import { fileDownload } from '@/utils/file'; +import { fileDownload } from '@/utils/web/file'; import { htmlTemplate } from '@/constants/common'; import { useRouter } from 'next/router'; import { useGlobalStore } from '@/store/global'; diff --git a/client/src/components/Language/index.tsx b/client/src/components/Language/index.tsx index e6bdcc78a15..7ef15b987e1 100644 --- a/client/src/components/Language/index.tsx +++ b/client/src/components/Language/index.tsx @@ -1,6 +1,6 @@ import React, { useState } from 'react'; import { Menu, MenuButton, MenuItem, MenuList, MenuButtonProps } from '@chakra-ui/react'; -import { getLangStore, LangEnum, setLangStore, langMap } from '@/utils/i18n'; +import { getLangStore, LangEnum, setLangStore, langMap } from '@/utils/web/i18n'; import MyIcon from '@/components/Icon'; import { useTranslation } from 'react-i18next'; import { useRouter } from 'next/router'; diff --git a/client/src/components/Markdown/CodeLight.tsx b/client/src/components/Markdown/CodeLight.tsx index a6caed93d29..d8ee83fdd18 100644 --- a/client/src/components/Markdown/CodeLight.tsx +++ b/client/src/components/Markdown/CodeLight.tsx @@ -2,7 +2,7 @@ import React from 'react'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { Box, Flex, useColorModeValue } from '@chakra-ui/react'; import Icon from '@/components/Icon'; -import { useCopyData } from '@/utils/tools'; +import { useCopyData } from '@/hooks/useCopyData'; const codeLight: { [key: string]: React.CSSProperties } = { 'code[class*=language-]': { diff --git a/client/src/components/Markdown/chat/Quote.tsx b/client/src/components/Markdown/chat/Quote.tsx index 9b4f16021ac..3a838c37885 100644 --- a/client/src/components/Markdown/chat/Quote.tsx +++ b/client/src/components/Markdown/chat/Quote.tsx @@ -1,6 +1,6 @@ import React, { useMemo } from 'react'; import { Box, useTheme } from '@chakra-ui/react'; -import { getFileAndOpen } from '@/utils/common/file'; +import { getFileAndOpen } from '@/utils/web/file'; import { useToast } from '@/hooks/useToast'; import { getErrText } from '@/utils/tools'; diff --git a/client/src/components/core/dataset/SelectModal.tsx b/client/src/components/core/dataset/SelectModal.tsx index 3dda8b466d9..85b0db93020 100644 --- a/client/src/components/core/dataset/SelectModal.tsx +++ b/client/src/components/core/dataset/SelectModal.tsx @@ -1,4 +1,4 @@ -import { getKbList, getKbPaths } from '@/api/plugins/kb'; +import { getDatasets, getDatasetPaths } from '@/api/core/dataset'; import MyModal from '@/components/MyModal'; import { useQuery } from '@tanstack/react-query'; import React, { Dispatch, useMemo, useState } from 'react'; @@ -12,7 +12,7 @@ type PathItemType = { parentName: string; }; -const DatasetSelectModal = ({ +const DatasetSelectContainer = ({ isOpen, parentId, setParentId, @@ -97,7 +97,7 @@ export const useDatasetSelect = () => { const [parentId, setParentId] = useState(); const { data } = useQuery(['loadDatasetData', parentId], () => - Promise.all([getKbList({ parentId }), getKbPaths(parentId)]) + Promise.all([getDatasets({ parentId }), getDatasetPaths(parentId)]) ); const paths = useMemo( @@ -119,4 +119,4 @@ export const useDatasetSelect = () => { }; }; -export default DatasetSelectModal; +export default DatasetSelectContainer; diff --git a/client/src/constants/kb.ts b/client/src/constants/dataset.ts similarity index 84% rename from client/src/constants/kb.ts rename to client/src/constants/dataset.ts index 104cb589a0e..ee15e954fde 100644 --- a/client/src/constants/kb.ts +++ b/client/src/constants/dataset.ts @@ -1,6 +1,6 @@ -import type { KbItemType } from '@/types/plugin'; +import type { DatasetItemType } from '@/types/core/dataset'; -export const defaultKbDetail: KbItemType = { +export const defaultKbDetail: DatasetItemType = { _id: '', userId: '', avatar: '/icon/logo.svg', diff --git a/client/src/hooks/useCopyData.tsx b/client/src/hooks/useCopyData.tsx new file mode 100644 index 00000000000..54ecd1995cd --- /dev/null +++ b/client/src/hooks/useCopyData.tsx @@ -0,0 +1,39 @@ +import { useTranslation } from 'react-i18next'; +import { useToast } from './useToast'; + +/** + * copy text data + */ +export const useCopyData = () => { + const { t } = useTranslation(); + const { toast } = useToast(); + + return { + copyData: async ( + data: string, + title: string | null = t('common.Copy Successful'), + duration = 1000 + ) => { + try { + if (navigator.clipboard) { + await navigator.clipboard.writeText(data); + } else { + throw new Error(''); + } + } catch (error) { + const textarea = document.createElement('textarea'); + textarea.value = data; + document.body.appendChild(textarea); + textarea.select(); + document.execCommand('copy'); + document.body.removeChild(textarea); + } + + toast({ + title, + status: 'success', + duration + }); + } + }; +}; diff --git a/client/src/pages/_app.tsx b/client/src/pages/_app.tsx index 64fba807bfc..2b2ee6f9154 100644 --- a/client/src/pages/_app.tsx +++ b/client/src/pages/_app.tsx @@ -10,7 +10,7 @@ import NProgress from 'nprogress'; //nprogress module import Router from 'next/router'; import { clientInitData, feConfigs } from '@/store/static'; import { appWithTranslation, useTranslation } from 'next-i18next'; -import { getLangStore, setLangStore } from '@/utils/i18n'; +import { getLangStore, setLangStore } from '@/utils/web/i18n'; import { useRouter } from 'next/router'; import { useGlobalStore } from '@/store/global'; @@ -85,7 +85,10 @@ function App({ Component, pageProps }: AppProps) { <> {feConfigs?.systemTitle || 'AI'} - + ) { try { @@ -22,7 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< vectorModel: getVectorModel(item.vectorModel) })); - jsonRes(res, { + jsonRes(res, { data }); } catch (err) { diff --git a/client/src/pages/api/plugins/kb/create.ts b/client/src/pages/api/core/dataset/create.ts similarity index 88% rename from client/src/pages/api/plugins/kb/create.ts rename to client/src/pages/api/core/dataset/create.ts index ddc183dee63..03206e58ce9 100644 --- a/client/src/pages/api/plugins/kb/create.ts +++ b/client/src/pages/api/core/dataset/create.ts @@ -2,11 +2,11 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; import { connectToDatabase, KB } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; -import type { CreateKbParams } from '@/api/request/kb'; +import type { CreateDatasetParams } from '@/api/core/dataset/index.d'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { - const { name, tags, avatar, vectorModel, parentId, type } = req.body as CreateKbParams; + const { name, tags, avatar, vectorModel, parentId, type } = req.body as CreateDatasetParams; // 凭证校验 const { userId } = await authUser({ req, authToken: true }); diff --git a/client/src/pages/api/openapi/kb/delDataById.ts b/client/src/pages/api/core/dataset/data/delDataById.ts similarity index 100% rename from client/src/pages/api/openapi/kb/delDataById.ts rename to client/src/pages/api/core/dataset/data/delDataById.ts diff --git a/client/src/pages/api/plugins/kb/data/exportAll.ts b/client/src/pages/api/core/dataset/data/exportAll.ts similarity index 100% rename from client/src/pages/api/plugins/kb/data/exportAll.ts rename to client/src/pages/api/core/dataset/data/exportAll.ts diff --git a/client/src/pages/api/plugins/kb/data/getDataById.ts b/client/src/pages/api/core/dataset/data/getDataById.ts similarity index 89% rename from client/src/pages/api/plugins/kb/data/getDataById.ts rename to client/src/pages/api/core/dataset/data/getDataById.ts index 38d4ca940a8..1275055cddd 100644 --- a/client/src/pages/api/plugins/kb/data/getDataById.ts +++ b/client/src/pages/api/core/dataset/data/getDataById.ts @@ -3,8 +3,8 @@ import { jsonRes } from '@/service/response'; import { connectToDatabase } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; import { PgClient } from '@/service/pg'; -import type { KbDataItemType } from '@/types/plugin'; import { PgDatasetTableName } from '@/constants/plugin'; +import type { PgDataItemType } from '@/types/core/dataset/data'; export type Response = { id: string; @@ -29,7 +29,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< const where: any = [['user_id', userId], 'AND', ['id', dataId]]; - const searchRes = await PgClient.select(PgDatasetTableName, { + const searchRes = await PgClient.select(PgDatasetTableName, { fields: ['kb_id', 'id', 'q', 'a', 'source', 'file_id'], where, limit: 1 diff --git a/client/src/pages/api/plugins/kb/data/getDataList.ts b/client/src/pages/api/core/dataset/data/getDataList.ts similarity index 91% rename from client/src/pages/api/plugins/kb/data/getDataList.ts rename to client/src/pages/api/core/dataset/data/getDataList.ts index 74a261c86e1..8314a4717c1 100644 --- a/client/src/pages/api/plugins/kb/data/getDataList.ts +++ b/client/src/pages/api/core/dataset/data/getDataList.ts @@ -3,9 +3,9 @@ import { jsonRes } from '@/service/response'; import { connectToDatabase } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; import { PgClient } from '@/service/pg'; -import type { KbDataItemType } from '@/types/plugin'; import { PgDatasetTableName } from '@/constants/plugin'; -import { OtherFileId } from '@/constants/kb'; +import { OtherFileId } from '@/constants/dataset'; +import type { PgDataItemType } from '@/types/core/dataset/data'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -50,7 +50,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ]; const [searchRes, total] = await Promise.all([ - PgClient.select(PgDatasetTableName, { + PgClient.select(PgDatasetTableName, { fields: ['id', 'q', 'a', 'source', 'file_id'], where, order: [{ field: 'id', mode: 'DESC' }], diff --git a/client/src/pages/api/plugins/kb/data/getQueueLen.ts b/client/src/pages/api/core/dataset/data/getQueueLen.ts similarity index 100% rename from client/src/pages/api/plugins/kb/data/getQueueLen.ts rename to client/src/pages/api/core/dataset/data/getQueueLen.ts diff --git a/client/src/pages/api/plugins/kb/data/getTrainingData.ts b/client/src/pages/api/core/dataset/data/getTrainingData.ts similarity index 100% rename from client/src/pages/api/plugins/kb/data/getTrainingData.ts rename to client/src/pages/api/core/dataset/data/getTrainingData.ts diff --git a/client/src/pages/api/plugins/kb/data/insertData.ts b/client/src/pages/api/core/dataset/data/insertData.ts similarity index 88% rename from client/src/pages/api/plugins/kb/data/insertData.ts rename to client/src/pages/api/core/dataset/data/insertData.ts index fe0ed42de2f..d5d79cc89ac 100644 --- a/client/src/pages/api/plugins/kb/data/insertData.ts +++ b/client/src/pages/api/core/dataset/data/insertData.ts @@ -1,18 +1,18 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; -import { connectToDatabase, KB } from '@/service/mongo'; +import { connectToDatabase } from '@/service/mongo'; import { authKb, authUser } from '@/service/utils/auth'; import { withNextCors } from '@/service/utils/tools'; import { PgDatasetTableName } from '@/constants/plugin'; -import { insertKbItem, PgClient } from '@/service/pg'; +import { insertData2Dataset, PgClient } from '@/service/pg'; import { getVectorModel } from '@/service/utils/data'; import { getVector } from '@/pages/api/openapi/plugin/vector'; -import { DatasetItemType } from '@/types/plugin'; +import { DatasetDataItemType } from '@/types/core/dataset/data'; import { countPromptTokens } from '@/utils/common/tiktoken'; export type Props = { kbId: string; - data: DatasetItemType; + data: DatasetDataItemType; }; export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse) { @@ -58,7 +58,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex userId }); - const response = await insertKbItem({ + const response = await insertData2Dataset({ userId, kbId, data: [ diff --git a/client/src/pages/api/openapi/kb/pushData.ts b/client/src/pages/api/core/dataset/data/pushData.ts similarity index 90% rename from client/src/pages/api/openapi/kb/pushData.ts rename to client/src/pages/api/core/dataset/data/pushData.ts index e20542feca8..501c8401a9e 100644 --- a/client/src/pages/api/openapi/kb/pushData.ts +++ b/client/src/pages/api/core/dataset/data/pushData.ts @@ -8,19 +8,9 @@ import { PgDatasetTableName, TrainingModeEnum } from '@/constants/plugin'; import { startQueue } from '@/service/utils/tools'; import { PgClient } from '@/service/pg'; import { getVectorModel } from '@/service/utils/data'; -import { DatasetItemType } from '@/types/plugin'; +import { DatasetDataItemType } from '@/types/core/dataset/data'; import { countPromptTokens } from '@/utils/common/tiktoken'; - -export type Props = { - kbId: string; - data: DatasetItemType[]; - mode: `${TrainingModeEnum}`; - prompt?: string; -}; - -export type Response = { - insertLen: number; -}; +import type { PushDataProps, PushDataResponse } from '@/api/core/dataset/data.d'; const modeMap = { [TrainingModeEnum.index]: true, @@ -29,7 +19,7 @@ const modeMap = { export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse) { try { - const { kbId, data, mode = TrainingModeEnum.index, prompt } = req.body as Props; + const { kbId, data, mode = TrainingModeEnum.index, prompt } = req.body as PushDataProps; if (!kbId || !Array.isArray(data)) { throw new Error('KbId or data is empty'); @@ -48,7 +38,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex // 凭证校验 const { userId } = await authUser({ req }); - jsonRes(res, { + jsonRes(res, { data: await pushDataToKb({ kbId, data, @@ -71,7 +61,7 @@ export async function pushDataToKb({ data, mode, prompt -}: { userId: string } & Props): Promise { +}: { userId: string } & PushDataProps): Promise { const [kb, vectorModel] = await Promise.all([ authKb({ userId, @@ -94,7 +84,7 @@ export async function pushDataToKb({ // 过滤重复的 qa 内容 const set = new Set(); - const filterData: DatasetItemType[] = []; + const filterData: DatasetDataItemType[] = []; data.forEach((item) => { if (!item.q) return; @@ -150,7 +140,7 @@ export async function pushDataToKb({ ) ) .filter((item) => item.status === 'fulfilled') - .map((item: any) => item.value); + .map((item: any) => item.value); // 插入记录 const insertRes = await TrainingData.insertMany( diff --git a/client/src/pages/api/openapi/kb/updateData.ts b/client/src/pages/api/core/dataset/data/updateData.ts similarity index 88% rename from client/src/pages/api/openapi/kb/updateData.ts rename to client/src/pages/api/core/dataset/data/updateData.ts index 430b487fe93..9b949140ae9 100644 --- a/client/src/pages/api/openapi/kb/updateData.ts +++ b/client/src/pages/api/core/dataset/data/updateData.ts @@ -4,19 +4,13 @@ import { authUser } from '@/service/utils/auth'; import { PgClient } from '@/service/pg'; import { withNextCors } from '@/service/utils/tools'; import { KB, connectToDatabase } from '@/service/mongo'; -import { getVector } from '../plugin/vector'; +import { getVector } from '@/pages/api/openapi/plugin/vector'; import { PgDatasetTableName } from '@/constants/plugin'; - -export type Props = { - dataId: string; - kbId: string; - a?: string; - q?: string; -}; +import type { UpdateDataPrams } from '@/api/core/dataset/data.d'; export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse) { try { - const { dataId, a = '', q = '', kbId } = req.body as Props; + const { dataId, a = '', q = '', kbId } = req.body as UpdateDataPrams; if (!dataId) { throw new Error('缺少参数'); diff --git a/client/src/pages/api/plugins/kb/delete.ts b/client/src/pages/api/core/dataset/delete.ts similarity index 100% rename from client/src/pages/api/plugins/kb/delete.ts rename to client/src/pages/api/core/dataset/delete.ts diff --git a/client/src/pages/api/plugins/kb/detail.ts b/client/src/pages/api/core/dataset/detail.ts similarity index 100% rename from client/src/pages/api/plugins/kb/detail.ts rename to client/src/pages/api/core/dataset/detail.ts diff --git a/client/src/pages/api/core/dataset/file/delById.ts b/client/src/pages/api/core/dataset/file/delById.ts index 1fa5f2e3940..cb95c58121c 100644 --- a/client/src/pages/api/core/dataset/file/delById.ts +++ b/client/src/pages/api/core/dataset/file/delById.ts @@ -6,7 +6,7 @@ import { GridFSStorage } from '@/service/lib/gridfs'; import { PgClient } from '@/service/pg'; import { PgDatasetTableName } from '@/constants/plugin'; import { Types } from 'mongoose'; -import { OtherFileId } from '@/constants/kb'; +import { OtherFileId } from '@/constants/dataset'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { diff --git a/client/src/pages/api/core/dataset/file/detail.ts b/client/src/pages/api/core/dataset/file/detail.ts index ccdbfa721b2..dc3567040fd 100644 --- a/client/src/pages/api/core/dataset/file/detail.ts +++ b/client/src/pages/api/core/dataset/file/detail.ts @@ -3,8 +3,8 @@ import { jsonRes } from '@/service/response'; import { connectToDatabase } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; import { GridFSStorage } from '@/service/lib/gridfs'; -import { OtherFileId } from '@/constants/kb'; -import type { FileInfo } from '@/types/plugin'; +import { OtherFileId } from '@/constants/dataset'; +import type { GSFileInfoType } from '@/types/common/file'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -15,7 +15,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< const { userId } = await authUser({ req, authToken: true }); if (fileId === OtherFileId) { - return jsonRes(res, { + return jsonRes(res, { data: { id: OtherFileId, size: 0, @@ -31,7 +31,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< const file = await gridFs.findAndAuthFile(fileId); - jsonRes(res, { + jsonRes(res, { data: file }); } catch (err) { diff --git a/client/src/pages/api/core/dataset/file/list.ts b/client/src/pages/api/core/dataset/file/list.ts index f9daf18a96e..536e244a73d 100644 --- a/client/src/pages/api/core/dataset/file/list.ts +++ b/client/src/pages/api/core/dataset/file/list.ts @@ -5,7 +5,7 @@ import { authUser } from '@/service/utils/auth'; import { GridFSStorage } from '@/service/lib/gridfs'; import { PgClient } from '@/service/pg'; import { PgDatasetTableName } from '@/constants/plugin'; -import { FileStatusEnum, OtherFileId } from '@/constants/kb'; +import { FileStatusEnum, OtherFileId } from '@/constants/dataset'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { diff --git a/client/src/pages/api/plugins/kb/list.ts b/client/src/pages/api/core/dataset/list.ts similarity index 87% rename from client/src/pages/api/plugins/kb/list.ts rename to client/src/pages/api/core/dataset/list.ts index 9957411ec7c..a4afc3f5e43 100644 --- a/client/src/pages/api/plugins/kb/list.ts +++ b/client/src/pages/api/core/dataset/list.ts @@ -3,8 +3,8 @@ import { jsonRes } from '@/service/response'; import { connectToDatabase, KB } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; import { getVectorModel } from '@/service/utils/data'; -import { KbListItemType } from '@/types/plugin'; -import { KbTypeEnum } from '@/constants/kb'; +import type { DatasetsItemType } from '@/types/core/dataset'; +import { KbTypeEnum } from '@/constants/dataset'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -27,7 +27,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< })) ); - jsonRes(res, { + jsonRes(res, { data }); } catch (err) { diff --git a/client/src/pages/api/plugins/kb/paths.ts b/client/src/pages/api/core/dataset/paths.ts similarity index 79% rename from client/src/pages/api/plugins/kb/paths.ts rename to client/src/pages/api/core/dataset/paths.ts index db6b5e26dee..b59d20ea4bf 100644 --- a/client/src/pages/api/plugins/kb/paths.ts +++ b/client/src/pages/api/core/dataset/paths.ts @@ -1,7 +1,7 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; import { connectToDatabase, KB } from '@/service/mongo'; -import { KbPathItemType } from '@/types/plugin'; +import type { DatasetPathItemType } from '@/types/core/dataset'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { @@ -9,7 +9,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< const { parentId } = req.query as { parentId: string }; - jsonRes(res, { + jsonRes(res, { data: await getParents(parentId) }); } catch (err) { @@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< } } -async function getParents(parentId?: string): Promise { +async function getParents(parentId?: string): Promise { if (!parentId) { return []; } diff --git a/client/src/pages/api/openapi/kb/searchTest.ts b/client/src/pages/api/core/dataset/searchTest.ts similarity index 83% rename from client/src/pages/api/openapi/kb/searchTest.ts rename to client/src/pages/api/core/dataset/searchTest.ts index 25974b0822c..dc78b17b3c9 100644 --- a/client/src/pages/api/openapi/kb/searchTest.ts +++ b/client/src/pages/api/core/dataset/searchTest.ts @@ -3,20 +3,14 @@ import { jsonRes } from '@/service/response'; import { authUser } from '@/service/utils/auth'; import { PgClient } from '@/service/pg'; import { withNextCors } from '@/service/utils/tools'; -import { getVector } from '../plugin/vector'; -import type { KbTestItemType } from '@/types/plugin'; +import { getVector } from '../../openapi/plugin/vector'; import { PgDatasetTableName } from '@/constants/plugin'; import { KB } from '@/service/mongo'; - -export type Props = { - kbId: string; - text: string; -}; -export type Response = KbTestItemType['results']; +import type { SearchTestProps, SearchTestResponseType } from '@/api/core/dataset/index.d'; export default withNextCors(async function handler(req: NextApiRequest, res: NextApiResponse) { try { - const { kbId, text } = req.body as Props; + const { kbId, text } = req.body as SearchTestProps; if (!kbId || !text) { throw new Error('缺少参数'); @@ -49,7 +43,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex COMMIT;` ); - jsonRes(res, { + jsonRes(res, { data: response?.[2]?.rows || [] }); } catch (err) { diff --git a/client/src/pages/api/plugins/kb/update.ts b/client/src/pages/api/core/dataset/update.ts similarity index 86% rename from client/src/pages/api/plugins/kb/update.ts rename to client/src/pages/api/core/dataset/update.ts index 5492a106585..4cf118af4b0 100644 --- a/client/src/pages/api/plugins/kb/update.ts +++ b/client/src/pages/api/core/dataset/update.ts @@ -2,11 +2,11 @@ import type { NextApiRequest, NextApiResponse } from 'next'; import { jsonRes } from '@/service/response'; import { connectToDatabase, KB } from '@/service/mongo'; import { authUser } from '@/service/utils/auth'; -import type { KbUpdateParams } from '@/api/request/kb'; +import type { DatasetUpdateParams } from '@/api/core/dataset/index.d'; export default async function handler(req: NextApiRequest, res: NextApiResponse) { try { - const { id, parentId, name, avatar, tags } = req.body as KbUpdateParams; + const { id, parentId, name, avatar, tags } = req.body as DatasetUpdateParams; if (!id) { throw new Error('缺少参数'); diff --git a/client/src/pages/app/detail/components/API.tsx b/client/src/pages/app/detail/components/API.tsx index 2f1a966af6b..79aa84cb3bd 100644 --- a/client/src/pages/app/detail/components/API.tsx +++ b/client/src/pages/app/detail/components/API.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useState } from 'react'; import { Box, Divider, Flex, useTheme, Button, Skeleton, useDisclosure } from '@chakra-ui/react'; -import { useCopyData } from '@/utils/tools'; +import { useCopyData } from '@/hooks/useCopyData'; import dynamic from 'next/dynamic'; import MyIcon from '@/components/Icon'; import { useGlobalStore } from '@/store/global'; diff --git a/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx b/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx index 4cd8ea53626..6007df4129f 100644 --- a/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx +++ b/client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeKbSearch.tsx @@ -9,16 +9,16 @@ import Divider from '../modules/Divider'; import Container from '../modules/Container'; import RenderInput from '../render/RenderInput'; import RenderOutput from '../render/RenderOutput'; -import { KBSelectModal } from '../../../KBSelectModal'; -import type { SelectedKbType } from '@/types/plugin'; +import { DatasetSelectModal } from '../../../DatasetSelectModal'; +import type { SelectedDatasetType } from '@/types/core/dataset'; import Avatar from '@/components/Avatar'; const KBSelect = ({ activeKbs = [], onChange }: { - activeKbs: SelectedKbType; - onChange: (e: SelectedKbType) => void; + activeKbs: SelectedDatasetType; + onChange: (e: SelectedDatasetType) => void; }) => { const theme = useTheme(); const { allDatasets, loadAllDatasets } = useDatasetStore(); @@ -57,7 +57,7 @@ const KBSelect = ({ ))} - import('../VariableEditModal')); const InfoModal = dynamic(() => import('../InfoModal')); -const KBSelectModal = dynamic(() => import('../KBSelectModal')); +const DatasetSelectModal = dynamic(() => import('../DatasetSelectModal')); const AIChatSettingsModal = dynamic(() => import('../AIChatSettingsModal')); const Settings = ({ appId }: { appId: string }) => { @@ -565,7 +565,7 @@ const Settings = ({ appId }: { appId: string }) => { /> )} {isOpenKbSelect && ( - ({ kbId: item._id, diff --git a/client/src/pages/app/detail/components/KBSelectModal.tsx b/client/src/pages/app/detail/components/DatasetSelectModal.tsx similarity index 94% rename from client/src/pages/app/detail/components/KBSelectModal.tsx rename to client/src/pages/app/detail/components/DatasetSelectModal.tsx index 8f8e31996a2..b064ae02ad5 100644 --- a/client/src/pages/app/detail/components/KBSelectModal.tsx +++ b/client/src/pages/app/detail/components/DatasetSelectModal.tsx @@ -14,18 +14,18 @@ import { import Avatar from '@/components/Avatar'; import { useForm } from 'react-hook-form'; import { QuestionOutlineIcon } from '@chakra-ui/icons'; -import type { SelectedKbType } from '@/types/plugin'; +import type { SelectedDatasetType } from '@/types/core/dataset'; import { useToast } from '@/hooks/useToast'; import MySlider from '@/components/Slider'; import MyTooltip from '@/components/MyTooltip'; import MyModal from '@/components/MyModal'; import MyIcon from '@/components/Icon'; -import { KbTypeEnum } from '@/constants/kb'; +import { KbTypeEnum } from '@/constants/dataset'; import { useTranslation } from 'react-i18next'; import { useQuery } from '@tanstack/react-query'; import { useDatasetStore } from '@/store/dataset'; import { feConfigs } from '@/store/static'; -import DatasetSelectModal, { useDatasetSelect } from '@/components/core/dataset/SelectModal'; +import DatasetSelectContainer, { useDatasetSelect } from '@/components/core/dataset/SelectModal'; export type KbParamsType = { searchSimilarity: number; @@ -33,20 +33,20 @@ export type KbParamsType = { searchEmptyText: string; }; -export const KBSelectModal = ({ +export const DatasetSelectModal = ({ isOpen, activeKbs = [], onChange, onClose }: { isOpen: boolean; - activeKbs: SelectedKbType; - onChange: (e: SelectedKbType) => void; + activeKbs: SelectedDatasetType; + onChange: (e: SelectedDatasetType) => void; onClose: () => void; }) => { const { t } = useTranslation(); const theme = useTheme(); - const [selectedKbList, setSelectedKbList] = useState(activeKbs); + const [selectedKbList, setSelectedKbList] = useState(activeKbs); const { toast } = useToast(); const { paths, parentId, setParentId, datasets } = useDatasetSelect(); const { allDatasets, loadAllDatasets } = useDatasetStore(); @@ -61,7 +61,7 @@ export const KBSelectModal = ({ }, [datasets, allDatasets, selectedKbList]); return ( - { // filter out the kb that is not in the kList const filterKbList = selectedKbList.filter((kb) => { - return datasets.find((item) => item._id === kb.kbId); + return allDatasets.find((item) => item._id === kb.kbId); }); onClose(); @@ -196,7 +196,7 @@ export const KBSelectModal = ({ 完成 - + ); }; @@ -297,4 +297,4 @@ export const KbParamsModal = ({ ); }; -export default KBSelectModal; +export default DatasetSelectModal; diff --git a/client/src/pages/app/detail/components/InfoModal.tsx b/client/src/pages/app/detail/components/InfoModal.tsx index 5e87b53dd6a..7544c8e6524 100644 --- a/client/src/pages/app/detail/components/InfoModal.tsx +++ b/client/src/pages/app/detail/components/InfoModal.tsx @@ -13,7 +13,7 @@ import { useForm } from 'react-hook-form'; import { AppSchema } from '@/types/mongoSchema'; import { useToast } from '@/hooks/useToast'; import { useSelectFile } from '@/hooks/useSelectFile'; -import { compressImg } from '@/utils/file'; +import { compressImg } from '@/utils/web/file'; import { getErrText } from '@/utils/tools'; import { useUserStore } from '@/store/user'; import { useRequest } from '@/hooks/useRequest'; diff --git a/client/src/pages/app/detail/components/OutLink.tsx b/client/src/pages/app/detail/components/OutLink.tsx index 156b50b0407..aaa5e329fdd 100644 --- a/client/src/pages/app/detail/components/OutLink.tsx +++ b/client/src/pages/app/detail/components/OutLink.tsx @@ -30,7 +30,8 @@ import { createShareChat, putShareChat } from '@/api/support/outLink'; -import { formatTimeToChatTime, useCopyData } from '@/utils/tools'; +import { formatTimeToChatTime } from '@/utils/tools'; +import { useCopyData } from '@/hooks/useCopyData'; import { useForm } from 'react-hook-form'; import { defaultOutLinkForm } from '@/constants/model'; import type { OutLinkEditType } from '@/types/support/outLink'; diff --git a/client/src/pages/app/detail/index.tsx b/client/src/pages/app/detail/index.tsx index b928ed0ae03..0a501c846a1 100644 --- a/client/src/pages/app/detail/index.tsx +++ b/client/src/pages/app/detail/index.tsx @@ -14,7 +14,7 @@ import MyIcon from '@/components/Icon'; import PageContainer from '@/components/PageContainer'; import Loading from '@/components/Loading'; import BasicEdit from './components/BasicEdit'; -import { serviceSideProps } from '@/utils/i18n'; +import { serviceSideProps } from '@/utils/web/i18n'; const AdEdit = dynamic(() => import('./components/AdEdit'), { ssr: false, diff --git a/client/src/pages/app/list/component/CreateModal.tsx b/client/src/pages/app/list/component/CreateModal.tsx index b5bace51137..426cb19e1c0 100644 --- a/client/src/pages/app/list/component/CreateModal.tsx +++ b/client/src/pages/app/list/component/CreateModal.tsx @@ -13,7 +13,7 @@ import { } from '@chakra-ui/react'; import { useSelectFile } from '@/hooks/useSelectFile'; import { useForm } from 'react-hook-form'; -import { compressImg } from '@/utils/file'; +import { compressImg } from '@/utils/web/file'; import { getErrText } from '@/utils/tools'; import { useToast } from '@/hooks/useToast'; import { postCreateApp } from '@/api/app'; diff --git a/client/src/pages/app/list/index.tsx b/client/src/pages/app/list/index.tsx index c6d744c41f5..2bde0ddb87d 100644 --- a/client/src/pages/app/list/index.tsx +++ b/client/src/pages/app/list/index.tsx @@ -16,7 +16,7 @@ import { AddIcon } from '@chakra-ui/icons'; import { delModelById } from '@/api/app'; import { useToast } from '@/hooks/useToast'; import { useConfirm } from '@/hooks/useConfirm'; -import { serviceSideProps } from '@/utils/i18n'; +import { serviceSideProps } from '@/utils/web/i18n'; import { useTranslation } from 'next-i18next'; import MyIcon from '@/components/Icon'; diff --git a/client/src/pages/appStore/index.tsx b/client/src/pages/appStore/index.tsx index 32963eea903..56b5721f884 100644 --- a/client/src/pages/appStore/index.tsx +++ b/client/src/pages/appStore/index.tsx @@ -7,7 +7,7 @@ import type { ShareAppItem } from '@/types/app'; import { useUserStore } from '@/store/user'; import ShareModelList from './components/list'; import styles from './index.module.scss'; -import { serviceSideProps } from '@/utils/i18n'; +import { serviceSideProps } from '@/utils/web/i18n'; const modelList = () => { const { Loading } = useLoading(); diff --git a/client/src/pages/chat/index.tsx b/client/src/pages/chat/index.tsx index 14b25a97322..0e1935deb40 100644 --- a/client/src/pages/chat/index.tsx +++ b/client/src/pages/chat/index.tsx @@ -30,7 +30,7 @@ import SliderApps from './components/SliderApps'; import ChatHeader from './components/ChatHeader'; import { getErrText } from '@/utils/tools'; import { useUserStore } from '@/store/user'; -import { serviceSideProps } from '@/utils/i18n'; +import { serviceSideProps } from '@/utils/web/i18n'; const Chat = ({ appId, chatId }: { appId: string; chatId: string }) => { const router = useRouter(); diff --git a/client/src/pages/chat/share.tsx b/client/src/pages/chat/share.tsx index a2889eb0ec2..a63d8a42409 100644 --- a/client/src/pages/chat/share.tsx +++ b/client/src/pages/chat/share.tsx @@ -19,7 +19,7 @@ import ChatBox, { type ComponentRef, type StartChatFnProps } from '@/components/ import PageContainer from '@/components/PageContainer'; import ChatHeader from './components/ChatHeader'; import ChatHistorySlider from './components/ChatHistorySlider'; -import { serviceSideProps } from '@/utils/i18n'; +import { serviceSideProps } from '@/utils/web/i18n'; const OutLink = ({ shareId, chatId }: { shareId: string; chatId: string }) => { const router = useRouter(); diff --git a/client/src/pages/index.tsx b/client/src/pages/index.tsx index 74eddcad091..1b5208cde12 100644 --- a/client/src/pages/index.tsx +++ b/client/src/pages/index.tsx @@ -1,7 +1,7 @@ import React, { useEffect } from 'react'; import { Box } from '@chakra-ui/react'; import { feConfigs } from '@/store/static'; -import { serviceSideProps } from '@/utils/i18n'; +import { serviceSideProps } from '@/utils/web/i18n'; import { useRouter } from 'next/router'; import Navbar from './components/Navbar'; @@ -10,6 +10,7 @@ import Ability from './components/Ability'; import Choice from './components/Choice'; import Footer from './components/Footer'; import Loading from '@/components/Loading'; +import Head from 'next/head'; const Home = ({ homeUrl = '/' }: { homeUrl: string }) => { const router = useRouter(); @@ -23,26 +24,33 @@ const Home = ({ homeUrl = '/' }: { homeUrl: string }) => { router.prefetch('/login'); }, []); - return homeUrl === '/' ? ( - - - - - - - - - - - - {feConfigs?.show_git && ( - -