LangChain-Chatchat 是一款中文友好的全流程本地知识库问答应用,支持 FastChat 接入的ChatGLM-2/LLaMA-2等多款主流LLMs+多款embedding模型m3e等+多种TextSplitter分词器,支持FAISS/Milvus/PGVector向量库, 基于LangChain 框架+FastAPI的API调用服务+Streamlit 的WebUI操作。
该项目采用 FastChat + Langchain + FastAPI + Streamlit 构建的基于 Langchain 与 ChatGLM 等大语言模型的本地知识库问答应用实现。
环境准备:
conda create --name lcchat python=3.10.6
conda activate lcchat
安装环境:
# 安装全部依赖
pip install -r requirements.txt
pip install -r requirements_api.txt
pip install -r requirements_webui.txt
#这里GPU是12.2
conda install pytorch==2.1.1 torchvision==0.16.1 torchaudio==2.1.1 pytorch-cuda=12.1 -c pytorch -c nvidia
模型下载:
如需在本地或离线环境下运行本项目,需要首先将项目所需的模型下载至本地,通常开源 LLM 与 Embedding 模型可以从 HuggingFace 下载。
$ git lfs install
$ git clone https://huggingface.co/THUDM/chatglm3-6b
$ git clone https://huggingface.co/BAAI/bge-large-zh
初始化:
按照下列方式初始化自己的知识库和简单的复制配置文件
$ python copy_config_example.py
$ python init_database.py --recreate-vs
一键启动服务:
一键启动
按照以下命令启动项目
python startup.py -a
访问页面:
http://127.0.0.1:8501
登入页面后,可以创建自己的知识库并上传内容。下图(创建知识库后,对话检索知识库内容示意)