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:
parent
a4a0980cd3
commit
eb2439b90c
@ -123,7 +123,15 @@ export async function addFileLoader(
|
||||
|
||||
// JSON类型
|
||||
if (['.json'].includes(file.ext)) {
|
||||
const jsonObject = JSON.parse(fileContent)
|
||||
let jsonObject = {}
|
||||
let jsonParsed = true
|
||||
try {
|
||||
jsonObject = JSON.parse(fileContent)
|
||||
} catch (error) {
|
||||
jsonParsed = false
|
||||
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,
|
||||
@ -132,6 +140,7 @@ export async function addFileLoader(
|
||||
loaderType: loaderReturn.loaderType
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 文本类型
|
||||
const loaderReturn = await ragApplication.addLoader(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user