mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-09 06:49:02 +08:00
fix: support html file in knowledge base (#1703)
This commit is contained in:
parent
50727025c3
commit
9a38c97552
@ -2,6 +2,7 @@ import * as fs from 'node:fs'
|
|||||||
|
|
||||||
import { LocalPathLoader, RAGApplication, TextLoader } from '@llm-tools/embedjs'
|
import { LocalPathLoader, RAGApplication, TextLoader } from '@llm-tools/embedjs'
|
||||||
import type { AddLoaderReturn } from '@llm-tools/embedjs-interfaces'
|
import type { AddLoaderReturn } from '@llm-tools/embedjs-interfaces'
|
||||||
|
import { WebLoader } from '@llm-tools/embedjs-loader-web'
|
||||||
import { LoaderReturn } from '@shared/config/types'
|
import { LoaderReturn } from '@shared/config/types'
|
||||||
import { FileType, KnowledgeBaseParams } from '@types'
|
import { FileType, KnowledgeBaseParams } from '@types'
|
||||||
import Logger from 'electron-log'
|
import Logger from 'electron-log'
|
||||||
@ -69,8 +70,26 @@ export async function addFileLoader(
|
|||||||
} as LoaderReturn
|
} as LoaderReturn
|
||||||
}
|
}
|
||||||
|
|
||||||
// 文本类型
|
|
||||||
const fileContent = fs.readFileSync(file.path, 'utf-8')
|
const fileContent = fs.readFileSync(file.path, 'utf-8')
|
||||||
|
// HTML类型
|
||||||
|
if (['.html', '.htm'].includes(file.ext)) {
|
||||||
|
const loaderReturn = await ragApplication.addLoader(
|
||||||
|
new WebLoader({
|
||||||
|
urlOrContent: fileContent,
|
||||||
|
chunkSize: base.chunkSize,
|
||||||
|
chunkOverlap: base.chunkOverlap
|
||||||
|
}) as any,
|
||||||
|
forceReload
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
entriesAdded: loaderReturn.entriesAdded,
|
||||||
|
uniqueId: loaderReturn.uniqueId,
|
||||||
|
uniqueIds: [loaderReturn.uniqueId],
|
||||||
|
loaderType: loaderReturn.loaderType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文本类型
|
||||||
const loaderReturn = await ragApplication.addLoader(
|
const loaderReturn = await ragApplication.addLoader(
|
||||||
new TextLoader({ text: fileContent, chunkSize: base.chunkSize, chunkOverlap: base.chunkOverlap }) as any,
|
new TextLoader({ text: fileContent, chunkSize: base.chunkSize, chunkOverlap: base.chunkOverlap }) as any,
|
||||||
forceReload
|
forceReload
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user