balibabu
commited on
Commit
·
26d72b4
1
Parent(s):
fe09cc5
Feat: Metadata in documents for improve the prompt #3690 (#4462)
Browse files### What problem does this PR solve?
Feat: Metadata in documents for improve the prompt #3690
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/hooks/document-hooks.ts +37 -9
- web/src/interfaces/database/document.ts +1 -0
- web/src/interfaces/request/document.ts +5 -0
- web/src/locales/en.ts +22 -0
- web/src/locales/zh-traditional.ts +21 -0
- web/src/locales/zh.ts +22 -0
- web/src/pages/add-knowledge/components/knowledge-file/hooks.ts +32 -0
- web/src/pages/add-knowledge/components/knowledge-file/index.tsx +20 -0
- web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx +22 -3
- web/src/pages/add-knowledge/components/knowledge-file/set-meta-modal/index.tsx +81 -0
- web/src/services/knowledge-service.ts +6 -1
- web/src/utils/api.ts +1 -0
web/src/hooks/document-hooks.ts
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import { IReferenceChunk } from '@/interfaces/database/chat';
|
2 |
import { IDocumentInfo } from '@/interfaces/database/document';
|
3 |
import { IChunk } from '@/interfaces/database/knowledge';
|
4 |
-
import {
|
|
|
|
|
|
|
5 |
import i18n from '@/locales/config';
|
6 |
import chatService from '@/services/chat-service';
|
7 |
import kbService from '@/services/knowledge-service';
|
@@ -396,7 +399,6 @@ export const useRemoveNextDocument = () => {
|
|
396 |
};
|
397 |
|
398 |
export const useDeleteDocument = () => {
|
399 |
-
// const queryClient = useQueryClient();
|
400 |
const {
|
401 |
data,
|
402 |
isPending: loading,
|
@@ -405,9 +407,7 @@ export const useDeleteDocument = () => {
|
|
405 |
mutationKey: ['deleteDocument'],
|
406 |
mutationFn: async (documentIds: string[]) => {
|
407 |
const data = await kbService.document_delete({ doc_ids: documentIds });
|
408 |
-
|
409 |
-
// queryClient.invalidateQueries({ queryKey: ['fetchFlowList'] });
|
410 |
-
// }
|
411 |
return data;
|
412 |
},
|
413 |
});
|
@@ -441,9 +441,7 @@ export const useUploadAndParseDocument = (uploadMethod: string) => {
|
|
441 |
}
|
442 |
const data = await chatService.uploadAndParseExternal(formData);
|
443 |
return data?.data;
|
444 |
-
} catch (error) {
|
445 |
-
console.log('🚀 ~ useUploadAndParseDocument ~ error:', error);
|
446 |
-
}
|
447 |
},
|
448 |
});
|
449 |
|
@@ -465,7 +463,6 @@ export const useParseDocument = () => {
|
|
465 |
}
|
466 |
return data;
|
467 |
} catch (error) {
|
468 |
-
console.log('🚀 ~ mutationFn: ~ error:', error);
|
469 |
message.error('error');
|
470 |
}
|
471 |
},
|
@@ -473,3 +470,34 @@ export const useParseDocument = () => {
|
|
473 |
|
474 |
return { parseDocument: mutateAsync, data, loading };
|
475 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import { IReferenceChunk } from '@/interfaces/database/chat';
|
2 |
import { IDocumentInfo } from '@/interfaces/database/document';
|
3 |
import { IChunk } from '@/interfaces/database/knowledge';
|
4 |
+
import {
|
5 |
+
IChangeParserConfigRequestBody,
|
6 |
+
IDocumentMetaRequestBody,
|
7 |
+
} from '@/interfaces/request/document';
|
8 |
import i18n from '@/locales/config';
|
9 |
import chatService from '@/services/chat-service';
|
10 |
import kbService from '@/services/knowledge-service';
|
|
|
399 |
};
|
400 |
|
401 |
export const useDeleteDocument = () => {
|
|
|
402 |
const {
|
403 |
data,
|
404 |
isPending: loading,
|
|
|
407 |
mutationKey: ['deleteDocument'],
|
408 |
mutationFn: async (documentIds: string[]) => {
|
409 |
const data = await kbService.document_delete({ doc_ids: documentIds });
|
410 |
+
|
|
|
|
|
411 |
return data;
|
412 |
},
|
413 |
});
|
|
|
441 |
}
|
442 |
const data = await chatService.uploadAndParseExternal(formData);
|
443 |
return data?.data;
|
444 |
+
} catch (error) {}
|
|
|
|
|
445 |
},
|
446 |
});
|
447 |
|
|
|
463 |
}
|
464 |
return data;
|
465 |
} catch (error) {
|
|
|
466 |
message.error('error');
|
467 |
}
|
468 |
},
|
|
|
470 |
|
471 |
return { parseDocument: mutateAsync, data, loading };
|
472 |
};
|
473 |
+
|
474 |
+
export const useSetDocumentMeta = () => {
|
475 |
+
const queryClient = useQueryClient();
|
476 |
+
|
477 |
+
const {
|
478 |
+
data,
|
479 |
+
isPending: loading,
|
480 |
+
mutateAsync,
|
481 |
+
} = useMutation({
|
482 |
+
mutationKey: ['setDocumentMeta'],
|
483 |
+
mutationFn: async (params: IDocumentMetaRequestBody) => {
|
484 |
+
try {
|
485 |
+
const { data } = await kbService.setMeta({
|
486 |
+
meta: params.meta,
|
487 |
+
doc_id: params.documentId,
|
488 |
+
});
|
489 |
+
|
490 |
+
if (data?.code === 0) {
|
491 |
+
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
|
492 |
+
|
493 |
+
message.success(i18n.t('message.modified'));
|
494 |
+
}
|
495 |
+
return data?.code;
|
496 |
+
} catch (error) {
|
497 |
+
message.error('error');
|
498 |
+
}
|
499 |
+
},
|
500 |
+
});
|
501 |
+
|
502 |
+
return { setDocumentMeta: mutateAsync, data, loading };
|
503 |
+
};
|
web/src/interfaces/database/document.ts
CHANGED
@@ -24,6 +24,7 @@ export interface IDocumentInfo {
|
|
24 |
type: string;
|
25 |
update_date: string;
|
26 |
update_time: number;
|
|
|
27 |
}
|
28 |
|
29 |
export interface IParserConfig {
|
|
|
24 |
type: string;
|
25 |
update_date: string;
|
26 |
update_time: number;
|
27 |
+
meta_fields?: Record<string, any>;
|
28 |
}
|
29 |
|
30 |
export interface IParserConfig {
|
web/src/interfaces/request/document.ts
CHANGED
@@ -10,3 +10,8 @@ export interface IChangeParserRequestBody {
|
|
10 |
doc_id: string;
|
11 |
parser_config: IChangeParserConfigRequestBody;
|
12 |
}
|
|
|
|
|
|
|
|
|
|
|
|
10 |
doc_id: string;
|
11 |
parser_config: IChangeParserConfigRequestBody;
|
12 |
}
|
13 |
+
|
14 |
+
export interface IDocumentMetaRequestBody {
|
15 |
+
documentId: string;
|
16 |
+
meta: string; // json format string
|
17 |
+
}
|
web/src/locales/en.ts
CHANGED
@@ -169,6 +169,28 @@ export default {
|
|
169 |
autoQuestions: 'Auto-question',
|
170 |
autoQuestionsTip: `Automatically extract N questions for each chunk to increase their ranking for queries containing those questions. You can check or update the added questions for a chunk from the chunk list. This feature will not disrupt the chunking process if an error occurs, except that it may add an empty result to the original chunk. Be aware that extra tokens will be consumed by the LLM specified in 'System model settings'.`,
|
171 |
redo: 'Do you want to clear the existing {{chunkNum}} chunks?',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
172 |
},
|
173 |
knowledgeConfiguration: {
|
174 |
titleDescription:
|
|
|
169 |
autoQuestions: 'Auto-question',
|
170 |
autoQuestionsTip: `Automatically extract N questions for each chunk to increase their ranking for queries containing those questions. You can check or update the added questions for a chunk from the chunk list. This feature will not disrupt the chunking process if an error occurs, except that it may add an empty result to the original chunk. Be aware that extra tokens will be consumed by the LLM specified in 'System model settings'.`,
|
171 |
redo: 'Do you want to clear the existing {{chunkNum}} chunks?',
|
172 |
+
setMetaData: 'Set Meta Data',
|
173 |
+
pleaseInputJson: 'Please enter JSON',
|
174 |
+
documentMetaTips: `<p>The meta data is in Json format(it's not searchable). It will be added into prompt for LLM if any chunks of this document are included in the prompt.</p>
|
175 |
+
<p>Examples:</p>
|
176 |
+
<b>The meta data is:</b><br>
|
177 |
+
<code>
|
178 |
+
{
|
179 |
+
"Author": "Alex Dowson",
|
180 |
+
"Date": "2024-11-12"
|
181 |
+
}
|
182 |
+
</code><br>
|
183 |
+
<b>The prompt will be:</b><br>
|
184 |
+
<p>Document: the_name_of_document</p>
|
185 |
+
<p>Author: Alex Dowson</p>
|
186 |
+
<p>Date: 2024-11-12</p>
|
187 |
+
<p>Relevant fragments as following:</p>
|
188 |
+
<ul>
|
189 |
+
<li> Here is the chunk content....</li>
|
190 |
+
<li> Here is the chunk content....</li>
|
191 |
+
</ul>
|
192 |
+
`,
|
193 |
+
metaData: 'Meta data',
|
194 |
},
|
195 |
knowledgeConfiguration: {
|
196 |
titleDescription:
|
web/src/locales/zh-traditional.ts
CHANGED
@@ -165,6 +165,27 @@ export default {
|
|
165 |
autoQuestions: '自動問題',
|
166 |
autoQuestionsTip: `在查詢此類問題時,為每個區塊提取 N 個問題以提高其排名分數。在「系統模型設定」中設定的 LLM 將消耗額外的 token。您可以在區塊清單中查看結果。如果發生錯誤,此功能不會破壞整個分塊過程,除了將空結果新增至原始區塊。 `,
|
167 |
redo: '是否清空已有 {{chunkNum}}個 chunk?',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
168 |
},
|
169 |
knowledgeConfiguration: {
|
170 |
titleDescription: '在這裡更新您的知識庫詳細信息,尤其是解析方法。',
|
|
|
165 |
autoQuestions: '自動問題',
|
166 |
autoQuestionsTip: `在查詢此類問題時,為每個區塊提取 N 個問題以提高其排名分數。在「系統模型設定」中設定的 LLM 將消耗額外的 token。您可以在區塊清單中查看結果。如果發生錯誤,此功能不會破壞整個分塊過程,除了將空結果新增至原始區塊。 `,
|
167 |
redo: '是否清空已有 {{chunkNum}}個 chunk?',
|
168 |
+
setMetaData: '設定元數據',
|
169 |
+
pleaseInputJson: '請輸入JSON',
|
170 |
+
documentMetaTips: `<p>元資料為 Json 格式(不可搜尋)。如果提示中包含該文件的任何部分,它將被添加到 LLM 提示中。
|
171 |
+
<p>範例:</p>
|
172 |
+
<b>元資料是:</b><br>
|
173 |
+
<code>
|
174 |
+
{
|
175 |
+
"Author": "Alex Dowson",
|
176 |
+
"Date": "2024-11-12"
|
177 |
+
}
|
178 |
+
</code><br>
|
179 |
+
<b>提示將是:</b><br>
|
180 |
+
<p>文檔:文檔名稱</p>
|
181 |
+
<p>作者:Alex Dowson</p>
|
182 |
+
<p>日期:2024-11-12</p>
|
183 |
+
<p>相關片段如下:</p>
|
184 |
+
<ul>
|
185 |
+
<li>這是區塊內容....</li>
|
186 |
+
<li>這是區塊內容....</li>
|
187 |
+
</ul>
|
188 |
+
`,
|
189 |
},
|
190 |
knowledgeConfiguration: {
|
191 |
titleDescription: '在這裡更新您的知識庫詳細信息,尤其是解析方法。',
|
web/src/locales/zh.ts
CHANGED
@@ -166,6 +166,28 @@ export default {
|
|
166 |
autoQuestions: '自动问题',
|
167 |
autoQuestionsTip: `在查询此类问题时,为每个块提取 N 个问题以提高其排名得分。在“系统模型设置”中设置的 LLM 将消耗额外的 token。您可以在块列表中查看结果。如果发生错误,此功能不会破坏整个分块过程,除了将空结果添加到原始块。`,
|
168 |
redo: '是否清空已有 {{chunkNum}}个 chunk?',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
169 |
},
|
170 |
knowledgeConfiguration: {
|
171 |
titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
|
|
|
166 |
autoQuestions: '自动问题',
|
167 |
autoQuestionsTip: `在查询此类问题时,为每个块提取 N 个问题以提高其排名得分。在“系统模型设置”中设置的 LLM 将消耗额外的 token。您可以在块列表中查看结果。如果发生错误,此功能不会破坏整个分块过程,除了将空结果添加到原始块。`,
|
168 |
redo: '是否清空已有 {{chunkNum}}个 chunk?',
|
169 |
+
setMetaData: '设置元数据',
|
170 |
+
pleaseInputJson: '请输入JSON',
|
171 |
+
documentMetaTips: `<p>元数据为 Json 格式(不可搜索)。如果提示中包含此文档的任何块,它将被添加到 LLM 的提示中。</p>
|
172 |
+
<p>示例:</p>
|
173 |
+
<b>元数据为:</b><br>
|
174 |
+
<code>
|
175 |
+
{
|
176 |
+
“作者”:“Alex Dowson”,
|
177 |
+
“日期”:“2024-11-12”
|
178 |
+
}
|
179 |
+
</code><br>
|
180 |
+
<b>提示将为:</b><br>
|
181 |
+
<p>文档:the_name_of_document</p>
|
182 |
+
<p>作者:Alex Dowson</p>
|
183 |
+
<p>日期:2024-11-12</p>
|
184 |
+
<p>相关片段如下:</p>
|
185 |
+
<ul>
|
186 |
+
<li> 这是块内容....</li>
|
187 |
+
<li> 这是块内容....</li>
|
188 |
+
</ul>
|
189 |
+
`,
|
190 |
+
metaData: '元資料',
|
191 |
},
|
192 |
knowledgeConfiguration: {
|
193 |
titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
|
web/src/pages/add-knowledge/components/knowledge-file/hooks.ts
CHANGED
@@ -4,6 +4,7 @@ import {
|
|
4 |
useNextWebCrawl,
|
5 |
useRunNextDocument,
|
6 |
useSaveNextDocumentName,
|
|
|
7 |
useSetNextDocumentParser,
|
8 |
useUploadNextDocument,
|
9 |
} from '@/hooks/document-hooks';
|
@@ -236,3 +237,34 @@ export const useHandleRunDocumentByIds = (id: string) => {
|
|
236 |
loading: isLoading,
|
237 |
};
|
238 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
useNextWebCrawl,
|
5 |
useRunNextDocument,
|
6 |
useSaveNextDocumentName,
|
7 |
+
useSetDocumentMeta,
|
8 |
useSetNextDocumentParser,
|
9 |
useUploadNextDocument,
|
10 |
} from '@/hooks/document-hooks';
|
|
|
237 |
loading: isLoading,
|
238 |
};
|
239 |
};
|
240 |
+
|
241 |
+
export const useShowMetaModal = (documentId: string) => {
|
242 |
+
const { setDocumentMeta, loading } = useSetDocumentMeta();
|
243 |
+
|
244 |
+
const {
|
245 |
+
visible: setMetaVisible,
|
246 |
+
hideModal: hideSetMetaModal,
|
247 |
+
showModal: showSetMetaModal,
|
248 |
+
} = useSetModalState();
|
249 |
+
|
250 |
+
const onSetMetaModalOk = useCallback(
|
251 |
+
async (meta: string) => {
|
252 |
+
const ret = await setDocumentMeta({
|
253 |
+
documentId,
|
254 |
+
meta,
|
255 |
+
});
|
256 |
+
if (ret === 0) {
|
257 |
+
hideSetMetaModal();
|
258 |
+
}
|
259 |
+
},
|
260 |
+
[setDocumentMeta, documentId, hideSetMetaModal],
|
261 |
+
);
|
262 |
+
|
263 |
+
return {
|
264 |
+
setMetaLoading: loading,
|
265 |
+
onSetMetaModalOk,
|
266 |
+
setMetaVisible,
|
267 |
+
hideSetMetaModal,
|
268 |
+
showSetMetaModal,
|
269 |
+
};
|
270 |
+
};
|
web/src/pages/add-knowledge/components/knowledge-file/index.tsx
CHANGED
@@ -20,6 +20,7 @@ import {
|
|
20 |
useHandleWebCrawl,
|
21 |
useNavigateToOtherPage,
|
22 |
useRenameDocument,
|
|
|
23 |
} from './hooks';
|
24 |
import ParsingActionCell from './parsing-action-cell';
|
25 |
import ParsingStatusCell from './parsing-status-cell';
|
@@ -30,6 +31,7 @@ import FileUploadModal from '@/components/file-upload-modal';
|
|
30 |
import { IDocumentInfo } from '@/interfaces/database/document';
|
31 |
import { formatDate } from '@/utils/date';
|
32 |
import styles from './index.less';
|
|
|
33 |
|
34 |
const { Text } = Typography;
|
35 |
|
@@ -79,6 +81,14 @@ const KnowledgeFile = () => {
|
|
79 |
keyPrefix: 'knowledgeDetails',
|
80 |
});
|
81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
const rowSelection = useGetRowSelection();
|
83 |
|
84 |
const columns: ColumnsType<IDocumentInfo> = [
|
@@ -157,6 +167,7 @@ const KnowledgeFile = () => {
|
|
157 |
setCurrentRecord={setRecord}
|
158 |
showRenameModal={showRenameModal}
|
159 |
showChangeParserModal={showChangeParserModal}
|
|
|
160 |
record={record}
|
161 |
></ParsingActionCell>
|
162 |
),
|
@@ -225,6 +236,15 @@ const KnowledgeFile = () => {
|
|
225 |
loading={webCrawlUploadLoading}
|
226 |
onOk={onWebCrawlUploadOk}
|
227 |
></WebCrawlModal>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
</div>
|
229 |
);
|
230 |
};
|
|
|
20 |
useHandleWebCrawl,
|
21 |
useNavigateToOtherPage,
|
22 |
useRenameDocument,
|
23 |
+
useShowMetaModal,
|
24 |
} from './hooks';
|
25 |
import ParsingActionCell from './parsing-action-cell';
|
26 |
import ParsingStatusCell from './parsing-status-cell';
|
|
|
31 |
import { IDocumentInfo } from '@/interfaces/database/document';
|
32 |
import { formatDate } from '@/utils/date';
|
33 |
import styles from './index.less';
|
34 |
+
import { SetMetaModal } from './set-meta-modal';
|
35 |
|
36 |
const { Text } = Typography;
|
37 |
|
|
|
81 |
keyPrefix: 'knowledgeDetails',
|
82 |
});
|
83 |
|
84 |
+
const {
|
85 |
+
showSetMetaModal,
|
86 |
+
hideSetMetaModal,
|
87 |
+
setMetaVisible,
|
88 |
+
setMetaLoading,
|
89 |
+
onSetMetaModalOk,
|
90 |
+
} = useShowMetaModal(currentRecord.id);
|
91 |
+
|
92 |
const rowSelection = useGetRowSelection();
|
93 |
|
94 |
const columns: ColumnsType<IDocumentInfo> = [
|
|
|
167 |
setCurrentRecord={setRecord}
|
168 |
showRenameModal={showRenameModal}
|
169 |
showChangeParserModal={showChangeParserModal}
|
170 |
+
showSetMetaModal={showSetMetaModal}
|
171 |
record={record}
|
172 |
></ParsingActionCell>
|
173 |
),
|
|
|
236 |
loading={webCrawlUploadLoading}
|
237 |
onOk={onWebCrawlUploadOk}
|
238 |
></WebCrawlModal>
|
239 |
+
{setMetaVisible && (
|
240 |
+
<SetMetaModal
|
241 |
+
visible={setMetaVisible}
|
242 |
+
hideModal={hideSetMetaModal}
|
243 |
+
onOk={onSetMetaModalOk}
|
244 |
+
loading={setMetaLoading}
|
245 |
+
initialMetaData={currentRecord.meta_fields}
|
246 |
+
></SetMetaModal>
|
247 |
+
)}
|
248 |
</div>
|
249 |
);
|
250 |
};
|
web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx
CHANGED
@@ -11,6 +11,7 @@ import {
|
|
11 |
import { Button, Dropdown, MenuProps, Space, Tooltip } from 'antd';
|
12 |
import { isParserRunning } from '../utils';
|
13 |
|
|
|
14 |
import { DocumentType } from '../constant';
|
15 |
import styles from './index.less';
|
16 |
|
@@ -19,6 +20,7 @@ interface IProps {
|
|
19 |
setCurrentRecord: (record: IDocumentInfo) => void;
|
20 |
showRenameModal: () => void;
|
21 |
showChangeParserModal: () => void;
|
|
|
22 |
}
|
23 |
|
24 |
const ParsingActionCell = ({
|
@@ -26,6 +28,7 @@ const ParsingActionCell = ({
|
|
26 |
setCurrentRecord,
|
27 |
showRenameModal,
|
28 |
showChangeParserModal,
|
|
|
29 |
}: IProps) => {
|
30 |
const documentId = record.id;
|
31 |
const isRunning = isParserRunning(record.run);
|
@@ -47,9 +50,9 @@ const ParsingActionCell = ({
|
|
47 |
});
|
48 |
};
|
49 |
|
50 |
-
const setRecord = () => {
|
51 |
setCurrentRecord(record);
|
52 |
-
};
|
53 |
|
54 |
const onShowRenameModal = () => {
|
55 |
setRecord();
|
@@ -60,17 +63,33 @@ const ParsingActionCell = ({
|
|
60 |
showChangeParserModal();
|
61 |
};
|
62 |
|
|
|
|
|
|
|
|
|
|
|
63 |
const chunkItems: MenuProps['items'] = [
|
64 |
{
|
65 |
key: '1',
|
66 |
label: (
|
67 |
-
<div>
|
68 |
<Button type="link" onClick={onShowChangeParserModal}>
|
69 |
{t('chunkMethod')}
|
70 |
</Button>
|
71 |
</div>
|
72 |
),
|
73 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
];
|
75 |
|
76 |
return (
|
|
|
11 |
import { Button, Dropdown, MenuProps, Space, Tooltip } from 'antd';
|
12 |
import { isParserRunning } from '../utils';
|
13 |
|
14 |
+
import { useCallback } from 'react';
|
15 |
import { DocumentType } from '../constant';
|
16 |
import styles from './index.less';
|
17 |
|
|
|
20 |
setCurrentRecord: (record: IDocumentInfo) => void;
|
21 |
showRenameModal: () => void;
|
22 |
showChangeParserModal: () => void;
|
23 |
+
showSetMetaModal: () => void;
|
24 |
}
|
25 |
|
26 |
const ParsingActionCell = ({
|
|
|
28 |
setCurrentRecord,
|
29 |
showRenameModal,
|
30 |
showChangeParserModal,
|
31 |
+
showSetMetaModal,
|
32 |
}: IProps) => {
|
33 |
const documentId = record.id;
|
34 |
const isRunning = isParserRunning(record.run);
|
|
|
50 |
});
|
51 |
};
|
52 |
|
53 |
+
const setRecord = useCallback(() => {
|
54 |
setCurrentRecord(record);
|
55 |
+
}, [record, setCurrentRecord]);
|
56 |
|
57 |
const onShowRenameModal = () => {
|
58 |
setRecord();
|
|
|
63 |
showChangeParserModal();
|
64 |
};
|
65 |
|
66 |
+
const onShowSetMetaModal = useCallback(() => {
|
67 |
+
setRecord();
|
68 |
+
showSetMetaModal();
|
69 |
+
}, [setRecord, showSetMetaModal]);
|
70 |
+
|
71 |
const chunkItems: MenuProps['items'] = [
|
72 |
{
|
73 |
key: '1',
|
74 |
label: (
|
75 |
+
<div className="flex flex-col">
|
76 |
<Button type="link" onClick={onShowChangeParserModal}>
|
77 |
{t('chunkMethod')}
|
78 |
</Button>
|
79 |
</div>
|
80 |
),
|
81 |
},
|
82 |
+
{ type: 'divider' },
|
83 |
+
{
|
84 |
+
key: '2',
|
85 |
+
label: (
|
86 |
+
<div className="flex flex-col">
|
87 |
+
<Button type="link" onClick={onShowSetMetaModal}>
|
88 |
+
{t('setMetaData')}
|
89 |
+
</Button>
|
90 |
+
</div>
|
91 |
+
),
|
92 |
+
},
|
93 |
];
|
94 |
|
95 |
return (
|
web/src/pages/add-knowledge/components/knowledge-file/set-meta-modal/index.tsx
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { IModalProps } from '@/interfaces/common';
|
2 |
+
import { IDocumentInfo } from '@/interfaces/database/document';
|
3 |
+
import Editor, { loader } from '@monaco-editor/react';
|
4 |
+
|
5 |
+
import { Form, Modal } from 'antd';
|
6 |
+
import DOMPurify from 'dompurify';
|
7 |
+
import { useCallback, useEffect } from 'react';
|
8 |
+
import { useTranslation } from 'react-i18next';
|
9 |
+
|
10 |
+
loader.config({ paths: { vs: '/vs' } });
|
11 |
+
|
12 |
+
type FieldType = {
|
13 |
+
meta?: string;
|
14 |
+
};
|
15 |
+
|
16 |
+
export function SetMetaModal({
|
17 |
+
visible,
|
18 |
+
hideModal,
|
19 |
+
onOk,
|
20 |
+
initialMetaData,
|
21 |
+
}: IModalProps<any> & { initialMetaData?: IDocumentInfo['meta_fields'] }) {
|
22 |
+
const { t } = useTranslation();
|
23 |
+
const [form] = Form.useForm();
|
24 |
+
|
25 |
+
const handleOk = useCallback(async () => {
|
26 |
+
const values = await form.validateFields();
|
27 |
+
onOk?.(values.meta);
|
28 |
+
}, [form, onOk]);
|
29 |
+
|
30 |
+
useEffect(() => {
|
31 |
+
form.setFieldValue('meta', JSON.stringify(initialMetaData, null, 4));
|
32 |
+
}, [form, initialMetaData]);
|
33 |
+
|
34 |
+
return (
|
35 |
+
<Modal
|
36 |
+
title={t('knowledgeDetails.setMetaData')}
|
37 |
+
open={visible}
|
38 |
+
onOk={handleOk}
|
39 |
+
onCancel={hideModal}
|
40 |
+
>
|
41 |
+
<Form
|
42 |
+
name="basic"
|
43 |
+
initialValues={{ remember: true }}
|
44 |
+
autoComplete="off"
|
45 |
+
layout={'vertical'}
|
46 |
+
form={form}
|
47 |
+
>
|
48 |
+
<Form.Item<FieldType>
|
49 |
+
label={t('knowledgeDetails.metaData')}
|
50 |
+
name="meta"
|
51 |
+
rules={[
|
52 |
+
{
|
53 |
+
required: true,
|
54 |
+
validator(rule, value) {
|
55 |
+
try {
|
56 |
+
JSON.parse(value);
|
57 |
+
return Promise.resolve();
|
58 |
+
} catch (error) {
|
59 |
+
return Promise.reject(
|
60 |
+
new Error(t('knowledgeDetails.pleaseInputJson')),
|
61 |
+
);
|
62 |
+
}
|
63 |
+
},
|
64 |
+
},
|
65 |
+
]}
|
66 |
+
tooltip={
|
67 |
+
<div
|
68 |
+
dangerouslySetInnerHTML={{
|
69 |
+
__html: DOMPurify.sanitize(
|
70 |
+
t('knowledgeDetails.documentMetaTips'),
|
71 |
+
),
|
72 |
+
}}
|
73 |
+
></div>
|
74 |
+
}
|
75 |
+
>
|
76 |
+
<Editor height={200} defaultLanguage="json" theme="vs-dark" />
|
77 |
+
</Form.Item>
|
78 |
+
</Form>
|
79 |
+
</Modal>
|
80 |
+
);
|
81 |
+
}
|
web/src/services/knowledge-service.ts
CHANGED
@@ -31,6 +31,7 @@ const {
|
|
31 |
document_infos,
|
32 |
upload_and_parse,
|
33 |
listTagByKnowledgeIds,
|
|
|
34 |
} = api;
|
35 |
|
36 |
const methods = {
|
@@ -55,7 +56,7 @@ const methods = {
|
|
55 |
url: kb_list,
|
56 |
method: 'get',
|
57 |
},
|
58 |
-
//
|
59 |
get_document_list: {
|
60 |
url: get_document_list,
|
61 |
method: 'get',
|
@@ -100,6 +101,10 @@ const methods = {
|
|
100 |
url: document_infos,
|
101 |
method: 'post',
|
102 |
},
|
|
|
|
|
|
|
|
|
103 |
// chunk管理
|
104 |
chunk_list: {
|
105 |
url: chunk_list,
|
|
|
31 |
document_infos,
|
32 |
upload_and_parse,
|
33 |
listTagByKnowledgeIds,
|
34 |
+
setMeta,
|
35 |
} = api;
|
36 |
|
37 |
const methods = {
|
|
|
56 |
url: kb_list,
|
57 |
method: 'get',
|
58 |
},
|
59 |
+
// document manager
|
60 |
get_document_list: {
|
61 |
url: get_document_list,
|
62 |
method: 'get',
|
|
|
101 |
url: document_infos,
|
102 |
method: 'post',
|
103 |
},
|
104 |
+
setMeta: {
|
105 |
+
url: setMeta,
|
106 |
+
method: 'post',
|
107 |
+
},
|
108 |
// chunk管理
|
109 |
chunk_list: {
|
110 |
url: chunk_list,
|
web/src/utils/api.ts
CHANGED
@@ -70,6 +70,7 @@ export default {
|
|
70 |
document_infos: `${api_host}/document/infos`,
|
71 |
upload_and_parse: `${api_host}/document/upload_and_parse`,
|
72 |
parse: `${api_host}/document/parse`,
|
|
|
73 |
|
74 |
// chat
|
75 |
setDialog: `${api_host}/dialog/set`,
|
|
|
70 |
document_infos: `${api_host}/document/infos`,
|
71 |
upload_and_parse: `${api_host}/document/upload_and_parse`,
|
72 |
parse: `${api_host}/document/parse`,
|
73 |
+
setMeta: `${api_host}/document/set_meta`,
|
74 |
|
75 |
// chat
|
76 |
setDialog: `${api_host}/dialog/set`,
|