Skip to content

Commit

Permalink
4.6.9-production (#952)
Browse files Browse the repository at this point in the history
* move components to web package (#37)

* move components

* fix

* fix: cq connection

* fix pagination (#41)

* doc

* openapi config

* fix team share app lose (#42)

* fix: ts

* doc

* doc

---------

Co-authored-by: heheer <[email protected]>
Co-authored-by: yst <[email protected]>
  • Loading branch information
3 people authored Mar 8, 2024
1 parent 46d9a64 commit 4d66e0f
Show file tree
Hide file tree
Showing 61 changed files with 289 additions and 140 deletions.
57 changes: 51 additions & 6 deletions docSite/content/docs/development/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ curl -O https://raw.githubusercontent.com/labring/FastGPT/main/projects/app/data
```bash
# 进入项目目录
cd 项目目录
# 创建 mongo 密钥
openssl rand -base64 756 > ./mongodb.key
# 600不行可以用chmod 999
chmod 600 ./mongodb.key
chown 999:root ./mongodb.key
# 启动容器
docker-compose pull
docker-compose up -d
Expand All @@ -128,7 +123,7 @@ docker ps
# 进入容器
docker exec -it mongo bash

# 连接数据库
# 连接数据库(这里要填Mongo的用户名和密码)
mongo -u myname -p mypassword --authenticationDatabase admin

# 初始化副本集。如果需要外网访问,mongo:27017 可以改成 ip:27017。但是需要同时修改 FastGPT 连接的参数(MONGODB_URI=mongodb://myname:mypassword@mongo:27017/fastgpt?authSource=admin => MONGODB_URI=mongodb://myname:mypassword@ip:27017/fastgpt?authSource=admin)
Expand All @@ -142,8 +137,58 @@ rs.initiate({
rs.status()
```
**关于 host: "mongo:27017" 说明**
1. mongo:27017 代表指向同一个 docker 网络的 mongo 容器的 27017 服务。因此,如果使用该参数,外网是无法访问到数据库的。
2. ip:27017 (ip替换成公网IP):代表通过你的公网IP进行访问。如果用该方法,同时需要修改 docker-compose 中 mongo 的连接参数,因为默认是用 `mongo:27017` 进行连接。
## 五、访问 FastGPT
目前可以通过 `ip:3000` 直接访问(注意防火墙)。登录用户名为 `root`,密码为`docker-compose.yml`环境变量里设置的 `DEFAULT_ROOT_PSW`
如果需要域名访问,请自行安装并配置 Nginx。
## FAQ
### Mongo 启动失败
docker-compose 示例优化 Mongo 副本集参数,不需要手动创建再挂载。如果无法启动,可以尝试更换下面的脚本:
1. 终端中执行:
```bash
openssl rand -base64 756 > ./mongodb.key
chmod 600 ./mongodb.key
chown 999:root ./mongodb.key
```
2. 修改 docker-compose.yml:
```yml
mongo:
# image: mongo:5.0.18
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/mongo:5.0.18 # 阿里云
container_name: mongo
ports:
- 27017:27017
networks:
- fastgpt
command: mongod --keyFile /data/mongodb.key --replSet rs0
environment:
# 默认的用户名和密码,只有首次允许有效
- MONGO_INITDB_ROOT_USERNAME=myname
- MONGO_INITDB_ROOT_PASSWORD=mypassword
volumes:
- ./mongo/data:/data/db
- ./mongodb.key:/data/mongodb.key
```
3. 重启服务
```bash
docker-compose down
docker-compose up -d
```
4. 进入容器执行副本集合初始化(看上方)
15 changes: 13 additions & 2 deletions docSite/content/docs/development/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ OneAPI 的 API Key 配置错误,需要修改`OPENAI_API_KEY`环境变量,并
### 页面崩溃

1. 关闭翻译
2. 检查配置文件是否正常加载,如果没有正常加载会导致缺失系统信息,在某些操作下会导致空指针。(95%)
2. 检查配置文件是否正常加载,如果没有正常加载会导致缺失系统信息,在某些操作下会导致空指针。(95%情况,可以F12打开控制台,看具体的空指针情况
3. 某些api不兼容问题(较少)

### 开启内容补全后,响应速度变慢

1. 问题补全需要经过一轮AI生成。
2. 会进行3~5轮的查询,如果数据库性能不足,会有明显影响。

## 私有部署问题

### 知识库索引没有进度
Expand Down Expand Up @@ -80,7 +85,7 @@ OneAPI 的 API Key 配置错误,需要修改`OPENAI_API_KEY`环境变量,并

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

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

### 如何检查自定义配置文件是否挂载

Expand All @@ -93,6 +98,12 @@ OneAPI 的 API Key 配置错误,需要修改`OPENAI_API_KEY`环境变量,并
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或镜像名访问其它镜像,需将其它镜像也加入到网络中。
Expand Down
2 changes: 1 addition & 1 deletion docSite/content/docs/development/upgrading/469.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'V4.6.9(进行中)'
title: 'V4.6.9'
description: 'FastGPT V4.6.9更新说明'
icon: 'upgrade'
draft: false
Expand Down
16 changes: 11 additions & 5 deletions files/deploy/fastgpt/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,27 @@ services:
volumes:
- ./pg/data:/var/lib/postgresql/data
mongo:
image: mongo:5.0.18
# image: registry.cn-hangzhou.aliyuncs.com/fastgpt/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
command: mongod --keyFile /data/mongodb.key --replSet rs0
environment:
# 默认的用户名和密码,只有首次允许有效
- MONGO_INITDB_ROOT_USERNAME=myname
- MONGO_INITDB_ROOT_USERNAME=myusername
- MONGO_INITDB_ROOT_PASSWORD=mypassword
volumes:
- ./mongo/data:/data/db
- ./mongodb.key:/data/mongodb.key
entrypoint:
- bash
- -c
- |
openssl rand -base64 128 > /data/mongodb.key
chmod 400 /data/mongodb.key
chown 999:999 /data/mongodb.key
exec docker-entrypoint.sh $$@
fastgpt:
container_name: fastgpt
image: ghcr.io/labring/fastgpt:latest # git
Expand Down
2 changes: 2 additions & 0 deletions packages/global/common/system/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export type SystemEnvType = {
vectorMaxProcess: number;
qaMaxProcess: number;
pgHNSWEfSearch: number;
oneapiUrl?: string;
chatApiKey?: string;
};

// declare global {
Expand Down
1 change: 1 addition & 0 deletions packages/global/support/wallet/bill/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export type BillSchemaType = {
datasetSize?: number;
extraPoints?: number;
};
username: string;
};

export type ChatModuleUsageType = {
Expand Down
4 changes: 2 additions & 2 deletions packages/service/core/ai/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type { UserModelSchema } from '@fastgpt/global/support/user/type';
import OpenAI from '@fastgpt/global/core/ai';

export const openaiBaseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
export const baseUrl = process.env.ONEAPI_URL || openaiBaseUrl;
export const baseUrl = global?.systemEnv?.oneapiUrl || process.env.ONEAPI_URL || openaiBaseUrl;

export const systemAIChatKey = process.env.CHAT_API_KEY || '';
export const systemAIChatKey = global?.systemEnv?.chatApiKey || process.env.CHAT_API_KEY || '';

export const getAIApi = (props?: {
userKey?: UserModelSchema['openaiAccount'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React, { useState, useMemo, useRef } from 'react';
import { Box, Card, Flex, useTheme, useOutsideClick, Button } from '@chakra-ui/react';
import { addDays, format } from 'date-fns';
import { type DateRange, DayPicker } from 'react-day-picker';
import MyIcon from '@fastgpt/web/components/common/Icon';
import 'react-day-picker/dist/style.css';
import zhCN from 'date-fns/locale/zh-CN';
import { useTranslation } from 'next-i18next';
import MyIcon from '../Icon';

const DateRangePicker = ({
onChange,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useCallback } from 'react';
import LoadingComponent from '@/components/Loading';
import LoadingComponent from '../components/common/MyLoading';

export const useLoading = (props?: { defaultLoading: boolean }) => {
const [isLoading, setIsLoading] = useState(props?.defaultLoading || false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,47 @@
import { useRef, useState, useCallback, useMemo, useEffect } from 'react';
import type { PagingData } from '@/types/index.d';
import { IconButton, Flex, Box, Input } from '@chakra-ui/react';
import { ArrowBackIcon, ArrowForwardIcon } from '@chakra-ui/icons';
import { useMutation } from '@tanstack/react-query';
import { useToast } from '@fastgpt/web/hooks/useToast';

import { throttle } from 'lodash';
import { useToast } from './useToast';

const thresholdVal = 100;

type PagingData<T> = {
pageNum: number;
pageSize: number;
data: T[];
total?: number;
};

export function usePagination<T = any>({
api,
pageSize = 10,
params = {},
defaultRequest = true,
type = 'button',
onChange
onChange,
elementRef
}: {
api: (data: any) => any;
pageSize?: number;
params?: Record<string, any>;
defaultRequest?: boolean;
type?: 'button' | 'scroll';
onChange?: (pageNum: number) => void;
elementRef?: React.RefObject<HTMLDivElement>;
}) {
const elementRef = useRef<HTMLDivElement>(null);
const { toast } = useToast();
const [pageNum, setPageNum] = useState(1);
const pageNumRef = useRef(pageNum);
pageNumRef.current = pageNum;
const [total, setTotal] = useState(0);
const totalRef = useRef(total);
totalRef.current = total;
const [data, setData] = useState<T[]>([]);
const dataLengthRef = useRef(data.length);
dataLengthRef.current = data.length;
const maxPage = useMemo(() => Math.ceil(total / pageSize) || 1, [pageSize, total]);

const { mutate, isLoading } = useMutation({
Expand All @@ -40,7 +54,11 @@ export function usePagination<T = any>({
});
setPageNum(num);
res.total !== undefined && setTotal(res.total);
setData(res.data);
if (type === 'scroll') {
setData((prevData) => [...prevData, ...res.data]);
} else {
setData(res.data);
}
onChange && onChange(num);
} catch (error: any) {
toast({
Expand Down Expand Up @@ -147,7 +165,7 @@ export function usePagination<T = any>({
);

useEffect(() => {
if (!elementRef.current || type !== 'scroll') return;
if (!elementRef?.current || type !== 'scroll') return;

const scrolling = throttle((e: Event) => {
const element = e.target as HTMLDivElement;
Expand All @@ -159,16 +177,23 @@ export function usePagination<T = any>({
// 内容总高度
const scrollHeight = element.scrollHeight;
// 判断是否滚动到底部
if (scrollTop + clientHeight + thresholdVal >= scrollHeight) {
mutate(pageNum + 1);
if (
scrollTop + clientHeight + thresholdVal >= scrollHeight &&
dataLengthRef.current < totalRef.current
) {
mutate(pageNumRef.current + 1);
}
}, 100);
elementRef.current.addEventListener('scroll', scrolling);

const handleScroll = (e: Event) => {
scrolling(e);
};

elementRef.current.addEventListener('scroll', handleScroll);
return () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
elementRef.current?.removeEventListener('scroll', scrolling);
elementRef.current?.removeEventListener('scroll', handleScroll);
};
}, [elementRef, mutate, pageNum, type]);
}, [elementRef, mutate, pageNum, type, total, data.length]);

useEffect(() => {
defaultRequest && mutate(1);
Expand All @@ -179,6 +204,7 @@ export function usePagination<T = any>({
pageSize,
total,
data,
setData,
isLoading,
Pagination,
ScrollData,
Expand Down
8 changes: 7 additions & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@
"@lexical/react": "0.12.6",
"papaparse": "^5.4.1",
"@lexical/utils": "0.12.6",
"@lexical/text": "0.12.6"
"@lexical/text": "0.12.6",
"date-fns": "2.30.0",
"react-day-picker": "^8.7.1",
"lodash": "^4.17.21",
"@tanstack/react-query": "^4.24.10",
"dayjs": "^1.11.7"
},
"devDependencies": {
"@types/lodash": "^4.14.191",
"@types/react": "18.2.0",
"@types/papaparse": "^5.3.7",
"@types/react-dom": "18.2.0",
Expand Down
Loading

0 comments on commit 4d66e0f

Please sign in to comment.