Skip to content

Commit 823f4b7

Browse files
authored
Optimize the structure and naming of projects (#335)
1 parent a3c7748 commit 823f4b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+882
-821
lines changed

client/src/api/core/dataset/data.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { KbTypeEnum } from '@/constants/dataset';
2+
import type { RequestPaging } from '@/types';
3+
import { TrainingModeEnum } from '@/constants/plugin';
4+
5+
export type PushDataProps = {
6+
kbId: string;
7+
data: DatasetItemType[];
8+
mode: `${TrainingModeEnum}`;
9+
prompt?: string;
10+
};
11+
export type PushDataResponse = {
12+
insertLen: number;
13+
};
14+
15+
export type UpdateDataPrams = {
16+
dataId: string;
17+
kbId: string;
18+
a?: string;
19+
q?: string;
20+
};
21+
22+
export type GetDatasetDataListProps = RequestPaging & {
23+
kbId: string;
24+
searchText: string;
25+
fileId: string;
26+
};

client/src/api/core/dataset/data.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { GET, POST, PUT, DELETE } from '@/api/request';
2+
import type { DatasetDataItemType } from '@/types/core/dataset/data';
3+
import type {
4+
PushDataProps,
5+
PushDataResponse,
6+
UpdateDataPrams,
7+
GetDatasetDataListProps
8+
} from './data.d';
9+
import { QuoteItemType } from '@/types/chat';
10+
import { getToken } from '@/utils/user';
11+
import download from 'downloadjs';
12+
13+
/* kb data */
14+
export const getDatasetDataList = (data: GetDatasetDataListProps) =>
15+
POST(`/core/dataset/data/getDataList`, data);
16+
17+
/**
18+
* export and download data
19+
*/
20+
export const exportDatasetData = (data: { kbId: string }) =>
21+
fetch(`/api/core/dataset/data/exportAll?kbId=${data.kbId}`, {
22+
method: 'GET',
23+
headers: {
24+
token: getToken()
25+
}
26+
})
27+
.then(async (res) => {
28+
if (!res.ok) {
29+
const data = await res.json();
30+
throw new Error(data?.message || 'Export failed');
31+
}
32+
return res.blob();
33+
})
34+
.then((blob) => download(blob, 'dataset.csv', 'text/csv'));
35+
36+
/**
37+
* 获取模型正在拆分数据的数量
38+
*/
39+
export const getTrainingData = (data: { kbId: string; init: boolean }) =>
40+
POST<{
41+
qaListLen: number;
42+
vectorListLen: number;
43+
}>(`/core/dataset/data/getTrainingData`, data);
44+
45+
/* get length of system training queue */
46+
export const getTrainingQueueLen = () => GET<number>(`/core/dataset/data/getQueueLen`);
47+
48+
export const getDatasetDataItemById = (dataId: string) =>
49+
GET<QuoteItemType>(`/core/dataset/data/getDataById`, { dataId });
50+
51+
/**
52+
* push data to training queue
53+
*/
54+
export const postChunks2Dataset = (data: PushDataProps) =>
55+
POST<PushDataResponse>(`/core/dataset/data/pushData`, data);
56+
57+
/**
58+
* insert one data to dataset (immediately insert)
59+
*/
60+
export const postData2Dataset = (data: { kbId: string; data: DatasetDataItemType }) =>
61+
POST<string>(`/core/dataset/data/insertData`, data);
62+
63+
/**
64+
* 更新一条数据
65+
*/
66+
export const putDatasetDataById = (data: UpdateDataPrams) =>
67+
PUT('/core/dataset/data/updateData', data);
68+
/**
69+
* 删除一条知识库数据
70+
*/
71+
export const delOneDatasetDataById = (dataId: string) =>
72+
DELETE(`/core/dataset/data/delDataById?dataId=${dataId}`);

client/src/api/core/dataset/file.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { GET, POST, PUT, DELETE } from '@/api/request';
2-
import type { FileInfo, KbFileItemType } from '@/types/plugin';
2+
import type { DatasetFileItemType } from '@/types/core/dataset/file';
3+
import type { GSFileInfoType } from '@/types/common/file';
34

45
import type { GetFileListProps, UpdateFileProps } from './file.d';
56

67
export const getDatasetFiles = (data: GetFileListProps) =>
7-
POST<KbFileItemType[]>(`/core/dataset/file/list`, data);
8+
POST<DatasetFileItemType[]>(`/core/dataset/file/list`, data);
89
export const delDatasetFileById = (params: { fileId: string; kbId: string }) =>
910
DELETE(`/core/dataset/file/delById`, params);
1011
export const getFileInfoById = (fileId: string) =>
11-
GET<FileInfo>(`/core/dataset/file/detail`, { fileId });
12+
GET<GSFileInfoType>(`/core/dataset/file/detail`, { fileId });
1213
export const delDatasetEmptyFiles = (kbId: string) =>
1314
DELETE(`/core/dataset/file/delEmptyFiles`, { kbId });
1415

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { KbTypeEnum } from '@/constants/dataset';
2+
import type { RequestPaging } from '@/types';
3+
import { TrainingModeEnum } from '@/constants/plugin';
4+
import type { SearchTestItemType } from '@/types/core/dataset';
5+
6+
export type DatasetUpdateParams = {
7+
id: string;
8+
parentId?: string;
9+
tags?: string;
10+
name?: string;
11+
avatar?: string;
12+
};
13+
export type CreateDatasetParams = {
14+
parentId?: string;
15+
name: string;
16+
tags: string[];
17+
avatar: string;
18+
vectorModel?: string;
19+
type: `${KbTypeEnum}`;
20+
};
21+
22+
export type DatasetUpdateParams = {
23+
id: string;
24+
parentId?: string;
25+
tags?: string;
26+
name?: string;
27+
avatar?: string;
28+
};
29+
30+
export type SearchTestProps = {
31+
kbId: string;
32+
text: string;
33+
};
34+
export type SearchTestResponseType = SearchTestItemType['results'];

client/src/api/core/dataset/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { GET, POST, PUT, DELETE } from '@/api/request';
2+
import type { DatasetItemType, DatasetsItemType, DatasetPathItemType } from '@/types/core/dataset';
3+
import type {
4+
DatasetUpdateParams,
5+
CreateDatasetParams,
6+
SearchTestProps,
7+
SearchTestResponseType
8+
} from './index.d';
9+
import { KbTypeEnum } from '@/constants/dataset';
10+
11+
export const getDatasets = (data: { parentId?: string; type?: `${KbTypeEnum}` }) =>
12+
GET<DatasetsItemType[]>(`/core/dataset/list`, data);
13+
14+
/**
15+
* get type=dataset list
16+
*/
17+
export const getAllDataset = () => GET<DatasetsItemType[]>(`/core/dataset/allDataset`);
18+
19+
export const getDatasetPaths = (parentId?: string) =>
20+
GET<DatasetPathItemType[]>('/core/dataset/paths', { parentId });
21+
22+
export const getDatasetById = (id: string) => GET<DatasetItemType>(`/core/dataset/detail?id=${id}`);
23+
24+
export const postCreateDataset = (data: CreateDatasetParams) =>
25+
POST<string>(`/core/dataset/create`, data);
26+
27+
export const putDatasetById = (data: DatasetUpdateParams) => PUT(`/core/dataset/update`, data);
28+
29+
export const delDatasetById = (id: string) => DELETE(`/core/dataset/delete?id=${id}`);
30+
31+
export const postSearchText = (data: SearchTestProps) =>
32+
POST<SearchTestResponseType>(`/core/dataset/searchTest`, data);

client/src/api/plugins/kb.ts

Lines changed: 0 additions & 106 deletions
This file was deleted.

client/src/api/request/kb.d.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

client/src/components/APIKeyModal/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import { useQuery, useMutation } from '@tanstack/react-query';
1919
import { useLoading } from '@/hooks/useLoading';
2020
import dayjs from 'dayjs';
2121
import { AddIcon, DeleteIcon } from '@chakra-ui/icons';
22-
import { getErrText, useCopyData } from '@/utils/tools';
22+
import { getErrText } from '@/utils/tools';
23+
import { useCopyData } from '@/hooks/useCopyData';
2324
import { useToast } from '@/hooks/useToast';
2425
import MyIcon from '../Icon';
2526
import MyModal from '../MyModal';

client/src/components/ChatBox/QuoteModal.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import React, { useCallback, useMemo, useState } from 'react';
22
import { ModalBody, Box, useTheme } from '@chakra-ui/react';
3-
import { getKbDataItemById } from '@/api/plugins/kb';
3+
import { getDatasetDataItemById } from '@/api/core/dataset/data';
44
import { useLoading } from '@/hooks/useLoading';
55
import { useToast } from '@/hooks/useToast';
66
import { getErrText } from '@/utils/tools';
77
import { QuoteItemType } from '@/types/chat';
88
import MyIcon from '@/components/Icon';
99
import InputDataModal, { RawFileText } from '@/pages/kb/detail/components/InputDataModal';
1010
import MyModal from '../MyModal';
11-
import { KbDataItemType } from '@/types/plugin';
11+
import type { PgDataItemType } from '@/types/core/dataset/data';
1212
import { useRouter } from 'next/router';
1313

14-
type SearchType = KbDataItemType & {
14+
type SearchType = PgDataItemType & {
1515
kb_id?: string;
1616
};
1717

@@ -40,7 +40,7 @@ const QuoteModal = ({
4040
if (!item.id) return;
4141
try {
4242
setIsLoading(true);
43-
const data = await getKbDataItemById(item.id);
43+
const data = await getDatasetDataItemById(item.id);
4444

4545
if (!data) {
4646
onUpdateQuote(item.id, '已删除');

client/src/components/ChatBox/SelectDataset.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useTranslation } from 'next-i18next';
44
import { useToast } from '@/hooks/useToast';
55
import Avatar from '../Avatar';
66
import MyIcon from '@/components/Icon';
7-
import { KbTypeEnum } from '@/constants/kb';
7+
import { KbTypeEnum } from '@/constants/dataset';
88
import DatasetSelectModal, { useDatasetSelect } from '@/components/core/dataset/SelectModal';
99

1010
const SelectDataset = ({

client/src/components/ChatBox/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@ import {
1616
ExportChatType
1717
} from '@/types/chat';
1818
import { useToast } from '@/hooks/useToast';
19-
import {
20-
useCopyData,
21-
voiceBroadcast,
22-
cancelBroadcast,
23-
hasVoiceApi,
24-
getErrText
25-
} from '@/utils/tools';
19+
import { voiceBroadcast, cancelBroadcast, hasVoiceApi } from '@/utils/web/voice';
20+
import { getErrText } from '@/utils/tools';
21+
import { useCopyData } from '@/hooks/useCopyData';
2622
import { Box, Card, Flex, Input, Textarea, Button, useTheme, BoxProps } from '@chakra-ui/react';
2723
import { feConfigs } from '@/store/static';
2824
import { event } from '@/utils/plugin/eventbus';
@@ -32,7 +28,7 @@ import { VariableItemType } from '@/types/app';
3228
import { VariableInputEnum } from '@/constants/app';
3329
import { useForm } from 'react-hook-form';
3430
import { MessageItemType } from '@/pages/api/openapi/v1/chat/completions';
35-
import { fileDownload } from '@/utils/file';
31+
import { fileDownload } from '@/utils/web/file';
3632
import { htmlTemplate } from '@/constants/common';
3733
import { useRouter } from 'next/router';
3834
import { useGlobalStore } from '@/store/global';

0 commit comments

Comments
 (0)