Files
gangyan/langchain-chat/README.md

101 lines
3.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

📃 **LangChain-Chat**
基于大语言模型与 Langchain 等应用框架实现,开源、可离线部署的检索增强生成(RAG)大模型知识库项目。
> 本项目基本框架自 Langchain-Chatchat 修改,里面整体逻辑已大部分根据业务进行优化调整
---
## 目录
* [快速上手](README.md#快速上手)
* [1. 环境配置](README.md#1-环境配置)
* [2. 模型下载](README.md#2-模型下载)
* [3. 初始化知识库和配置文件](README.md#3-初始化知识库和配置文件)
* [4. 一键启动](README.md#4-一键启动)
* [5. 启动界面示例](README.md#5-启动界面示例)
+ 依托于开源 LLM 与 Embedding 模型,可实现全部使用**开源**模型**离线私有部署**。与此同时,也支持
OpenAI GPT API 的调用,并将在持续扩充对各类模型及模型 API 的接入。
+ 实现原理过程包括加载文件 -> 读取文本 -> 文本分割 -> 文本向量化 -> 问句向量化 ->
在文本向量中匹配出与问句向量最相似的 `top k`个 -> 匹配出的文本作为上下文和问题一起添加到 `prompt`中 -> 提交给 `LLM`生成回答。
## 快速上手
### 1. 环境配置
+ 首先,确保你的机器安装了 Python 3.8 - 3.11 (推荐使用 Python3.11)。
```
$ python --version
Python 3.11.7
```
接着,创建一个虚拟环境,并在虚拟环境内安装项目的依赖
```shell
# 拉取仓库
$ git clone https://git.ckcest.cn/machine-learning/Langchain-Chat.git
# 进入目录
$ cd Langchain-Chat
# 安装全部依赖
$ 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
模型可以从 [ModelScope](https://modelscope.cn/models) 下载。
以Qwen3 LLM 模型 [Qwen/Qwen3-8B](https://modelscope.cn/models/Qwen/Qwen3-8B) 与 Embedding
模型 [Qwen/Qwen3-Embedding-8B](https://modelscope.cn/models/Qwen/Qwen3-Embedding-8B) 为例:
下载模型需要先[安装 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://www.modelscope.cn/Qwen/Qwen3-8B.git
$ git clone https://www.modelscope.cn/AI-ModelScope/bge-large-zh.git
```
### 3. 初始化知识库和配置文件
按照下列方式初始化自己的知识库和简单的复制配置文件
```shell
$ python copy_config_example.py
$ python init_database.py --recreate-vs
```
### 4. 一键启动
按照以下命令启动项目
```shell
$ python startup.py -a
```
### 5. 启动界面示例
如果正常启动,将能看到以下界面
1. FastAPI Docs 界面
2. Web UI 启动界面示例:
- Web UI 对话界面
- Web UI 知识库管理页面