fix(KnowledgeBase): handle JSON parse failure by falling back to text file processing to avoid error display affecting normal progress indication

This commit is contained in:
onlyfeng 2025-02-20 11:02:47 +08:00 committed by 亢奋猫
parent a4a0980cd3
commit eb2439b90c

View File

@ -123,13 +123,22 @@ export async function addFileLoader(
// JSON类型 // JSON类型
if (['.json'].includes(file.ext)) { if (['.json'].includes(file.ext)) {
const jsonObject = JSON.parse(fileContent) let jsonObject = {}
const loaderReturn = await ragApplication.addLoader(new JsonLoader({ object: jsonObject })) let jsonParsed = true
return { try {
entriesAdded: loaderReturn.entriesAdded, jsonObject = JSON.parse(fileContent)
uniqueId: loaderReturn.uniqueId, } catch (error) {
uniqueIds: [loaderReturn.uniqueId], jsonParsed = false
loaderType: loaderReturn.loaderType Logger.warn('[KnowledgeBase] failed parsing json file, failling back to text processing:', file.path, error)
}
if (jsonParsed) {
const loaderReturn = await ragApplication.addLoader(new JsonLoader({ object: jsonObject }))
return {
entriesAdded: loaderReturn.entriesAdded,
uniqueId: loaderReturn.uniqueId,
uniqueIds: [loaderReturn.uniqueId],
loaderType: loaderReturn.loaderType
}
} }
} }