Langchain-Chatchat icon indicating copy to clipboard operation
Langchain-Chatchat copied to clipboard

文件对话doc文件上传失败

Open gj6956 opened this issue 1 year ago • 1 comments

1.选择"文件对话" 微信截图_20240221104215

2.选择需要上传的文件 微信截图_20240221104231

3.点击"开始上传"

4.后台显示文件向量化成功 微信截图_20240221104416

5.临时文件夹中没有对应的doc文件 微信截图_20240221104428

gj6956 avatar Feb 21 '24 02:02 gj6956

🤖

你好 @gj6956,很高兴再次见到你!遇到什么问题了呢?

您的问题可能是由于文件没有正确保存在临时目录中。负责将上传的文件保存到指定目录的是 _parse_files_in_thread 函数。如果在此过程中出现异常,该函数将返回一个失败消息以及文件名。

这是相关的代码:

def parse_file(file: UploadFile) -> dict:
    '''
    保存单个文件。
    '''
    try:
        filename = file.filename
        file_path = os.path.join(dir, filename)
        file_content = file.file.read()  # 读取上传文件的内容

        if not os.path.isdir(os.path.dirname(file_path)):
            os.makedirs(os.path.dirname(file_path))
        with open(file_path, "wb") as f:
            f.write(file_content)
        kb_file = KnowledgeFile(filename=filename, knowledge_base_name="temp")
        kb_file.filepath = file_path
        docs = kb_file.file2text(zh_title_enhance=zh_title_enhance,
                                 chunk_size=chunk_size,
                                 chunk_overlap=chunk_overlap)
        return True, filename, f"成功上传文件 {filename}", docs
    except Exception as e:
        msg = f"{filename} 文件上传失败,报错信息为: {e}"
        return False, filename, msg, []

如果文件没有出现在临时文件夹中,可能是在文件保存过程中出现了异常。您应该检查 upload_temp_docs 函数返回的 failed_files 列表,看看是否有关于文件上传过程的任何错误消息。

这是相关的代码:

failed_files = []
documents = []
path, id = get_temp_dir(prev_id)
for success, file, msg, docs in _parse_files_in_thread(files=files,
                                                    dir=path,
                                                    zh_title_enhance=zh_title_enhance,
                                                    chunk_size=chunk_size,
                                                    chunk_overlap=chunk_overlap):
    if success:
        documents += docs
    else:
        failed_files.append({file: msg})

如果 failed_files 列表中有任何错误消息,它们应该提供更多关于为什么文件没有出现在临时文件夹中的信息。

源代码:

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Feb 21 '24 02:02 dosubot[bot]

这个问题已经被标记为 stale ,因为它已经超过 30 天没有任何活动。

github-actions[bot] avatar Mar 22 '24 21:03 github-actions[bot]

@dosubot 现在msg的消息有返回给前端ui,用来提示给用户吗?

iuhiyuh avatar May 17 '24 06:05 iuhiyuh