This commit is contained in:
archer
2023-08-08 16:14:03 +08:00
parent 6531af6c3a
commit 5116bf7d25
70 changed files with 617 additions and 411 deletions

View File

@@ -2,8 +2,11 @@
"sidebar.docSidebar.intro": {
"message": "介绍"
},
"sidebar.docSidebar.category.Quick Start": {
"message": "快速开始"
"sidebar.docSidebar.category.Develop": {
"message": "开发"
},
"sidebar.docSidebar.category.Proxy": {
"message": "Proxy 方案"
},
"sidebar.docSidebar.category.Deploy": {
"message": "部署"

View File

@@ -1,92 +0,0 @@
# docker-compose 快速部署
## 代理环境(国外服务器可忽略)
选择一个即可。这只是代理!!!不是项目。
1. [sealos nginx 方案](./proxy/sealos.md) - 推荐。约等于不用钱,不需要额外准备任何东西。
2. [clash 方案](./proxy/clash.md) - 仅需一台服务器(需要有 clash
3. [nginx 方案](./proxy/nginx.md) - 需要一台国外服务器
4. [cloudflare 方案](./proxy/cloudflare.md) - 需要有域名(每日免费 10w 次代理请求)
5. [腾讯云函数代理方案](https://github.com/easychen/openai-api-proxy/blob/master/FUNC.md) - 仅需一台服务器
## openai key 池管理方案
推荐使用 [one-api](https://github.com/songquanpeng/one-api) 项目来管理 key 池,兼容 openai 和微软等多渠道。部署可以看该项目的 README.md也可以看 [在 Sealos 1 分钟部署 one-api](./oneapi/index.md)
### 1. 准备一些内容
> 1. 服务器开通 80 端口。用代理的话,对应的代理端口也需要打开。
> 2. QQ 邮箱 Code进入 QQ 邮箱 -> 账号 -> 申请 SMTP 账号
> 3. 有域名的准备好 SSL 证书
### 2. 安装 docker 和 docker-compose
这个不同系统略有区别,百度安装下。验证安装成功后进行下一步。下面给出一个例子:
```bash
# 安装docker
curl -L https://get.daocloud.io/docker | sh
sudo systemctl start docker
# 安装 docker-compose
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# 验证安装
docker -v
docker-compose -v
# 如果docker-compose运行不了可以把 deploy/fastgpt/docker-compose 文件复制到服务器,然后在 docker-compose 文件夹里执行 sh init.sh。会把docker-compose文件复制到对应目录。
```
### 2. 创建 3 个初始化文件
将 [fastgpt](https://github.com/labring/FastGPT/blob/main/files/deploy/fastgpt) 文件夹中三个文件复制到服务器分别为fastgpt/docker-compose.yaml, fastgpt/pg/init.sql, fastgpt/nginx/nginx.conf
可以手动创建或者直接把整个 fastgpt 文件夹复制过去。
### 3. 运行 docker-compose
下面是一个辅助脚本,也可以直接 docker-compose up -d
**run.sh 运行文件**
```bash
#!/bin/bash
docker-compose pull
docker-compose up -d
echo "Docker Compose 重新拉取镜像完成!"
# 删除本地旧镜像
images=$(docker images --format "{{.ID}} {{.Repository}}" | grep fastgpt)
# 将镜像 ID 和名称放入数组中
IFS=$'\n' read -rd '' -a image_array <<<"$images"
# 遍历数组并删除所有旧的镜像
for ((i=1; i<${#image_array[@]}; i++))
do
image=${image_array[$i]}
image_id=${image%% *}
docker rmi $image_id
done
```
## FastGpt Admin
参考 admin 里的 README.md
## 其他优化点
# Git Action 自动打包镜像
.github 里拥有一个 git 提交到 main 分支时自动打包 amd64 和 arm64 镜像的 actions。你仅需要提前在 git 配置好 session。
1. 创建账号 session: 头像 -> settings -> 最底部 Developer settings -> Personal access tokens -> tokens(classic) -> 创建新 session把一些看起来需要的权限勾上。
2. 添加 session 到仓库: 仓库 -> settings -> Secrets and variables -> Actions -> 创建 secret
3. 填写 secret: Name-GH_PAT, Secret-第一步的 tokens
## 其他问题
### Mac 可能的问题
> 因为教程有部分镜像不兼容 arm64所以写个文档指导新手如何快速在 mac 上面搭建 fast-gpt[在 mac 上面部署 fastgpt 可能存在的问题](./mac.md)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 MiB

View File

@@ -0,0 +1,175 @@
# docker-compose 快速部署
## 一、预先准备
### 准备好代理环境(国外服务器可忽略)
确保可访问到 OpenAI方案可参考[sealos nginx 中转](../proxy/sealos)
### OneAPI (可选,需要多模型和 key 轮询时使用)
推荐使用 [one-api](https://github.com/songquanpeng/one-api) 项目来管理 key 池,兼容 openai 、微软和国内主流模型等。
部署可以看该项目的 [README.md](https://github.com/songquanpeng/one-api),也可以看 [在 Sealos 1 分钟部署 one-api](../oneapi)
## 二、安装 docker 和 docker-compose
这个不同系统略有区别,百度安装下。验证安装成功后进行下一步。下面给出 centos 一个例子:
```bash
# 安装docker
curl -L https://get.daocloud.io/docker | sh
sudo systemctl start docker
# 安装 docker-compose
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
# 验证安装
docker -v
docker-compose -v
```
## 三、创建 docker-compose.yml 文件
```yml
# 非 host 版本, 不使用本机代理
version: '3.3'
services:
pg:
image: ghcr.io/c121914yu/fastgpt:latest # git
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/pgvector:v0.4.2 # 阿里云
container_name: pg
restart: always
ports: # 生产环境建议不要暴露
- 5432:5432
networks:
- fastgpt
environment:
# 这里的配置只有首次运行生效。修改后,重启镜像是不会生效的。需要把持久化数据删除再重启,才有效果
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgres
volumes:
- ./pg/data:/var/lib/postgresql/data
mongo:
image: mongo:5.0.18
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/mongo:5.0.18 # 阿里云
container_name: mongo
restart: always
ports: # 生产环境建议不要暴露
- 27017:27017
networks:
- fastgpt
environment:
# 这里的配置只有首次运行生效。修改后,重启镜像是不会生效的。需要把持久化数据删除再重启,才有效果
- MONGO_INITDB_ROOT_USERNAME=username
- MONGO_INITDB_ROOT_PASSWORD=password
volumes:
- ./mongo/data:/data/db
fastgpt:
container_name: fastgpt
# image: c121914yu/fast-gpt:latest # docker hub
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:latest # 阿里云
ports:
- 3000:3000
networks:
- fastgpt
depends_on:
- mongo
- pg
restart: always
environment:
# root 密码,用户名为: root
- DEFAULT_ROOT_PSW=1234
# 中转地址,如果是用官方号,不需要管
- OPENAI_BASE_URL=https://api.openai.com/v1
- CHAT_API_KEY=sk-xxxx
- DB_MAX_LINK=5 # database max link
- TOKEN_KEY=any
- ROOT_KEY=root_key
# mongo 配置,不需要改
- MONGODB_URI=mongodb://username:password@mongo:27017/?authSource=admin
- MONGODB_NAME=fastgpt
# pg配置.
- PG_HOST=pg
- PG_PORT=5432
- PG_USER=username
- PG_PASSWORD=password
- PG_DB_NAME=postgres
networks:
fastgpt:
```
```yml
# host 版本, 不推荐。
version: '3.3'
services:
pg:
image: ankane/pgvector:v0.4.2 # dockerhub
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/pgvector:v0.4.2 # 阿里云
container_name: pg
restart: always
ports: # 生产环境建议不要暴露
- 5432:5432
environment:
# 这里的配置只有首次运行生效。修改后,重启镜像是不会生效的。需要把持久化数据删除再重启,才有效果
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
- POSTGRES_DB=postgres
volumes:
- ./pg/data:/var/lib/postgresql/data
mongo:
image: mongo:5.0.18
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/mongo:5.0.18 # 阿里云
container_name: mongo
restart: always
ports: # 生产环境建议不要暴露
- 27017:27017
environment:
# 这里的配置只有首次运行生效。修改后,重启镜像是不会生效的。需要把持久化数据删除再重启,才有效果
- MONGO_INITDB_ROOT_USERNAME=username
- MONGO_INITDB_ROOT_PASSWORD=password
volumes:
- ./mongo/data:/data/db
- ./mongo/logs:/var/log/mongodb
fastgpt:
# image: ghcr.io/c121914yu/fastgpt:latest # github
# image: c121914yu/fast-gpt:latest # docker hub
image: registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:latest # 阿里云
network_mode: host
restart: always
container_name: fastgpt
environment:
# root 密码,用户名为: root
- DEFAULT_ROOT_PSW=1234
# 中转地址,如果是用官方号,不需要管
- OPENAI_BASE_URL=https://api.openai.com/v1
- CHAT_API_KEY=sk-xxxx
- DB_MAX_LINK=5 # database max link
# token加密凭证随便填作为登录凭证
- TOKEN_KEY=any
# root key, 最高权限,可以内部接口互相调用
- ROOT_KEY=root_key
# mongo 配置,不需要改
- MONGODB_URI=mongodb://username:password@0.0.0.0:27017/?authSource=admin
- MONGODB_NAME=fastgpt
# pg 配置
- PG_HOST=0.0.0.0
- PG_PORT=5432
- PG_USER=username
- PG_PASSWORD=password
- PG_DB_NAME=postgres
```
## 四、运行 docker-compose
```bash
# 在 docker-compose.yml 同级目录下执行
docker-compose up -d
```
## 五、访问
如果需要域名访问,自行安装 Nginx。目前可以通过: `ip:3000` 直接访问(注意防火墙)。登录用户名为 root密码为刚刚环境变量里设置的 `DEFAULT_ROOT_PSW`
## 一些问题

View File

@@ -1,4 +1,4 @@
# Mac 上部署可能遇到的问题
# Mac 上部署可能遇到的问题(旧版)
### 前置条件

View File

@@ -0,0 +1,13 @@
---
sidebar_position: 1
---
# Sealos 一键部署
无需服务器、无需魔法、无需域名,点击即可部署 👇
[![](https://raw.githubusercontent.com/labring-actions/templates/main/Deploy-on-Sealos.svg)](https://cloud.sealos.io/?openapp=system-fastdeploy%3FtemplateName%3Dfastgpt)
由于需要部署数据库,部署完后需要等待 2~4 分钟才能正常访问。
## 运行

View File

@@ -0,0 +1,37 @@
# 本地开发
第一次开发,需要先部署数据库,建议本地开发可以随便找一台 2c2g 的轻量小数据库实践。数据库部署教程:[Docker 快速部署](../deploy/docker.md)
client 目录下为 FastGPT 核心代码。NextJS 框架前后端在一起的api 服务位于 src/pages/api 内。
## 初始配置
**1. 环境变量**
复制.env.template 文件,生成一个.env.local 环境变量文件夹,修改.env.local 里内容才是有效的变量。变量说明见 .env.template
**2. config 配置文件**
复制 data/config.json 文件,生成一个 data/config.local.json 配置文件。
这个文件大部分时候不需要修改。只需要关注 SystemParams 里的参数:
```
"vectorMaxProcess": 向量生成最大进程,根据数据库和 key 的并发数来决定,通常单个 120 号2c4g 服务器设置10~15。
"qaMaxProcess": QA 生成最大进程
"pgIvfflatProbe": PG vector 搜索探针,没有添加 vector 索引时可忽略。
```
## 运行
```
cd client
pnpm i
pnpm dev
```
## 镜像打包
```bash
docker build -t c121914yu/fastgpt .
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 MiB

View File

@@ -36,18 +36,10 @@ http {
open_file_cache_errors off;
server {
listen 443 ssl;
server_name your_host;
ssl_certificate /ssl/your_host.pem;
ssl_certificate_key /ssl/your_host.key;
ssl_session_timeout 5m;
listen 3999;
server_name 你的 ip 地址;
location ~ /openai/(.*) {
# auth check
if ($auth != "xxxxxx") {
return 403;
}
proxy_pass https://api.openai.com/$1$is_args$args;
proxy_set_header Host api.openai.com;
proxy_set_header X-Real-IP $remote_addr;
@@ -64,10 +56,5 @@ http {
proxy_busy_buffers_size 256k;
}
}
server {
listen 80;
server_name ai.fastgpt.run;
rewrite ^(.*) https://$server_name$1 permanent;
}
}
```

View File

@@ -1,23 +1,29 @@
# sealos 部署 openai 中转
---
sidebar_position: 1
---
# sealos 部署 nginx 实现中转
## 登录 sealos cloud
[sealos cloud](https://cloud.sealos.io/)
## 创建应用
## 一、点击创建应用
打开 App Launchpad -> 新建应用
![step1](./imgs//sealos1.png)
![step2](./imgs//sealos2.png)
### 开启外网访问
### 二、填写基本配置
务必开启外网访问,复制下外网访问提供的地址。
![step3](./imgs//sealos3.png)
### 添加 configmap 文件
### 三、添加 configmap 文件
1. 复制下面这段代码,注意 `server_name` 后面的内容替换成上图的地址。
1. 复制下面这段配置文件,注意 `server_name` 后面的内容替换成第二步的外网访问地址。
```
user nginx;
@@ -43,17 +49,11 @@ http {
proxy_buffer_size 128k;
proxy_buffers 4 256k;
server {
listen 80;
server_name tgohwtdlrmer.cloud.sealos.io; # 这个地方替换成 sealos 提供的内容
location ~ /openai/(.*) {
# auth check
if ($http_auth != "auth") { # 安全凭证
return 403;
}
proxy_pass https://api.openai.com/$1$is_args$args;
proxy_set_header Host api.openai.com;
proxy_set_header X-Real-IP $remote_addr;
@@ -81,20 +81,22 @@ http {
![step4](./imgs//sealos4.png)
### 部署应用
### 四、部署应用
填写完毕后,点击右上角的 `部署应用`,即可完成。
## 修改 FastGpt 环境变量
## 五、修改 FastGpt 环境变量
1. 进入刚刚部署应用的详情,复制外网地址
![step5](./imgs//sealos5.png)
注意:这是个 API 地址,点击打开是无效的。如需验证,可以访问: 【\*\*\*.close.sealos.io/openai/api】如果提示 "Invalid URL (GET /api)" 则代表成功。
![step5](./imgs//sealos5.png)
2. 修改环境变量(是 FastGpt 的环境变量,不是 sealos 的):
```
OPENAI_BASE_URL=https://tgohwtdlrmer.cloud.sealos.io/openai/v1
OPENAI_BASE_URL_AUTH=auth
```
**Done!**

Binary file not shown.

After

Width:  |  Height:  |  Size: 596 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 428 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 177 KiB

View File

@@ -2,7 +2,7 @@
sidebar_position: 1
---
# FastGpt 是什么?
# 快速了解 FastGpt
FastGPT 是一个基于向量 + LLM 模型的 AI 问答系统。可以帮助你快捷、高效的将内部文档进行训练。提供了丰富的调试工具便于调整数据,并可以通过 Iframe 或 API 的形式接入到你现有的应用中。
@@ -11,33 +11,38 @@ FastGPT 是一个基于向量 + LLM 模型的 AI 问答系统。可以帮助你
| ![Demo](./imgs/intro1.png) | ![Demo](./imgs/intro2.png) |
| ![Demo](./imgs/intro3.png) | ![Demo](./imgs/intro4.png) |
#### 知识库原理图
## FastGPT 能力
### 1. AI 客服
通过导入文档或已有问答对进行训练,让 AI 模型能根据你的文档进行回答问题。
![Ability1](./imgs/ability1.png)
### 2. 自动数据预处理
提供手动输入、直接分段、LLM 自动处理和 CSV 等多种数据导入途径,兼顾精确和快速训练场景。
![Ability1](./imgs/ability2.png)
### 3. 工作流编排
基于 Flow 模块的工作流编排,可以帮助你设计更加复杂的问答流程。例如查询数据库、查询库存、预约实验室等。
![Ability1](./imgs/ability3.png)
### 4. 无缝衔接的 OpenAPI
FastGPT 对外 API 接口对齐 GPT 官方接口,你可以直接在现有的 GPT 应用中通过修改 BaseURL 和 Authorization 即可接入 FastGPT。
![Ability1](./imgs/ability4.png)
## FastGPT 特点
1. 项目开源。FastGPT 遵循 Apache License 2.0 开源协议,你可以在 GitHub Clone FastGPT 进行二次开发和发布。FastGPT 社区版将保留核心的功能,商业版仅在社区版基础上使用 API 的形式进行扩展,不影响学习使用。
2. 独特的 QA 结构。针对客服问答场景设计的 QA 结构,提高在大量数据场景中的准确性。
3. 可视化工作流。通过 Flow 模块展示了从问题输入到模型输出的完整流程,便于调试和设计复杂流程。
4. 无限扩展。基于 HTTP 进行扩展,无需修改 FastGPT 源码,也可快速接入现有的程序中。
5. 便捷调试。提供搜索测试、引用修改、完整对话预览等多种调试途径。
6. 支持多种模型:支持 GPT、Claude、文心一言等多类 LLM 模型,未来也将支持自定义的向量模型。
## 知识库核心流程图
![KBProcess](./imgs/KBProcess.jpg?raw=true 'KBProcess')
## 🏘️ 交流群
添加 wx 进入:
![Demo](https://otnvvf-imgs.oss.laf.run/wx300.jpg)
## Powered by
- [TuShan: 5 分钟搭建后台管理系统](https://github.com/msgbyte/tushan)
- [Laf: 3 分钟快速接入三方应用](https://github.com/labring/laf)
- [Sealos: 快速部署集群应用](https://github.com/labring/sealos)
- [One API: 令牌管理 & 二次分发,支持 Azure](https://github.com/songquanpeng/one-api)
## 👀 其他
- [FastGpt 常见问题](https://kjqvjse66l.feishu.cn/docx/HtrgdT0pkonP4kxGx8qcu6XDnGh)
- [docker 部署教程视频](https://www.bilibili.com/video/BV1jo4y147fT/)
- [公众号接入视频教程](https://www.bilibili.com/video/BV1xh4y1t7fy/)
- [FastGpt 知识库演示](https://www.bilibili.com/video/BV1Wo4y1p7i1/)
## 第三方生态
- [luolinAI: 企微机器人,开箱即用](https://github.com/luolin-ai/FastGPT-Enterprise-WeChatbot)
## 🌟 Star History
[![Star History Chart](https://api.star-history.com/svg?repos=labring/FastGPT&type=Date)](https://star-history.com/#labring/FastGPT&Date)

View File

@@ -1,23 +0,0 @@
# 本地开发
第一次开发,请先[部署教程](../deploy/docker.md),需要部署数据库.
client: FastGpt 网页项目
admin: 管理端
## 环境变量配置 (可能更新不及时,以 docker-compose 里的变量为准)
复制.env.template 文件,生成一个.env.local 环境变量文件夹,修改.env.local 里内容。
## 运行
```
pnpm dev
```
## 镜像打包
```bash
# 代理可选,不需要的去掉
docker build -t registry.cn-hangzhou.aliyuncs.com/fastgpt/fastgpt:latest . --network host --build-arg HTTP_PROXY=http://127.0.0.1:7890 --build-arg HTTPS_PROXY=http://127.0.0.1:7890
```

View File

@@ -1,6 +1,6 @@
{
"item.label.Docs": {
"message": "教程文档"
"message": "文档"
},
"item.label.Start Now": {
"message": "在线使用"