-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
出bug的具体模型
ChatGLM3-6B
出bug的具体模型教程
ChatGLM3-6B接入LangChain搭建知识库助手
教程负责人
Logan Zou
Bug描述
问题描述
在运行 create_db.py
构建知识库时,遇到 UnicodeDecodeError
错误,导致程序无法正常处理包含非UTF-8编码的中文文档。
错误信息
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa1 in position 45: invalid start byte
UnicodeDecodeError: 'johab' codec can't decode byte 0xa8 in position 4954251: illegal multibyte sequence
复现步骤
问题分析
编码处理缺失: get_text()
函数直接使用 UnstructuredMarkdownLoader
和 UnstructuredFileLoader
,没有指定编码参数
复现步骤
- 运行
python create_db.py
- 当处理包含GBK/GB2312编码的中文文档时触发错误
- 程序异常终止,无法完成知识库构建
建议解决方案
在 get_text()
函数中添加多编码fallback机制 (UTF-8 → GBK → GB2312 → latin-1)
影响范围
该问题影响所有需要处理多种编码中文文档的用户,特别是GBK编码文件。
期望行为
对所描述的文件能正常构建,不报错:
tar_dir = [
"/root/autodl-tmp/self-llm",
"/root/autodl-tmp/llm-universe",
"/root/autodl-tmp/prompt-engineering-for-developers",
"/root/autodl-tmp/so-large-lm",
"/root/autodl-tmp/hugging-llm",
]
环境信息
- Python版本: 3.8
- LangChain版本: 0.0.292
- 操作系统: Ubuntu 20.04 (AutoDL平台)
- PyTorch版本: 2.0.0+cu117
- CUDA版本: 11.8
- 其他关键依赖:
- gradio==4.4.0
- chromadb==0.4.15
- sentence-transformers==2.2.2
- unstructured==0.10.30
- markdown==3.3.7
- transformers==4.35.2
- modelscope==1.9.5
- 硬件要求: 24GB显存,4090
其他信息

确认事项 / Verification
- 此问题未在过往Issue中被报告过 / This issue hasn't been reported before
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working