Skip to content

Commit

Permalink
Optimize the structure and naming of projects (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Sep 21, 2023
1 parent a3c7748 commit 823f4b7
Show file tree
Hide file tree
Showing 97 changed files with 882 additions and 821 deletions.
26 changes: 26 additions & 0 deletions client/src/api/core/dataset/data.d.ts
Original file line number Diff line number Diff line change
@@ -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;
};
72 changes: 72 additions & 0 deletions client/src/api/core/dataset/data.ts
Original file line number Diff line number Diff line change
@@ -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<number>(`/core/dataset/data/getQueueLen`);

export const getDatasetDataItemById = (dataId: string) =>
GET<QuoteItemType>(`/core/dataset/data/getDataById`, { dataId });

/**
* push data to training queue
*/
export const postChunks2Dataset = (data: PushDataProps) =>
POST<PushDataResponse>(`/core/dataset/data/pushData`, data);

/**
* insert one data to dataset (immediately insert)
*/
export const postData2Dataset = (data: { kbId: string; data: DatasetDataItemType }) =>
POST<string>(`/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}`);
7 changes: 4 additions & 3 deletions client/src/api/core/dataset/file.ts
Original file line number Diff line number Diff line change
@@ -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<KbFileItemType[]>(`/core/dataset/file/list`, data);
POST<DatasetFileItemType[]>(`/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<FileInfo>(`/core/dataset/file/detail`, { fileId });
GET<GSFileInfoType>(`/core/dataset/file/detail`, { fileId });
export const delDatasetEmptyFiles = (kbId: string) =>
DELETE(`/core/dataset/file/delEmptyFiles`, { kbId });

Expand Down
34 changes: 34 additions & 0 deletions client/src/api/core/dataset/index.d.ts
Original file line number Diff line number Diff line change
@@ -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'];
32 changes: 32 additions & 0 deletions client/src/api/core/dataset/index.ts
Original file line number Diff line number Diff line change
@@ -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<DatasetsItemType[]>(`/core/dataset/list`, data);

/**
* get type=dataset list
*/
export const getAllDataset = () => GET<DatasetsItemType[]>(`/core/dataset/allDataset`);

export const getDatasetPaths = (parentId?: string) =>
GET<DatasetPathItemType[]>('/core/dataset/paths', { parentId });

export const getDatasetById = (id: string) => GET<DatasetItemType>(`/core/dataset/detail?id=${id}`);

export const postCreateDataset = (data: CreateDatasetParams) =>
POST<string>(`/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<SearchTestResponseType>(`/core/dataset/searchTest`, data);
106 changes: 0 additions & 106 deletions client/src/api/plugins/kb.ts

This file was deleted.

24 changes: 0 additions & 24 deletions client/src/api/request/kb.d.ts

This file was deleted.

3 changes: 2 additions & 1 deletion client/src/components/APIKeyModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 4 additions & 4 deletions client/src/components/ChatBox/QuoteModal.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
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';
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;
};

Expand Down Expand Up @@ -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, '已删除');
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/ChatBox/SelectDataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ({
Expand Down
12 changes: 4 additions & 8 deletions client/src/components/ChatBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down
Loading

0 comments on commit 823f4b7

Please sign in to comment.