forked from infiniflow/ragflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: select the corresponding parsing method according to the file t…
…ype and after the document is successfully uploaded, use the ChunkMethodModal to select the parsing method. and remove ChunkMethodModal from knowledge-file (infiniflow#158) * feat: select the corresponding parsing method according to the file type * feat: after the document is successfully uploaded, use the ChunkMethodModal to select the parsing method. * feat: add pdf types to ParserListMap * feat: remove ChunkMethodModal from knowledge-file
- Loading branch information
Showing
14 changed files
with
340 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { | ||
useFetchTenantInfo, | ||
useSelectParserList, | ||
} from '@/hooks/userSettingHook'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
|
||
const ParserListMap = new Map([ | ||
[ | ||
['pdf'], | ||
[ | ||
'naive', | ||
'resume', | ||
'manual', | ||
'paper', | ||
'book', | ||
'laws', | ||
'presentation', | ||
'one', | ||
], | ||
], | ||
[ | ||
['doc', 'docx'], | ||
['naive', 'resume', 'book', 'laws', 'one'], | ||
], | ||
[ | ||
['xlsx', 'xls'], | ||
['naive', 'qa', 'table', 'one'], | ||
], | ||
[['ppt', 'pptx'], ['presentation']], | ||
[ | ||
['jpg', 'jpeg', 'png', 'gif', 'bmp', 'tif', 'tiff', 'webp', 'svg', 'ico'], | ||
['picture'], | ||
], | ||
[['txt'], ['naive', 'resume', 'book', 'laws', 'one', 'qa', 'table']], | ||
[['csv'], ['naive', 'resume', 'book', 'laws', 'one', 'qa', 'table']], | ||
]); | ||
|
||
const getParserList = ( | ||
values: string[], | ||
parserList: Array<{ | ||
value: string; | ||
label: string; | ||
}>, | ||
) => { | ||
return parserList.filter((x) => values?.some((y) => y === x.value)); | ||
}; | ||
|
||
export const useFetchParserListOnMount = ( | ||
parserId: string, | ||
documentExtension: string, | ||
) => { | ||
const [selectedTag, setSelectedTag] = useState(''); | ||
const parserList = useSelectParserList(); | ||
|
||
const nextParserList = useMemo(() => { | ||
const key = [...ParserListMap.keys()].find((x) => | ||
x.some((y) => y === documentExtension), | ||
); | ||
if (key) { | ||
const values = ParserListMap.get(key); | ||
return getParserList(values ?? [], parserList); | ||
} | ||
|
||
return getParserList( | ||
['naive', 'resume', 'book', 'laws', 'one', 'qa', 'table'], | ||
parserList, | ||
); | ||
}, [parserList, documentExtension]); | ||
|
||
useFetchTenantInfo(); | ||
|
||
useEffect(() => { | ||
setSelectedTag(parserId); | ||
}, [parserId]); | ||
|
||
const handleChange = (tag: string, checked: boolean) => { | ||
const nextSelectedTag = checked ? tag : selectedTag; | ||
setSelectedTag(nextSelectedTag); | ||
}; | ||
|
||
return { parserList: nextParserList, handleChange, selectedTag }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.pageInputNumber { | ||
width: 220px; | ||
} | ||
|
||
.questionIcon { | ||
margin-inline-start: 4px; | ||
color: rgba(0, 0, 0, 0.45); | ||
cursor: help; | ||
writing-mode: horizontal-tb; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { IKnowledgeFile } from '@/interfaces/database/knowledge'; | ||
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document'; | ||
import { useCallback, useState } from 'react'; | ||
import { useSetModalState } from './commonHooks'; | ||
import { useSetDocumentParser } from './documentHooks'; | ||
import { useOneNamespaceEffectsLoading } from './storeHooks'; | ||
|
||
export const useChangeDocumentParser = (documentId: string) => { | ||
const setDocumentParser = useSetDocumentParser(); | ||
|
||
const { | ||
visible: changeParserVisible, | ||
hideModal: hideChangeParserModal, | ||
showModal: showChangeParserModal, | ||
} = useSetModalState(); | ||
const loading = useOneNamespaceEffectsLoading('kFModel', [ | ||
'document_change_parser', | ||
]); | ||
|
||
const onChangeParserOk = useCallback( | ||
async (parserId: string, parserConfig: IChangeParserConfigRequestBody) => { | ||
const ret = await setDocumentParser(parserId, documentId, parserConfig); | ||
if (ret === 0) { | ||
hideChangeParserModal(); | ||
} | ||
}, | ||
[hideChangeParserModal, setDocumentParser, documentId], | ||
); | ||
|
||
return { | ||
changeParserLoading: loading, | ||
onChangeParserOk, | ||
changeParserVisible, | ||
hideChangeParserModal, | ||
showChangeParserModal, | ||
}; | ||
}; | ||
|
||
export const useSetSelectedRecord = <T = IKnowledgeFile>() => { | ||
const [currentRecord, setCurrentRecord] = useState<T>({} as T); | ||
|
||
const setRecord = (record: T) => { | ||
setCurrentRecord(record); | ||
}; | ||
|
||
return { currentRecord, setRecord }; | ||
}; |
Oops, something went wrong.