add csv loader

This commit is contained in:
denislov 2025-02-12 01:44:58 +08:00
parent d958f8d31f
commit 66cba8d4e4
2 changed files with 23 additions and 1 deletions

View File

@ -120,6 +120,7 @@ class KnowledgeService {
if (item.type === 'file') { if (item.type === 'file') {
const file = item.content as FileType const file = item.content as FileType
console.log(file)
if (file.ext === '.pdf') { if (file.ext === '.pdf') {
return await ragApplication.addLoader( return await ragApplication.addLoader(
@ -165,6 +166,27 @@ class KnowledgeService {
) )
} }
if (file.ext === '.csv') {
try {
const module = await import('@llm-tools/embedjs-loader-csv/src/index.js')
// 使用module中的功能
console.log(module.CsvLoader) // 假设模块导出了一个默认值
return await ragApplication.addLoader(
new module.CsvLoader({
filePathOrUrl: file.path,
chunkSize: base.chunkSize,
chunkOverlap: base.chunkOverlap,
csvParseOptions: {
columns: true
}
}) as any,
forceReload
)
} catch (error) {
console.error('加载模块时出错:', error)
}
}
if (['.md'].includes(file.ext)) { if (['.md'].includes(file.ext)) {
return await ragApplication.addLoader( return await ragApplication.addLoader(
new MarkdownLoader({ new MarkdownLoader({

View File

@ -33,7 +33,7 @@ interface KnowledgeContentProps {
selectedBase: KnowledgeBase selectedBase: KnowledgeBase
} }
const fileTypes = ['.pdf', '.docx', '.pptx', '.xlsx', '.txt', '.md', '.html'] const fileTypes = ['.pdf', '.docx', '.pptx', '.xlsx', '.txt', '.md', '.html', '.csv']
const KnowledgeContent: FC<KnowledgeContentProps> = ({ selectedBase }) => { const KnowledgeContent: FC<KnowledgeContentProps> = ({ selectedBase }) => {
const { t } = useTranslation() const { t } = useTranslation()