Code Monkey home page Code Monkey logo

lcchat's Introduction

📃 LangChain-Chatchat (原 Langchain-ChatGLM)

基于 ChatGLM 等大语言模型与 Langchain 等应用框架实现,开源、可离线部署的检索增强生成(RAG)大模型知识库项目。

目录

介绍

🤖️ 一种利用 langchain **实现的基于本地知识库的问答应用,目标期望建立一套对中文场景与开源模型支持友好、可离线运行的知识库问答解决方案。

💡 受 GanymedeNil 的项目 document.aiAlexZhangji 创建的 ChatGLM-6B Pull Request 启发,建立了全流程可使用开源模型实现的本地知识库问答应用。本项目的最新版本中通过使用 FastChat 接入 Vicuna, Alpaca, LLaMA, Koala, RWKV 等模型,依托于 langchain 框架支持通过基于 FastAPI 提供的 API 调用服务,或使用基于 Streamlit 的 WebUI 进行操作。

✅ 依托于本项目支持的开源 LLM 与 Embedding 模型,本项目可实现全部使用开源模型离线私有部署。与此同时,本项目也支持 OpenAI GPT API 的调用,并将在后续持续扩充对各类模型及模型 API 的接入。

⛓️ 本项目实现原理如下图所示,过程包括加载文件 -> 读取文本 -> 文本分割 -> 文本向量化 -> 问句向量化 -> 在文本向量中匹配出与问句向量最相似的 top k个 -> 匹配出的文本作为上下文和问题一起添加到 prompt中 -> 提交给 LLM生成回答。

实现原理图

从文档处理角度来看,实现流程如下:

实现原理图2

快速上手

接着,创建一个虚拟环境,并在虚拟环境内安装项目的依赖

# 拉取仓库
$ git clone https://github.com/Tian789Gong/orange-Langchain.git


# 进入目录
$ cd orange-Langchain
# 安装全部依赖
$ pip install -r requirements.txt 
$ pip install -r requirements_api.txt
$ pip install -r requirements_webui.txt  

# 默认依赖包括基本运行环境(FAISS向量库)。如果要使用 milvus/pg_vector 等向量库,请将 requirements.txt 中相应依赖取消注释再安装。

2. 模型下载

如需在本地或离线环境下运行本项目,需要首先将项目所需的模型下载至本地,通常开源 LLM 与 Embedding 模型可以从 HuggingFace 下载。

以本项目中默认使用的 LLM 模型 THUDM/ChatGLM3-6B 与 Embedding 模型 BAAI/bge-large-zh 为例:

下载模型需要先安装 Git LFS ,然后运行

$ sudo apt-get update
$ sudo apt-get install git-lfs
$ git lfs install
$ git clone https://www.modelscope.cn/ZhipuAI/chatglm3-6b.git
$ cd chatglm3-6b
$ git lfs pull
$ ls -lh .git/lfs/objects
$ git lfs ls-files
$ cd ..
$ git clone https://www.modelscope.cn/AI-ModelScope/bge-large-zh.git
$ cd bge-large-zh
$ git lfs pull
$ ls -lh .git/lfs/objects
$ git lfs ls-files

$ pip install -U huggingface_hub $ export HF_ENDPOINT=https://hf-mirror.com $ huggingface-cli download --resume-download BAAI/bge-large-zh-v1.5 --local-dir bge-large-zh

3. 初始化知识库和配置文件

按照下列方式初始化自己的知识库和简单的复制配置文件

$ python3 copy_config_example.py
$ python3 init_database.py --recreate-vs

4. 一键启动

按照以下命令启动项目

$ python3 startup.py -a

5. 启动界面示例

如果正常启动,你将能看到以下界面

  1. FastAPI Docs 界面

  1. Web UI 启动界面示例:
  • Web UI 对话界面:

img

  • Web UI 知识库管理页面:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.