fix KnowledgeFile: set text_splitter_name in database to SpacyTextSplitter if it is not set

This commit is contained in:
liunux4odoo 2023-08-16 10:14:47 +08:00
parent 1551adb867
commit a47240e871
2 changed files with 2 additions and 1 deletions

View File

@ -27,7 +27,7 @@ def add_doc_to_db(session, kb_file: KnowledgeFile):
file_ext=kb_file.ext, file_ext=kb_file.ext,
kb_name=kb_file.kb_name, kb_name=kb_file.kb_name,
document_loader_name=kb_file.document_loader_name, document_loader_name=kb_file.document_loader_name,
text_splitter_name=kb_file.text_splitter_name, text_splitter_name=kb_file.text_splitter_name or "SpacyTextSplitter",
) )
kb.file_count += 1 kb.file_count += 1
session.add(new_file) session.add(new_file)

View File

@ -102,6 +102,7 @@ class KnowledgeFile:
chunk_size=CHUNK_SIZE, chunk_size=CHUNK_SIZE,
chunk_overlap=OVERLAP_SIZE, chunk_overlap=OVERLAP_SIZE,
) )
self.text_splitter_name = "SpacyTextSplitter"
else: else:
text_splitter_module = importlib.import_module('langchain.text_splitter') text_splitter_module = importlib.import_module('langchain.text_splitter')
TextSplitter = getattr(text_splitter_module, self.text_splitter_name) TextSplitter = getattr(text_splitter_module, self.text_splitter_name)