Loading...  📃 **LangChain-Chatchat** (原 Langchain-ChatGLM) 基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的检索增强生成(RAG)大模型知识库项目。 ### ⚠️ 重要提示 [](https://github.com/chatchat-space/Langchain-Chatchat#%EF%B8%8F-%E9%87%8D%E8%A6%81%E6%8F%90%E7%A4%BA) `0.2.10`将会是`0.2.x`系列的最后一个版本,`0.2.x`系列版本将会停止更新和技术支持,全力研发具有更强应用性的 `Langchain-Chatchat 0.3.x`。 `0.2.10` 的后续 bug 修复将会直接推送到`master`分支,而不在进行版本更新。 --- ## 目录 [](https://github.com/chatchat-space/Langchain-Chatchat#%E7%9B%AE%E5%BD%95) * [介绍](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#%E4%BB%8B%E7%BB%8D) * [解决的痛点](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#%E8%A7%A3%E5%86%B3%E7%9A%84%E7%97%9B%E7%82%B9) * [快速上手](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B) * [1. 环境配置](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#1-%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE) * [2. 模型下载](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#2-%E6%A8%A1%E5%9E%8B%E4%B8%8B%E8%BD%BD) * [3. 初始化知识库和配置文件](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#3-%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9F%A5%E8%AF%86%E5%BA%93%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6) * [4. 一键启动](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#4-%E4%B8%80%E9%94%AE%E5%90%AF%E5%8A%A8) * [5. 启动界面示例](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#5-%E5%90%AF%E5%8A%A8%E7%95%8C%E9%9D%A2%E7%A4%BA%E4%BE%8B) * [联系我们](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/README.md#%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC) ## 介绍 [](https://github.com/chatchat-space/Langchain-Chatchat#%E4%BB%8B%E7%BB%8D) 🤖️ 一种利用 [langchain](https://github.com/langchain-ai/langchain) 思想实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。 💡 受 [GanymedeNil](https://github.com/GanymedeNil) 的项目 [document.ai](https://github.com/GanymedeNil/document.ai) 和 [AlexZhangji](https://github.com/AlexZhangji) 创建的 [ChatGLM-6B Pull Request](https://github.com/THUDM/ChatGLM-6B/pull/216) 启发,建立了全流程可使用开源模型实现的本地知识库问答应用。本项目的最新版本中通过使用 [FastChat](https://github.com/lm-sys/FastChat) 接入 Vicuna, Alpaca, LLaMA, Koala, RWKV 等模型,依托于 [langchain](https://github.com/langchain-ai/langchain) 框架支持通过基于 [FastAPI](https://github.com/tiangolo/fastapi) 提供的 API 调用服务,或使用基于 [Streamlit](https://github.com/streamlit/streamlit) 的 WebUI 进行操作。 ✅ 依托于本项目支持的开源 LLM 与 Embedding 模型,本项目可实现全部使用**开源**模型**离线私有部署**。与此同时,本项目也支持 OpenAI GPT API 的调用,并将在后续持续扩充对各类模型及模型 API 的接入。 ⛓️ 本项目实现原理如下图所示,过程包括加载文件 -> 读取文本 -> 文本分割 -> 文本向量化 -> 问句向量化 -> 在文本向量中匹配出与问句向量最相似的 `top k`个 -> 匹配出的文本作为上下文和问题一起添加到 `prompt`中 -> 提交给 `LLM`生成回答。 📺 [原理介绍视频](https://www.bilibili.com/video/BV13M4y1e7cN/?share_source=copy_web&vd_source=e6c5aafe684f30fbe41925d61ca6d514)  从文档处理角度来看,实现流程如下:  🚩 本项目未涉及微调、训练过程,但可利用微调或训练对本项目效果进行优化。 🌐 [AutoDL 镜像](https://www.codewithgpu.com/i/chatchat-space/Langchain-Chatchat/Langchain-Chatchat) 中 `0.2.10` 版本所使用代码已更新至本项目 `v0.2.10` 版本。 🐳 [Docker 镜像](https://github.com/chatchat-space/Langchain-Chatchat/blob/master/registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.7) 已经更新到 `0.2.7` 版本。 🌲 一行命令运行 Docker : ```shell docker run -d --gpus all -p 80:8501 registry.cn-beijing.aliyuncs.com/chatchat/chatchat:0.2.7 ``` 🧩 本项目有一个非常完整的[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/) , README只是一个简单的介绍,\_ *仅仅是入门教程,能够基础运行*\_。 如果你想要更深入的了解本项目,或者想对本项目做出贡献。请移步 [Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/) 界面 ## 解决的痛点 [](https://github.com/chatchat-space/Langchain-Chatchat#%E8%A7%A3%E5%86%B3%E7%9A%84%E7%97%9B%E7%82%B9) 该项目是一个可以实现 \_\_完全本地化\_\_推理的知识库增强方案, 重点解决数据安全保护,私域化部署的企业痛点。 本开源方案采用`Apache License`,可以免费商用,无需付费。 我们支持市面上主流的本地大语言模型和Embedding模型,支持开源的本地向量数据库。 支持列表详见[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/) ## 快速上手 [](https://github.com/chatchat-space/Langchain-Chatchat#%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B) ### 1. 环境配置 [](https://github.com/chatchat-space/Langchain-Chatchat#1-%E7%8E%AF%E5%A2%83%E9%85%8D%E7%BD%AE) * 首先,确保你的机器安装了 Python 3.8 - 3.11 (我们强烈推荐使用 Python3.11)。 ``` $ python --version Python 3.11.7 ``` 接着,创建一个虚拟环境,并在虚拟环境内安装项目的依赖 ```shell # 拉取仓库 $ git clone https://github.com/chatchat-space/Langchain-Chatchat.git # 进入目录 $ cd Langchain-Chatchat # 安装全部依赖 $ pip install -r requirements.txt $ pip install -r requirements_api.txt $ pip install -r requirements_webui.txt # 默认依赖包括基本运行环境(FAISS向量库)。如果要使用 milvus/pg_vector 等向量库,请将 requirements.txt 中相应依赖取消注释再安装。 ``` 请注意,LangChain-Chatchat `0.2.x` 系列是针对 Langchain `0.0.x` 系列版本的,如果你使用的是 Langchain `0.1.x` 系列版本,需要降级您的`Langchain`版本。 ### 2, 模型下载 [](https://github.com/chatchat-space/Langchain-Chatchat#2-%E6%A8%A1%E5%9E%8B%E4%B8%8B%E8%BD%BD) 如需在本地或离线环境下运行本项目,需要首先将项目所需的模型下载至本地,通常开源 LLM 与 Embedding 模型可以从 [HuggingFace](https://huggingface.co/models) 下载。 以本项目中默认使用的 LLM 模型 [THUDM/ChatGLM3-6B](https://huggingface.co/THUDM/chatglm3-6b) 与 Embedding 模型 [BAAI/bge-large-zh](https://huggingface.co/BAAI/bge-large-zh) 为例: 下载模型需要先[安装 Git LFS](https://docs.github.com/zh/repositories/working-with-files/managing-large-files/installing-git-large-file-storage) ,然后运行 ```shell $ git lfs install $ git clone https://huggingface.co/THUDM/chatglm3-6b $ git clone https://huggingface.co/BAAI/bge-large-zh ``` ### 3. 初始化知识库和配置文件 [](https://github.com/chatchat-space/Langchain-Chatchat#3-%E5%88%9D%E5%A7%8B%E5%8C%96%E7%9F%A5%E8%AF%86%E5%BA%93%E5%92%8C%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6) 按照下列方式初始化自己的知识库和简单的复制配置文件 ```shell $ python copy_config_example.py $ python init_database.py --recreate-vs ``` ### 4. 一键启动 [](https://github.com/chatchat-space/Langchain-Chatchat#4-%E4%B8%80%E9%94%AE%E5%90%AF%E5%8A%A8) 按照以下命令启动项目 ```shell $ python startup.py -a ``` ### 5. 启动界面示例 [](https://github.com/chatchat-space/Langchain-Chatchat#5-%E5%90%AF%E5%8A%A8%E7%95%8C%E9%9D%A2%E7%A4%BA%E4%BE%8B) 如果正常启动,你将能看到以下界面 1. FastAPI Docs 界面  2. Web UI 启动界面示例: * Web UI 对话界面:  * Web UI 知识库管理页面:  ### 注意 以上方式只是为了快速上手,如果需要更多的功能和自定义启动方式 ,请参考[Wiki](https://github.com/chatchat-space/Langchain-Chatchat/wiki/) --- ## 项目里程碑 [](https://github.com/chatchat-space/Langchain-Chatchat#%E9%A1%B9%E7%9B%AE%E9%87%8C%E7%A8%8B%E7%A2%91) * `2023年4月`: `Langchain-ChatGLM 0.1.0` 发布,支持基于 ChatGLM-6B 模型的本地知识库问答。 * `2023年8月`: `Langchain-ChatGLM` 改名为 `Langchain-Chatchat`,`0.2.0` 发布,使用 `fastchat` 作为模型加载方案,支持更多的模型和数据库。 * `2023年10月`: `Langchain-Chatchat 0.2.5` 发布,推出 Agent 内容,开源项目在`Founder Park & Zhipu AI & Zilliz` 举办的黑客马拉松获得三等奖。 * `2023年12月`: `Langchain-Chatchat` 开源项目获得超过 **20K** stars. * `2024年1月`: `LangChain 0.1.x` 推出,`Langchain-Chatchat 0.2.x` 发布稳定版本`0.2.10` 后将停止更新和技术支持,全力研发具有更强应用性的 `Langchain-Chatchat 0.3.x`。 * 🔥 让我们一起期待未来 Chatchat 的故事 ··· 最后修改:2024 年 03 月 23 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 如果觉得我的文章对你有用,请随意赞赏
34 条评论
命运理发师
狐妖传说
变形金刚5最后的骑士
刚果惊魂
不老奇事
黑道三宝
新流氓医生
零号追杀
一触即发
荣耀之谁与争锋
都是恋爱脑惹的祸
星球大战前传3西斯的复仇
世界上最好的
罗斯坎普黑手党和英国
比尔马赫还有其他人看到这个吗
谍与蝶
九月五日
这是汤姆格林的纪录片
活埋求生
我的三个儿子
雷蒙斯尼奇的不幸历险
不虚此行
新流氓医生
孤寂午后
秦岭诡事之守护者
剑客卡南
巨型漏洞
花木兰
熊出没逆转时空
评估
狂兽粤配
情感真挚自然,字里行间传递出强烈的感染力。
文章的确不错啊https://www.cscnn.com/
想想你的文章写的特别好https://www.237fa.com/