Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Mar 23, 2024
1 parent 471db41 commit 51e8b13
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bugs.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ assignees: ''
**你的版本**

- [ ] 公有云版本
- [ ] 私有部署版本
- [ ] 私有部署版本, 具体版本号:

**问题描述**

Expand Down
75 changes: 73 additions & 2 deletions docSite/content/docs/development/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ docker-compose up -d

可以通过`ip:3001`访问OneAPI,默认账号为`root`密码为`123456`

在OneApi中添加合适的渠道
在OneApi中添加合适的AI模型渠道

## 五、访问 FastGPT

目前可以通过 `ip:3000` 直接访问(注意防火墙)。登录用户名为 `root`,密码为`docker-compose.yml`环境变量里设置的 `DEFAULT_ROOT_PSW`

如果需要域名访问,请自行安装并配置 Nginx。

首次运行,会自动初始化 root 用户,密码为 `1234`(与环境变量中的`DEFAULT_ROOT_PSW`一致),日志里会提示一次`MongoServerError: Unable to read from a snapshot due to pending collection catalog changes;`可忽略。

## FAQ

Expand Down Expand Up @@ -197,4 +198,74 @@ rs.status()
```bash
docker-compose down
docker-compose up -d
```
```
### 如何更新版本?
1. 查看[更新文档](/docs/development/upgrading/intro/),确认要升级的版本,避免跨版本升级。
2. 修改镜像 tag 到指定版本
3. 执行下面命令会自动拉取镜像:
```bash
docker-compose pull
docker-compose up -d
```
4. 执行初始化脚本(如果有)
### 如何自定义配置文件?
修改`config.json`文件,并执行`docker-compose down`再执行`docker-compose up -d`重起容器。具体配置,参考[配置详解](/docs/development/configuration)。
### 如何检查自定义配置文件是否挂载
1. `docker logs fastgpt` 可以查看日志,在启动容器后,第一次请求网页,会进行配置文件读取,可以看看有没有读取成功以及有无错误日志。
2. `docker exec -it fastgpt sh` 进入 FastGPT 容器,可以通过`ls data`查看目录下是否成功挂载`config.json`文件。可通过`cat data/config.json`查看配置文件。
**可能不生效的原因**
1. 挂载目录不正确
2. 配置文件不正确,日志中会提示`invalid json`,配置文件需要是标准的 JSON 文件。
3. 修改后,没有`docker-compose down``docker-compose up -d`,restart是不会重新挂载文件的。
### 如何检查环境变量是否正常加载
1. `docker exec -it fastgpt sh` 进入 FastGPT 容器。
2. 直接输入`env`命令查看所有环境变量。
### 为什么无法连接`本地模型`镜像。
`docker-compose.yml`中使用了桥接的模式建立了`fastgpt`网络,如想通过0.0.0.0或镜像名访问其它镜像,需将其它镜像也加入到网络中。
### 端口冲突怎么解决?
docker-compose 端口定义为:`映射端口:运行端口`
桥接模式下,容器运行端口不会有冲突,但是会有映射端口冲突,只需将映射端口修改成不同端口即可。
如果`容器1`需要连接`容器2`,使用`容器2:运行端口`来进行连接即可。
(自行补习 docker 基本知识)
### relation "modeldata" does not exist
PG 数据库没有连接上/初始化失败,可以查看日志。FastGPT 会在每次连接上 PG 时进行表初始化,如果报错会有对应日志。
1. 检查数据库容器是否正常启动
2. 非 docker 部署的,需要手动安装 pg vector 插件
3. 查看 fastgpt 日志,有没有相关报错
### Operation `auth_codes.findOne()` buffering timed out after 10000ms
mongo连接失败,查看mongo的运行状态对应日志。
可能原因:
1. mongo 服务有没有起来(有些 cpu 不支持 AVX,无法用 mongo5,需要换成 mongo4.x,可以dockerhub找个最新的4.x,修改镜像版本,重新运行)
2. 环境变量(账号密码,注意host和port)
3. 副本集启动失败。
### 首次部署,root用户提示未注册
没有启动 Mongo 副本集模式。
85 changes: 13 additions & 72 deletions docSite/content/docs/development/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,10 @@ images: []

可以。需要准备好向量模型和LLM模型。

### insufficient_user_quota user quota is not enough

OneAPI 账号的余额不足,默认 root 用户只有 200 刀,可以手动修改。

### xxx渠道找不到

OneAPI 中没有配置该模型渠道。或者是修改了配置文件中一部分的模型,但没有全部修改。

### 页面中可以正常回复,API 报错

页面中是用 stream=true 模式,所以API也需要设置 stream=true 来进行测试。部分模型接口(国产居多)非 Stream 的兼容有点垃圾。

### Incorrect API key provided: sk-xxxx.You can find your api Key at xxx

OneAPI 的 API Key 配置错误,需要修改`OPENAI_API_KEY`环境变量,并重启容器(先 docker-compose down 然后再 docker-compose up -d 运行一次)。可以`exec`进入容器,`env`查看环境变量是否生效。

### 其他模型没法进行问题分类/内容提取

需要给其他模型配置`toolChoice=false`,就会默认走提示词模式。目前内置提示词仅针对了商业模型API进行测试,国内外的商业模型基本都可用。
Expand All @@ -54,85 +42,38 @@ OneAPI 的 API Key 配置错误,需要修改`OPENAI_API_KEY`环境变量,并
1. 问题补全需要经过一轮AI生成。
2. 会进行3~5轮的查询,如果数据库性能不足,会有明显影响。

### 模型响应为空
### 模型响应为空(core.chat.Chat API is error or undefined)

1. 检查 key 问题。
2. 如果是国内模型,可能是命中风控了。
3. 查看模型请求日志,检查出入参数是否异常。

### 知识库索引没有进度

先看日志报错信息。
先看日志报错信息。有以下几种情况:

1. 可以对话,但是索引没有进度:没有配置向量模型(vectorModels)
2. 不能对话,也不能索引:API调用失败。可能是没连上OneAPI或OpenAI
3. 有进度,但是非常慢:api key不行,OpenAI的免费号,一分钟只有3次还是60次。一天上限200次。

## 三、Docker 部署常见问题

### 如何更新?

1. 查看[更新文档](/docs/development/upgrading/intro/),确认要升级的版本,避免跨版本升级。
2. 修改镜像 tag 到指定版本
3. 执行下面命令会自动拉取镜像:

```bash
docker-compose pull
docker-compose up -d
```

4. 执行初始化脚本(如果有)

### 如何自定义配置文件?

修改`config.json`文件,并执行`docker-compose down`再执行`docker-compose up -d`重起容器。具体配置,参考[配置详解](/docs/development/configuration)。
### Connection error

### 如何检查自定义配置文件是否挂载
网络异常。国内服务器无法请求OpenAI,自行检查与AI模型的连接是否正常。

1. `docker logs fastgpt` 可以查看日志,在启动容器后,第一次请求网页,会进行配置文件读取,可以看看有没有读取成功以及有无错误日志。
2. `docker exec -it fastgpt sh` 进入 FastGPT 容器,可以通过`ls data`查看目录下是否成功挂载`config.json`文件。可通过`cat data/config.json`查看配置文件。
## 三、常见的 OneAPI 错误

**可能不生效的原因**

1. 挂载目录不正确
2. 配置文件不正确,日志中会提示`invalid json`,配置文件需要是标准的 JSON 文件。
3. 修改后,没有`docker-compose down``docker-compose up -d`,restart是不会重新挂载文件的。

### 如何检查环境变量是否正常加载

1. `docker exec -it fastgpt sh` 进入 FastGPT 容器。
2. 直接输入`env`命令查看所有环境变量。


### 为什么无法连接`本地模型`镜像。

`docker-compose.yml`中使用了桥接的模式建立了`fastgpt`网络,如想通过0.0.0.0或镜像名访问其它镜像,需将其它镜像也加入到网络中。

### 端口冲突怎么解决?

docker-compose 端口定义为:`映射端口:运行端口`

桥接模式下,容器运行端口不会有冲突,但是会有映射端口冲突,只需将映射端口修改成不同端口即可。

如果`容器1`需要连接`容器2`,使用`容器2:运行端口`来进行连接即可。

(自行补习 docker 基本知识)
### insufficient_user_quota user quota is not enough

### relation "modeldata" does not exist
OneAPI 账号的余额不足,默认 root 用户只有 200 刀,可以手动修改。

PG 数据库没有连接上/初始化失败,可以查看日志。FastGPT 会在每次连接上 PG 时进行表初始化,如果报错会有对应日志。
### xxx渠道找不到

1. 检查数据库容器是否正常启动
2. 非 docker 部署的,需要手动安装 pg vector 插件
3. 查看 fastgpt 日志,有没有相关报错
OneAPI 中没有配置该模型渠道。或者是修改了配置文件中一部分的模型,但没有全部修改。

### Operation `auth_codes.findOne()` buffering timed out after 10000ms
如果OneAPI中,没有配置对应的模型,`config.json`中也不要配置,否则容易报错。

mongo连接失败,检查
1. mongo 服务有没有起来(有些 cpu 不支持 AVX,无法用 mongo5,需要换成 mongo4.x,可以dockerhub找个最新的4.x,修改镜像版本,重新运行)
2. 环境变量(账号密码,注意host和port)
3. 副本集启动失败,一直在重启:没挂载mongo key;key没有权限;
### Incorrect API key provided: sk-xxxx.You can find your api Key at xxx

### 首次部署,root用户提示未注册
OneAPI 的 API Key 配置错误,需要修改`OPENAI_API_KEY`环境变量,并重启容器(先 docker-compose down 然后再 docker-compose up -d 运行一次)。

没有启动 Mongo 副本集模式
可以`exec`进入容器,`env`查看环境变量是否生效
2 changes: 1 addition & 1 deletion docSite/content/docs/development/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ git clone [email protected]:<github_username>/FastGPT.git

第一次开发,需要先部署数据库,建议本地开发可以随便找一台 2C2G 的轻量小数据库实践。数据库部署教程:[Docker 快速部署](/docs/development/docker/)。部署完了,可以本地访问其数据库。

Mongo 数据库需要修改副本集的`host`,从原来的`mongo:27017`修改为`ip:27017`(ip为对应的公网IP)
Mongo 数据库需要注意,需要注意在连接地址中增加 `directConnection=true` 参数,才能连接上副本集的数据库

### 4. 初始配置

Expand Down
26 changes: 15 additions & 11 deletions files/deploy/fastgpt/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 数据库的默认账号和密码仅首次运行时设置有效
# 如果修改了账号密码,记得改数据库和项目连接参数,别只改一处~
# 该配置文件只是给快速启动,测试使用。正式使用,记得务必修改账号密码,以及调整合适的知识库参数,共享内存等。

version: '3.3'
services:
pg:
Expand Down Expand Up @@ -37,13 +41,15 @@ services:
openssl rand -base64 128 > /data/mongodb.key
chmod 400 /data/mongodb.key
chown 999:999 /data/mongodb.key
echo 'rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "mongo:27017" }
]
})
console.log("finish")' > /data/initReplicaSet.js
echo 'const isInited = rs.status().ok === 1
if(!isInited){
rs.initiate({
_id: "rs0",
members: [
{ _id: 0, host: "mongo:27017" }
]
})
}' > /data/initReplicaSet.js
# 启动MongoDB服务
exec docker-entrypoint.sh "$@" &
Expand Down Expand Up @@ -73,12 +79,10 @@ services:
environment:
# root 密码,用户名为: root
- DEFAULT_ROOT_PSW=1234
# AI API的地址。务必加 /v1,下面默认填了 oneapi 的地址
# 中转地址,如果是用官方号,不需要管。务必加 /v1
- OPENAI_BASE_URL=http://oneapi:3000/v1
# API 密钥
- CHAT_API_KEY=sk-fastgpt
# database max link
- DB_MAX_LINK=30
- DB_MAX_LINK=30 # database max link
- TOKEN_KEY=any
- ROOT_KEY=root_key
- FILE_TOKEN_KEY=filetoken
Expand Down
3 changes: 1 addition & 2 deletions packages/service/support/user/team/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ export async function createDefaultTeam({
});

if (!tmb) {
console.log('create default team', userId);

// create
const [{ _id: insertedId }] = await MongoTeam.create(
[
Expand Down Expand Up @@ -99,6 +97,7 @@ export async function createDefaultTeam({
],
{ session }
);
console.log('create default team', userId);
} else {
console.log('default team exist', userId);
await MongoTeam.findByIdAndUpdate(tmb.teamId, {
Expand Down
2 changes: 1 addition & 1 deletion projects/app/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ OPENAI_BASE_URL=https://api.openai.com/v1
# 通用key。可以是 openai 的也可以是 oneapi 的。
# 此处逻辑:优先走 ONEAPI_URL,如果填写了 ONEAPI_URL,key 也需要是 ONEAPI 的 key
CHAT_API_KEY=sk-xxxx
# mongo 数据库连接参数
# mongo 数据库连接参数,本地开发时,mongo可能需要增加 directConnection=true 参数,才能连接上。
MONGODB_URI=mongodb://username:[email protected]:27017/fastgpt?authSource=admin
# PG 数据库连接参数
PG_URL=postgresql://username:password@host:port/postgres
Expand Down
22 changes: 12 additions & 10 deletions projects/app/src/service/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function connectToDatabase(): Promise<void> {
afterHook: async () => {
// init system config
getInitConfig();
// init vector database, init root user
//init vector database, init root user
await Promise.all([initVectorStore(), initRootUser()]);

startMongoWatch();
Expand All @@ -36,7 +36,7 @@ export function connectToDatabase(): Promise<void> {
});
}

async function initRootUser() {
async function initRootUser(retry = 3) {
try {
const rootUser = await MongoUser.findOne({
username: 'root'
Expand All @@ -48,12 +48,9 @@ async function initRootUser() {
await mongoSessionRun(async (session) => {
// init root user
if (rootUser) {
await MongoUser.findOneAndUpdate(
{ username: 'root' },
{
password: hashStr(psw)
}
);
await rootUser.updateOne({
password: hashStr(psw)
});
} else {
const [{ _id }] = await MongoUser.create(
[
Expand All @@ -75,7 +72,12 @@ async function initRootUser() {
password: psw
});
} catch (error) {
console.log('init root user error', error);
exit(1);
if (retry > 0) {
console.log('retry init root user');
return initRootUser(retry - 1);
} else {
console.error('init root user error', error);
exit(1);
}
}
}

0 comments on commit 51e8b13

Please sign in to comment.