From 9b9b6d5408d35ed8fbc30030333004524b2945e9 Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 3 Apr 2024 11:21:54 +0800 Subject: [PATCH] fix: #209 after saving the knowledge base configuration, jump to the dataset page (#212) ### What problem does this PR solve? fix: #209 after saving the knowledge base configuration, jump to the dataset page feat: translate ConfigurationForm feat: translate KnowledgeTesting feat: translate document list page feat: translate knowledge list page Issue link: #209 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- .../components/chunk-method-modal/index.tsx | 4 +- .../components/similarity-slider/index.tsx | 17 +- web/src/hooks/commonHooks.tsx | 8 +- web/src/hooks/routeHook.ts | 14 +- web/src/locales/config.ts | 8 +- web/src/locales/en.json | 166 +++++++++++++----- web/src/locales/zh.json | 38 ++-- .../components/knowledge-file/index.tsx | 34 ++-- .../parsing-action-cell/index.tsx | 8 +- .../parsing-status-cell/index.tsx | 9 +- .../knowledge-file/rename-modal/index.tsx | 9 +- .../knowledge-setting/configuration.tsx | 63 +++---- .../components/knowledge-setting/hooks.ts | 27 +-- .../components/knowledge-setting/index.tsx | 8 +- .../components/knowledge-sidebar/index.tsx | 16 +- .../testing-control/index.tsx | 22 ++- .../testing-result/index.tsx | 23 ++- web/src/pages/add-knowledge/index.tsx | 12 +- .../pages/knowledge/knowledge-card/index.tsx | 9 +- 19 files changed, 299 insertions(+), 196 deletions(-) diff --git a/web/src/components/chunk-method-modal/index.tsx b/web/src/components/chunk-method-modal/index.tsx index a74e24e22..759541196 100644 --- a/web/src/components/chunk-method-modal/index.tsx +++ b/web/src/components/chunk-method-modal/index.tsx @@ -22,6 +22,7 @@ import omit from 'lodash/omit'; import React, { useEffect, useMemo } from 'react'; import { useFetchParserListOnMount } from './hooks'; +import { useTranslate } from '@/hooks/commonHooks'; import styles from './index.less'; const { CheckableTag } = Tag; @@ -56,6 +57,7 @@ const ChunkMethodModal: React.FC = ({ documentExtension, ); const [form] = Form.useForm(); + const { t } = useTranslate('knowledgeDetails'); const handleOk = async () => { const values = await form.validateFields(); @@ -91,7 +93,7 @@ const ChunkMethodModal: React.FC = ({ return ( { + const { t } = useTranslate('knowledgeDetails'); + return ( <> - label="Similarity threshold" + label={t('similarityThreshold')} name={'similarity_threshold'} - tooltip={isTooltipShown && `We use hybrid similarity score to evaluate distance between two lines of text. - It\'s weighted keywords similarity and vector cosine similarity. - If the similarity between query and chunk is less than this threshold, the chunk will be filtered out.` - } + tooltip={isTooltipShown && t('similarityThresholdTip')} initialValue={0.2} > - label="Vector similarity weight" + label={t('vectorSimilarityWeight')} name={'vector_similarity_weight'} initialValue={0.3} - tooltip={isTooltipShown && `We use hybrid similarity score to evaluate distance between two lines of text. - It\'s weighted keywords similarity and vector cosine similarity. - The sum of both weights is 1.0. - `} + tooltip={isTooltipShown && t('vectorSimilarityWeightTip')} > diff --git a/web/src/hooks/commonHooks.tsx b/web/src/hooks/commonHooks.tsx index b087fb95b..4125cd7cd 100644 --- a/web/src/hooks/commonHooks.tsx +++ b/web/src/hooks/commonHooks.tsx @@ -92,9 +92,9 @@ export const useShowDeleteConfirm = () => { title: t('common.deleteModalTitle'), icon: , // content: 'Some descriptions', - okText: 'Yes', + okText: t('common.ok'), okType: 'danger', - cancelText: 'No', + cancelText: t('common.cancel'), async onOk() { try { const ret = await onOk?.(); @@ -115,3 +115,7 @@ export const useShowDeleteConfirm = () => { return showDeleteConfirm; }; + +export const useTranslate = (keyPrefix: string) => { + return useTranslation('translation', { keyPrefix }); +}; diff --git a/web/src/hooks/routeHook.ts b/web/src/hooks/routeHook.ts index 21829fde4..03ed287a2 100644 --- a/web/src/hooks/routeHook.ts +++ b/web/src/hooks/routeHook.ts @@ -1,4 +1,7 @@ -import { KnowledgeSearchParams } from '@/constants/knowledge'; +import { + KnowledgeRouteKey, + KnowledgeSearchParams, +} from '@/constants/knowledge'; import { useCallback } from 'react'; import { useLocation, useNavigate, useSearchParams } from 'umi'; @@ -42,3 +45,12 @@ export const useNavigateWithFromState = () => { [navigate], ); }; + +export const useNavigateToDataset = () => { + const navigate = useNavigate(); + const { knowledgeId } = useGetKnowledgeSearchParams(); + + return useCallback(() => { + navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${knowledgeId}`); + }, [knowledgeId, navigate]); +}; diff --git a/web/src/locales/config.ts b/web/src/locales/config.ts index b127f9147..311f5d200 100644 --- a/web/src/locales/config.ts +++ b/web/src/locales/config.ts @@ -5,12 +5,8 @@ import translation_en from './en.json'; import translation_zh from './zh.json'; const resources = { - en: { - translation: translation_en, - }, - zh: { - translation: translation_zh, - }, + en: translation_en, + zh: translation_zh, }; i18n.use(initReactI18next).init({ diff --git a/web/src/locales/en.json b/web/src/locales/en.json index 705e7fb8e..027d7b7ec 100644 --- a/web/src/locales/en.json +++ b/web/src/locales/en.json @@ -1,50 +1,122 @@ { - "common": { - "delete": "Delete", - "deleteModalTitle": "Are you sure delete this item?" - }, - "login": { - "login": "Sign in", - "signUp": "Sign up", - "loginDescription": "We’re so excited to see you again!", - "registerDescription": "Glad to have you on board!", - "emailLabel": "Email", - "emailPlaceholder": "Please input email", - "passwordLabel": "Password", - "passwordPlaceholder": "Please input password", - "rememberMe": "Remember me", - "signInTip": "Don’t have an account?", - "signUpTip": "Already have an account?", - "nicknameLabel": "Nickname", - "nicknamePlaceholder": "Please input nickname", - "register": "Create an account", - "continue": "Continue" - }, - "header": { - "knowledgeBase": "Knowledge Base", - "chat": "Chat", - "register": "Register", - "signin": "Sign in", - "home": "Home", - "setting": "用户设置", - "logout": "登出" - }, - "knowledgeList": { - "welcome": "Welcome back", - "description": "Which database are we going to use today?", - "createKnowledgeBase": "Create knowledge base", - "name": "Name", - "namePlaceholder": "Please input name!" - }, - "footer": { - "detail": "All rights reserved @ React" - }, - "layout": { - "file": "file", - "knowledge": "knowledge", - "chat": "chat" - }, - "setting": { - "btn": "en" + "translation": { + "common": { + "delete": "Delete", + "deleteModalTitle": "Are you sure delete this item?", + "ok": "Yes", + "cancel": "No", + "total": "Total", + "rename": "Rename", + "name": "Name", + "namePlaceholder": "Please input name" + }, + "login": { + "login": "Sign in", + "signUp": "Sign up", + "loginDescription": "We’re so excited to see you again!", + "registerDescription": "Glad to have you on board!", + "emailLabel": "Email", + "emailPlaceholder": "Please input email", + "passwordLabel": "Password", + "passwordPlaceholder": "Please input password", + "rememberMe": "Remember me", + "signInTip": "Don’t have an account?", + "signUpTip": "Already have an account?", + "nicknameLabel": "Nickname", + "nicknamePlaceholder": "Please input nickname", + "register": "Create an account", + "continue": "Continue" + }, + "header": { + "knowledgeBase": "Knowledge Base", + "chat": "Chat", + "register": "Register", + "signin": "Sign in", + "home": "Home", + "setting": "用户设置", + "logout": "登出" + }, + "knowledgeList": { + "welcome": "Welcome back", + "description": "Which database are we going to use today?", + "createKnowledgeBase": "Create knowledge base", + "name": "Name", + "namePlaceholder": "Please input name!", + "doc": "Docs" + }, + "knowledgeDetails": { + "dataset": "Dataset", + "testing": "Retrieval testing", + "configuration": "Configuration", + "name": "Name", + "namePlaceholder": "Please input name!", + "doc": "Docs", + "datasetDescription": "Hey, don't forget to adjust the chunk after adding the dataset! 😉", + "addFile": "Add file", + "searchFiles": "Search your files", + "localFiles": "Local files", + "emptyFiles": "Create empty file", + "chunkNumber": "Chunk Number", + "uploadDate": "Upload Date", + "chunkMethod": "Chunk Method", + "enabled": "Enabled", + "action": "Action", + "parsingStatus": "Parsing Status", + "processBeginAt": "Process Begin At", + "processDuration": "Process Duration", + "progressMsg": "Progress Msg", + "testingDescription": "Final step! After success, leave the rest to Infiniflow AI.", + "topK": "Top K", + "topKTip": "For the computaion cost, not all the retrieved chunk will be computed vector cosine similarity with query. The bigger the 'Top K' is, the higher the recall rate is, the slower the retrieval speed is.", + "similarityThreshold": "Similarity threshold", + "similarityThresholdTip": "We use hybrid similarity score to evaluate distance between two lines of text. It's weighted keywords similarity and vector cosine similarity. If the similarity between query and chunk is less than this threshold, the chunk will be filtered out.", + "vectorSimilarityWeight": "Vector similarity weight", + "vectorSimilarityWeightTip": "We use hybrid similarity score to evaluate distance between two lines of text. It's weighted keywords similarity and vector cosine similarity. The sum of both weights is 1.0.", + "testText": "Test text", + "testTextPlaceholder": "Please input your question!", + "testingLabel": "Testing", + "similarity": "Hybrid Similarity", + "termSimilarity": "Term Similarity", + "vectorSimilarity": "Vector Similarity", + "hits": "Hits", + "view": "View", + "filesSelected": "Files Selected" + }, + "knowledgeConfiguration": { + "titleDescription": "Update your knowledge base details especially parsing method here.", + "name": "Knowledge base name", + "photo": "Knowledge base photo", + "description": "Description", + "language": "Language", + "languageMessage": "Please input your language!", + "languagePlaceholder": "Please input your language!", + "permissions": "Permissions", + "embeddingModel": "Embedding model", + "chunkTokenNumber": "Chunk token number", + "embeddingModelTip": "The embedding model used to embedding chunks. It's unchangable once the knowledgebase has chunks. You need to delete all the chunks if you want to change it.", + "permissionsTip": "If the permission is 'Team', all the team member can manipulate the knowledgebase.", + "chunkTokenNumberTip": "It determine the token number of a chunk approximately.", + "chunkMethodTip": "The instruction is at right.", + "upload": "Upload", + "english": "English", + "chinese": "Chinese", + "embeddingModelPlaceholder": "Please select a embedding model", + "chunkMethodPlaceholder": "Please select a chunk method", + "save": "Save", + "me": "Only me", + "team": "Team", + "cancel": "Cancel" + }, + "footer": { + "detail": "All rights reserved @ React" + }, + "layout": { + "file": "file", + "knowledge": "knowledge", + "chat": "chat" + }, + "setting": { + "btn": "en" + } } } diff --git a/web/src/locales/zh.json b/web/src/locales/zh.json index 7eb7974a0..a6fd83502 100644 --- a/web/src/locales/zh.json +++ b/web/src/locales/zh.json @@ -1,21 +1,23 @@ { - "login": { "login": "登录" }, - "header": { - "register": "注册", - "signin": "登陆", - "home": "首页", - "setting": "user setting", - "logout": "logout" - }, - "footer": { - "detail": "版权所有 @ React" - }, - "layout": { - "file": "文件", - "knowledge": "知识库", - "chat": "聊天" - }, - "setting": { - "btn": "中文" + "translation": { + "login": { "login": "登录" }, + "header": { + "register": "注册", + "signin": "登陆", + "home": "首页", + "setting": "user setting", + "logout": "logout" + }, + "footer": { + "detail": "版权所有 @ React" + }, + "layout": { + "file": "文件", + "knowledge": "知识库", + "chat": "聊天" + }, + "setting": { + "btn": "中文" + } } } diff --git a/web/src/pages/add-knowledge/components/knowledge-file/index.tsx b/web/src/pages/add-knowledge/components/knowledge-file/index.tsx index 68666a0fa..a520a90db 100644 --- a/web/src/pages/add-knowledge/components/knowledge-file/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-file/index.tsx @@ -42,6 +42,7 @@ import ParsingStatusCell from './parsing-status-cell'; import RenameModal from './rename-modal'; import { useSetSelectedRecord } from '@/hooks/logicHooks'; +import { useTranslation } from 'react-i18next'; import styles from './index.less'; const KnowledgeFile = () => { @@ -76,6 +77,9 @@ const KnowledgeFile = () => { hideChangeParserModal, showChangeParserModal, } = useChangeDocumentParser(currentRecord.id); + const { t } = useTranslation('translation', { + keyPrefix: 'knowledgeDetails', + }); const actionItems: MenuProps['items'] = useMemo(() => { return [ @@ -87,7 +91,7 @@ const KnowledgeFile = () => { @@ -101,18 +105,18 @@ const KnowledgeFile = () => {
), // disabled: true, }, ]; - }, [linkToUploadPage, showCreateModal]); + }, [linkToUploadPage, showCreateModal, t]); const columns: ColumnsType = [ { - title: 'Name', + title: t('name'), dataIndex: 'name', key: 'name', fixed: 'left', @@ -133,17 +137,17 @@ const KnowledgeFile = () => { ), }, { - title: 'Chunk Number', + title: t('chunkNumber'), dataIndex: 'chunk_num', key: 'chunk_num', }, { - title: 'Upload Date', + title: t('uploadDate'), dataIndex: 'create_date', key: 'create_date', }, { - title: 'Chunk Method', + title: t('chunkMethod'), dataIndex: 'parser_id', key: 'parser_id', render: (text) => { @@ -151,7 +155,7 @@ const KnowledgeFile = () => { }, }, { - title: 'Enabled', + title: t('enabled'), key: 'status', dataIndex: 'status', render: (_, { status, id }) => ( @@ -166,7 +170,7 @@ const KnowledgeFile = () => { ), }, { - title: 'Parsing Status', + title: t('parsingStatus'), dataIndex: 'run', key: 'run', render: (text, record) => { @@ -174,7 +178,7 @@ const KnowledgeFile = () => { }, }, { - title: 'Action', + title: t('action'), key: 'action', render: (_, record) => ( { return (
-

Dataset

-

Hey, don't forget to adjust the chunk after adding the dataset! 😉

+

{t('dataset')}

+

{t('datasetDescription')}

-

Total

+

{t('total', { keyPrefix: 'common' })}

{total} files
{ diff --git a/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx index 480fa1537..d546621af 100644 --- a/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx @@ -1,4 +1,4 @@ -import { useShowDeleteConfirm } from '@/hooks/commonHooks'; +import { useShowDeleteConfirm, useTranslate } from '@/hooks/commonHooks'; import { useRemoveDocument } from '@/hooks/documentHooks'; import { IKnowledgeFile } from '@/interfaces/database/knowledge'; import { api_host } from '@/utils/api'; @@ -29,7 +29,7 @@ const ParsingActionCell = ({ }: IProps) => { const documentId = record.id; const isRunning = isParserRunning(record.run); - + const { t } = useTranslate('knowledgeDetails'); const removeDocument = useRemoveDocument(documentId); const showDeleteConfirm = useShowDeleteConfirm(); @@ -65,7 +65,7 @@ const ParsingActionCell = ({ label: (
), @@ -83,7 +83,7 @@ const ParsingActionCell = ({ - + - + - + + - Only me - Team + {t('me')} + {t('team')} @@ -96,10 +83,10 @@ const ConfigurationForm = ({ form }: { form: FormInstance }) => { - {parserList.map((x) => (