Skip to content

Commit

Permalink
Feat: Add TagTable
Browse files Browse the repository at this point in the history
  • Loading branch information
cike8899 committed Jan 6, 2025
1 parent 9c6cf12 commit 5bbfdb1
Show file tree
Hide file tree
Showing 16 changed files with 604 additions and 6 deletions.
2 changes: 1 addition & 1 deletion web/src/components/chunk-method-modal/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export const useFetchParserListOnMount = (
return { parserList: nextParserList, handleChange, selectedTag };
};

const hideAutoKeywords = ['qa', 'table', 'resume', 'knowledge_graph'];
const hideAutoKeywords = ['qa', 'table', 'resume', 'knowledge_graph', 'tag'];

export const useShowAutoKeywords = () => {
const showAutoKeywords = useCallback((selectedTag: string) => {
Expand Down
6 changes: 5 additions & 1 deletion web/src/components/confirm-delete-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ interface IProps {
export function ConfirmDeleteDialog({
children,
title,
onOk,
}: IProps & PropsWithChildren) {
const { t } = useTranslation();

Expand All @@ -39,7 +40,10 @@ export function ConfirmDeleteDialog({
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>{t('common.cancel')}</AlertDialogCancel>
<AlertDialogAction className="bg-colors-background-functional-solid-danger text--colors-text-neutral-strong">
<AlertDialogAction
className="bg-colors-background-functional-solid-danger text--colors-text-neutral-strong"
onClick={onOk}
>
<Trash2 />
{t('common.ok')}
</AlertDialogAction>
Expand Down
2 changes: 2 additions & 0 deletions web/src/components/parse-configuration/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export const excludedParseMethods = [
'one',
'picture',
'knowledge_graph',
'qa',
'tag',
];

export const showRaptorParseConfiguration = (parserId: string) => {
Expand Down
83 changes: 81 additions & 2 deletions web/src/hooks/knowledge-hooks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import { ResponsePostType } from '@/interfaces/database/base';
import { IKnowledge, ITestingResult } from '@/interfaces/database/knowledge';
import {
IKnowledge,
IRenameTag,
ITestingResult,
} from '@/interfaces/database/knowledge';
import i18n from '@/locales/config';
import kbService from '@/services/knowledge-service';
import kbService, {
listTag,
removeTag,
renameTag,
} from '@/services/knowledge-service';
import {
useInfiniteQuery,
useIsMutating,
Expand Down Expand Up @@ -259,3 +267,74 @@ export const useSelectIsTestingSuccess = () => {
return status.at(-1) === 'success';
};
//#endregion

//#region tags

export const useFetchTagList = () => {
const knowledgeBaseId = useKnowledgeBaseId();

const { data, isFetching: loading } = useQuery<Array<[string, number]>>({
queryKey: ['fetchTagList'],
initialData: [],
gcTime: 0, // https://tanstack.com/query/latest/docs/framework/react/guides/caching?from=reactQueryV3
queryFn: async () => {
const { data } = await listTag(knowledgeBaseId);
const list = data?.data || [];
return list;
},
});

return { list: data, loading };
};

export const useDeleteTag = () => {
const knowledgeBaseId = useKnowledgeBaseId();

const queryClient = useQueryClient();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['deleteTag'],
mutationFn: async (tags: string[]) => {
const { data } = await removeTag(knowledgeBaseId, tags);
if (data.code === 0) {
message.success(i18n.t(`message.deleted`));
queryClient.invalidateQueries({
queryKey: ['fetchTagList'],
});
}
return data?.data ?? [];
},
});

return { data, loading, deleteTag: mutateAsync };
};

export const useRenameTag = () => {
const knowledgeBaseId = useKnowledgeBaseId();

const queryClient = useQueryClient();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['deleteTag'],
mutationFn: async (params: IRenameTag) => {
const { data } = await renameTag(knowledgeBaseId, params);
if (data.code === 0) {
message.success(i18n.t(`message.modified`));
queryClient.invalidateQueries({
queryKey: ['fetchTagList'],
});
}
return data?.data ?? [];
},
});

return { data, loading, renameTag: mutateAsync };
};

//#endregion
2 changes: 2 additions & 0 deletions web/src/interfaces/database/knowledge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,5 @@ export interface ITestingResult {
documents: ITestingDocument[];
total: number;
}

export type IRenameTag = { fromTag: string; toTag: string };
5 changes: 5 additions & 0 deletions web/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default {
pleaseInput: 'Please input',
submit: 'Submit',
embedIntoSite: 'Embed into webpage',
previousPage: 'Previous',
nextPage: 'Next',
},
login: {
login: 'Sign in',
Expand Down Expand Up @@ -308,6 +310,9 @@ The above is the content you need to summarize.`,
vietnamese: 'Vietnamese',
pageRank: 'Page rank',
pageRankTip: `This increases the relevance score of the knowledge base. Its value will be added to the relevance score of all retrieved chunks from this knowledge base. Useful when you are searching within multiple knowledge bases and wanting to assign a higher pagerank score to a specific one.`,
tag: 'Tag',
frequency: 'Frequency',
searchTags: 'Search tags',
},
chunk: {
chunk: 'Chunk',
Expand Down
5 changes: 5 additions & 0 deletions web/src/locales/zh-traditional.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default {
pleaseInput: '請輸入',
submit: '提交',
embedIntoSite: '嵌入網站',
previousPage: '上一頁',
nextPage: '下一頁',
},
login: {
login: '登入',
Expand Down Expand Up @@ -292,6 +294,9 @@ export default {
pageRank: '頁面排名',
pageRankTip: `這用來提高相關性分數。所有檢索到的區塊的相關性得分將加上該數字。
當您想要先搜尋給定的知識庫時,請設定比其他人更高的 pagerank 分數。`,
tag: '標籤',
frequency: '頻次',
searchTags: '搜尋標籤',
},
chunk: {
chunk: '解析塊',
Expand Down
5 changes: 5 additions & 0 deletions web/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export default {
pleaseInput: '请输入',
submit: '提交',
embedIntoSite: '嵌入网站',
previousPage: '上一页',
nextPage: '下一页',
},
login: {
login: '登录',
Expand Down Expand Up @@ -309,6 +311,9 @@ export default {
pageRank: '页面排名',
pageRankTip: `这用于提高相关性得分。所有检索到的块的相关性得分将加上此数字。
当您想首先搜索给定的知识库时,请设置比其他知识库更高的 pagerank 得分。`,
tag: '标签',
frequency: '频次',
searchTags: '搜索标签',
},
chunk: {
chunk: '解析块',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DOMPurify from 'dompurify';
import camelCase from 'lodash/camelCase';
import { useMemo } from 'react';
import styles from './index.less';
import { TagTable } from './tag-table';
import { ImageMap } from './utils';

const { Title, Text } = Typography;
Expand Down Expand Up @@ -68,6 +69,7 @@ const CategoryPanel = ({ chunkMethod }: { chunkMethod: string }) => {
<SvgIcon name={'chunk-method/chunk-empty'} width={'100%'}></SvgIcon>
</Empty>
)}
{chunkMethod === 'tag' && <TagTable></TagTable>}
</section>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { LlmModelType } from '@/constants/knowledge';
import { useSetModalState } from '@/hooks/common-hooks';
import {
useFetchKnowledgeBaseConfiguration,
useRenameTag,
useUpdateKnowledge,
} from '@/hooks/knowledge-hooks';
import { useSelectLlmOptionsByModelType } from '@/hooks/llm-hooks';
Expand All @@ -14,7 +16,7 @@ import { useIsFetching } from '@tanstack/react-query';
import { Form, UploadFile } from 'antd';
import { FormInstance } from 'antd/lib';
import pick from 'lodash/pick';
import { useCallback, useEffect } from 'react';
import { useCallback, useEffect, useState } from 'react';

export const useSubmitKnowledgeConfiguration = (form: FormInstance) => {
const { saveKnowledgeConfiguration, loading } = useUpdateKnowledge();
Expand Down Expand Up @@ -87,3 +89,44 @@ export const useHandleChunkMethodChange = () => {

return { form, chunkMethod };
};

export const useRenameKnowledgeTag = () => {
const [tag, setTag] = useState<string>('');
const {
visible: tagRenameVisible,
hideModal: hideTagRenameModal,
showModal: showFileRenameModal,
} = useSetModalState();
const { renameTag, loading } = useRenameTag();

const onTagRenameOk = useCallback(
async (name: string) => {
const ret = await renameTag({
fromTag: tag,
toTag: name,
});

if (ret === 0) {
hideTagRenameModal();
}
},
[renameTag, tag, hideTagRenameModal],
);

const handleShowTagRenameModal = useCallback(
(record: string) => {
setTag(record);
showFileRenameModal();
},
[showFileRenameModal],
);

return {
renameLoading: loading,
initialName: tag,
onTagRenameOk,
tagRenameVisible,
hideTagRenameModal,
showTagRenameModal: handleShowTagRenameModal,
};
};
Loading

0 comments on commit 5bbfdb1

Please sign in to comment.