mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-27 08:25:07 +00:00
doc: m3e model
This commit is contained in:
8
docSite/content/docs/custom-models/_index.md
Normal file
8
docSite/content/docs/custom-models/_index.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
weight: 0
|
||||
title: '本地模型使用'
|
||||
description: 'FastGPT 对接本地模型'
|
||||
icon: 'model_training'
|
||||
draft: false
|
||||
images: []
|
||||
---
|
71
docSite/content/docs/custom-models/chatglm2.md
Normal file
71
docSite/content/docs/custom-models/chatglm2.md
Normal file
@@ -0,0 +1,71 @@
|
||||
---
|
||||
title: '接入 ChatGLM2-6B'
|
||||
description: ' 将 FastGPT 接入私有化模型 ChatGLM2-6B'
|
||||
icon: 'model_training'
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 753
|
||||
---
|
||||
|
||||
## 前言
|
||||
|
||||
FastGPT 允许你使用自己的 OpenAI API KEY 来快速调用 OpenAI 接口,目前集成了 GPT-3.5, GPT-4 和 embedding,可构建自己的知识库。但考虑到数据安全的问题,我们并不能将所有的数据都交付给云端大模型。
|
||||
|
||||
那么如何在 FastGPT 上接入私有化模型呢?本文就以清华的 ChatGLM2 为例,为各位讲解如何在 FastGPT 中接入私有化模型。
|
||||
|
||||
## ChatGLM2-6B 简介
|
||||
|
||||
ChatGLM2-6B 是开源中英双语对话模型 ChatGLM-6B 的第二代版本,具体介绍可参阅 [ChatGLM2-6B 项目主页](https://github.com/THUDM/ChatGLM2-6B)。
|
||||
|
||||
{{% alert context="warning" %}}
|
||||
注意,ChatGLM2-6B 权重对学术研究完全开放,在获得官方的书面许可后,亦允许商业使用。本教程只是介绍了一种用法,无权给予任何授权!
|
||||
{{% /alert %}}
|
||||
|
||||
## 推荐配置
|
||||
|
||||
依据官方数据,同样是生成 8192 长度,量化等级为 FP16 要占用 12.8GB 显存、int8 为 8.1GB 显存、int4 为 5.1GB 显存,量化后会稍微影响性能,但不多。
|
||||
|
||||
因此推荐配置如下:
|
||||
|
||||
{{< table "table-hover table-striped" >}}
|
||||
| 类型 | 内存 | 显存 | 硬盘空间 | 启动命令 |
|
||||
|------|---------|---------|----------|--------------------------|
|
||||
| fp16 | >=16GB | >=16GB | >=25GB | python openai_api.py 16 |
|
||||
| int8 | >=16GB | >=9GB | >=25GB | python openai_api.py 8 |
|
||||
| int4 | >=16GB | >=6GB | >=25GB | python openai_api.py 4 |
|
||||
{{< /table >}}
|
||||
|
||||
## 环境配置
|
||||
|
||||
- Python 3.8.10
|
||||
- CUDA 11.8
|
||||
- 科学上网环境
|
||||
|
||||
## 部署步骤
|
||||
|
||||
1. 根据上面的环境配置配置好环境,具体教程自行 GPT;
|
||||
2. 下载 [python 文件](https://github.com/labring/FastGPT/blob/main/files/models/ChatGLM2/openai_api.py)
|
||||
3. 在命令行输入命令 `pip install -r requirments.txt`;
|
||||
4. 打开你需要启动的 py 文件,在代码的第 76 行配置 token,这里的 token 只是加一层验证,防止接口被人盗用;
|
||||
5. 执行命令 `python openai_api.py 16`。这里的数字根据上面的配置进行选择。
|
||||
|
||||
然后等待模型下载,直到模型加载完毕为止。如果出现报错先问 GPT。
|
||||
|
||||
启动成功后应该会显示如下地址:
|
||||
|
||||

|
||||
|
||||
> 这里的 `http://0.0.0.0:6006` 就是连接地址。
|
||||
|
||||
然后现在回到 .env.local 文件,依照以下方式配置地址:
|
||||
|
||||
```bash
|
||||
OPENAI_BASE_URL=http://127.0.0.1:6006/v1
|
||||
CHAT_API_KEY=sk-aaabbbcccdddeeefffggghhhiiijjjkkk # 这里是你在代码中配置的 token,这里的 OPENAIKEY 可以任意填写
|
||||
```
|
||||
|
||||
这样就成功接入 ChatGLM2-6B 了。
|
||||
|
||||
## 注意
|
||||
|
||||
1. docker 部署时,给的推荐配置是组网模型,无法连接到本地的网络,以为这无法请求 0.0.0.0:6006。可以使用 host 模式,或者将模型发布到服务器上,并通过 oneapi 引入该模型。
|
81
docSite/content/docs/custom-models/m3e.md
Normal file
81
docSite/content/docs/custom-models/m3e.md
Normal file
@@ -0,0 +1,81 @@
|
||||
---
|
||||
title: '接入 M3E 向量模型'
|
||||
description: ' 将 FastGPT 接入私有化模型 M3E'
|
||||
icon: 'model_training'
|
||||
draft: false
|
||||
toc: true
|
||||
weight: 100
|
||||
---
|
||||
|
||||
## 前言
|
||||
|
||||
FastGPT 默认使用了 openai 的 embedding 向量模型,如果你想私有部署的话,可以使用 M3E 向量模型进行替换。M3E 向量模型属于小模型,资源使用不高,CPU 也可以运行。下面教程是基于 “睡大觉” 同学提供的一个 CPU 版本的镜像。
|
||||
|
||||
## 部署镜像
|
||||
|
||||
镜像名: `stawky/m3e-large-api:latest`
|
||||
端口号: 6008
|
||||
|
||||
## 接入 OneAPI
|
||||
|
||||
添加一个渠道,参数如下:
|
||||
|
||||

|
||||
|
||||
## 测试
|
||||
|
||||
curl 例子:
|
||||
|
||||
```bash
|
||||
curl --location --request POST 'https://domain/v1/embeddings' \
|
||||
--header 'Authorization: Bearer sk-key' \
|
||||
--header 'Content-Type: application/json' \
|
||||
--data-raw '{
|
||||
"model": "m3e",
|
||||
"input": ["laf是什么"]
|
||||
}'
|
||||
```
|
||||
|
||||
Authorization 为 sk-key。model 为刚刚在 OneAPI 填写的自定义模型。
|
||||
|
||||
## 接入 FastGPT
|
||||
|
||||
修改 config.json 配置文件,在 VectorModels 中加入 M3E 模型:
|
||||
|
||||
```json
|
||||
"VectorModels": [
|
||||
{
|
||||
"model": "text-embedding-ada-002",
|
||||
"name": "Embedding-2",
|
||||
"price": 0.2,
|
||||
"defaultToken": 500,
|
||||
"maxToken": 3000
|
||||
},
|
||||
{
|
||||
"model": "m3e",
|
||||
"name": "M3E(测试使用)",
|
||||
"price": 0.1,
|
||||
"defaultToken": 500,
|
||||
"maxToken": 1800
|
||||
}
|
||||
],
|
||||
```
|
||||
|
||||
## 测试使用
|
||||
|
||||
1. 创建知识库时候选择 M3E 模型。
|
||||
|
||||
注意,一旦选择后,知识库将无法修改向量模型。
|
||||
|
||||

|
||||
|
||||
2. 导入数据
|
||||
3. 搜索测试
|
||||
|
||||

|
||||
|
||||
4. 应用绑定知识库
|
||||
|
||||
注意,应用只能绑定同一个向量模型的知识库,不能跨模型绑定。并且,需要注意调整相似度,不同向量模型的相似度(距离)会有所区别,需要自行测试实验。
|
||||
|
||||

|
Reference in New Issue
Block a user