From d8f660370f55c5f495f92886217b0a85c588b103 Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Sun, 10 Sep 2023 15:51:32 +0800 Subject: [PATCH] perf: source update --- client/public/locales/en/common.json | 2 + client/public/locales/zh/common.json | 2 + client/src/components/ChatBox/QuoteModal.tsx | 4 +- .../src/components/ChatBox/ResponseTags.tsx | 2 +- .../src/components/Icon/icons/fill/plus.svg | 8 ++ client/src/components/Icon/index.tsx | 3 +- client/src/pages/api/openapi/kb/updateData.ts | 1 - .../app/detail/components/KBSelectModal.tsx | 101 ++++++++++-------- .../pages/kb/detail/components/DataCard.tsx | 2 +- .../kb/detail/components/InputDataModal.tsx | 5 +- client/src/service/models/kb.ts | 3 +- 11 files changed, 78 insertions(+), 55 deletions(-) create mode 100644 client/src/components/Icon/icons/fill/plus.svg diff --git a/client/public/locales/en/common.json b/client/public/locales/en/common.json index 39fa7168f..e32eb5db1 100644 --- a/client/public/locales/en/common.json +++ b/client/public/locales/en/common.json @@ -173,6 +173,8 @@ "Folder Name": "Input folder name", "My Dataset": "My Dataset", "Other Data": "Other Data", + "Select Dataset": "Select Dataset", + "Select Folder": "Enter folder", "Upload Time": "Upload Time", "deleteDatasetTips": "Are you sure to delete the knowledge base? Data cannot be recovered after deletion, please confirm!", "deleteFolderTips": "Are you sure to delete this folder and all the knowledge bases it contains? Data cannot be recovered after deletion, please confirm!" diff --git a/client/public/locales/zh/common.json b/client/public/locales/zh/common.json index 7554e62c8..5bde238de 100644 --- a/client/public/locales/zh/common.json +++ b/client/public/locales/zh/common.json @@ -173,6 +173,8 @@ "Folder Name": "输入文件夹名称", "My Dataset": "我的知识库", "Other Data": "其他数据", + "Select Dataset": "选择该知识库", + "Select Folder": "进入文件夹", "Upload Time": "上传时间", "deleteDatasetTips": "确认删除该知识库?删除后数据无法恢复,请确认!", "deleteFolderTips": "确认删除该文件夹及其包含的所有知识库?删除后数据无法恢复,请确认!" diff --git a/client/src/components/ChatBox/QuoteModal.tsx b/client/src/components/ChatBox/QuoteModal.tsx index 2096b4a9f..4e75016c6 100644 --- a/client/src/components/ChatBox/QuoteModal.tsx +++ b/client/src/components/ChatBox/QuoteModal.tsx @@ -19,7 +19,7 @@ const QuoteModal = ({ rawSearch = [], onClose }: { - onUpdateQuote: (quoteId: string, sourceText: string) => Promise; + onUpdateQuote: (quoteId: string, sourceText?: string) => Promise; rawSearch: SearchType[]; onClose: () => void; }) => { @@ -129,7 +129,7 @@ const QuoteModal = ({ {editDataItem && ( setEditDataItem(undefined)} - onSuccess={() => onUpdateQuote(editDataItem.id, '手动修改')} + onSuccess={() => onUpdateQuote(editDataItem.id)} onDelete={() => onUpdateQuote(editDataItem.id, '已删除')} kbId={editDataItem.kb_id} defaultValues={{ diff --git a/client/src/components/ChatBox/ResponseTags.tsx b/client/src/components/ChatBox/ResponseTags.tsx index 722f4d217..0f68360eb 100644 --- a/client/src/components/ChatBox/ResponseTags.tsx +++ b/client/src/components/ChatBox/ResponseTags.tsx @@ -44,7 +44,7 @@ const ResponseTags = ({ }; }, [responseData]); - const updateQuote = useCallback(async (quoteId: string, sourceText: string) => {}, []); + const updateQuote = useCallback(async (quoteId: string, sourceText?: string) => {}, []); const TagStyles: BoxProps = { mr: 2, diff --git a/client/src/components/Icon/icons/fill/plus.svg b/client/src/components/Icon/icons/fill/plus.svg new file mode 100644 index 000000000..528d8b162 --- /dev/null +++ b/client/src/components/Icon/icons/fill/plus.svg @@ -0,0 +1,8 @@ + + + + \ No newline at end of file diff --git a/client/src/components/Icon/index.tsx b/client/src/components/Icon/index.tsx index 3f6cb75a4..cd1167aba 100644 --- a/client/src/components/Icon/index.tsx +++ b/client/src/components/Icon/index.tsx @@ -82,7 +82,8 @@ const map = { markLight: require('./icons/light/mark.svg').default, retryLight: require('./icons/light/retry.svg').default, rightArrowLight: require('./icons/light/rightArrow.svg').default, - searchLight: require('./icons/light/search.svg').default + searchLight: require('./icons/light/search.svg').default, + plusFill: require('./icons/fill/plus.svg').default }; export type IconName = keyof typeof map; diff --git a/client/src/pages/api/openapi/kb/updateData.ts b/client/src/pages/api/openapi/kb/updateData.ts index 675295350..eca98af87 100644 --- a/client/src/pages/api/openapi/kb/updateData.ts +++ b/client/src/pages/api/openapi/kb/updateData.ts @@ -50,7 +50,6 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex await PgClient.update(PgTrainingTableName, { where: [['id', dataId], 'AND', ['user_id', userId]], values: [ - { key: 'source', value: '手动修改' }, { key: 'a', value: a.replace(/'/g, '"') }, ...(q ? [ diff --git a/client/src/pages/app/detail/components/KBSelectModal.tsx b/client/src/pages/app/detail/components/KBSelectModal.tsx index b4d00c357..2cb4519ad 100644 --- a/client/src/pages/app/detail/components/KBSelectModal.tsx +++ b/client/src/pages/app/detail/components/KBSelectModal.tsx @@ -173,52 +173,65 @@ export const KBSelectModal = ({ {filterKbList.unSelected.map((item) => (() => { return ( - { - if (item.type === KbTypeEnum.folder) { - setParentId(item._id); - } else if (item.type === KbTypeEnum.dataset) { - const vectorModel = selectedKbList[0]?.vectorModel?.model; - - if (vectorModel && vectorModel !== item.vectorModel.model) { - return toast({ - status: 'warning', - title: '仅能选择同一个索引模型的知识库' - }); - } - setSelectedKbList((state) => [ - ...state, - { kbId: item._id, vectorModel: item.vectorModel } - ]); - } - }} + label={ + item.type === KbTypeEnum.dataset + ? t('kb.Select Dataset') + : t('kb.Select Folder') + } > - - - - {item.name} - - - - {item.type === KbTypeEnum.folder ? ( - {t('Folder')} - ) : ( - <> - - {item.vectorModel.name} - - )} - - + { + if (item.type === KbTypeEnum.folder) { + setParentId(item._id); + } else if (item.type === KbTypeEnum.dataset) { + const vectorModel = selectedKbList[0]?.vectorModel?.model; + + if (vectorModel && vectorModel !== item.vectorModel.model) { + return toast({ + status: 'warning', + title: '仅能选择同一个索引模型的知识库' + }); + } + setSelectedKbList((state) => [ + ...state, + { kbId: item._id, vectorModel: item.vectorModel } + ]); + } + }} + > + + + + {item.name} + + + + {item.type === KbTypeEnum.folder ? ( + {t('Folder')} + ) : ( + <> + + {item.vectorModel.name} + + )} + + + ); })() )} diff --git a/client/src/pages/kb/detail/components/DataCard.tsx b/client/src/pages/kb/detail/components/DataCard.tsx index a22b9fbdf..3d95e74fb 100644 --- a/client/src/pages/kb/detail/components/DataCard.tsx +++ b/client/src/pages/kb/detail/components/DataCard.tsx @@ -238,7 +238,7 @@ const DataCard = ({ kbId }: { kbId: string }) => { - {item.source?.trim()} + ID:{item.id} { try { const url = await getFileViewUrl(fileId); diff --git a/client/src/service/models/kb.ts b/client/src/service/models/kb.ts index a1f9bea2a..eb8e74072 100644 --- a/client/src/service/models/kb.ts +++ b/client/src/service/models/kb.ts @@ -33,7 +33,8 @@ const kbSchema = new Schema({ type: { type: String, enum: Object.keys(KbTypeMap), - required: true + required: true, + default: 'dataset' }, tags: { type: [String],