perf: md引入;docker-compose;

This commit is contained in:
archer
2023-04-09 22:56:08 +08:00
parent 5e4c4dd79b
commit 99e5fbd0f5
17 changed files with 185 additions and 149 deletions

161
README.md
View File

@@ -31,7 +31,6 @@ docker push imageName:tag
# 或者直接拉镜像,见下方
```
#### 软件教程docker 安装
```bash
# 安装docker
@@ -39,20 +38,6 @@ curl -sSL https://get.daocloud.io/docker | sh
sudo systemctl start docker
```
#### 软件教程mongo 安装
```bash
docker pull mongo:6.0.4
docker stop mongo
docker rm mongo
docker run -d --name mongo \
-e MONGO_INITDB_ROOT_USERNAME= \
-e MONGO_INITDB_ROOT_PASSWORD= \
-v /root/service/mongo:/data/db \
mongo:6.0.4
# 检查 mongo 运行情况, 有成功的 logs 代表访问成功
docker logs mongo
```
#### 软件教程: clash 代理
```bash
# 下载包
@@ -70,8 +55,7 @@ export https_proxy=http://127.0.0.1:7890
export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
# 运行脚本: 删除clash - 到 clash 目录 - 删除缓存 - 执行运行
# 会生成一个 nohup.out 文件,可以看到 clash 的 logs
# 运行脚本: 删除clash - 到 clash 目录 - 删除缓存 - 执行运行. 会生成一个 nohup.out 文件,可以看到 clash 的 logs
OLD_PROCESS=$(pgrep clash)
if [ ! -z "$OLD_PROCESS" ]; then
echo "Killing old process: $OLD_PROCESS"
@@ -85,44 +69,9 @@ nohup ./clash-linux-amd64-v1.10.0 -d ./ &
echo "Restart clash"
```
#### 软件教程Nginx
...没写,这个百度吧。
#### redis-stack
安装
```bash
#!/bin/bash
docker pull redis/redis-stack:6.2.6-v6
docker stop fast-gpt-redis-stack
docker rm fast-gpt-redis-stack
docker run -d --name fast-gpt-redis-stack \
-v /redis/data:/data \
-v /etc/localtime:/etc/localtime:ro \
-v /redis.conf:/redis-stack.conf \
-e REDIS_ARGS="--requirepass 1111111"\
-p 8102:6379 \
-p 8103:8001 \
--restart unless-stopped \
redis/redis-stack:6.2.6-v6
```
```bash
# /redis.conf
# 开启aop持久化
appendonly yes
#default: 持久化文件
appendfilename "appendonly.aof"
#default: 每秒同步一次
appendfsync everysec
```
```bash
# 添加索引
FT.CREATE idx:model:data:hash ON HASH PREFIX 1 model:data: SCHEMA modelId TAG userId TAG status TAG q TEXT text TEXT vector VECTOR FLAT 6 DIM 1536 DISTANCE_METRIC COSINE TYPE FLOAT32
```
#### 服务器拉取镜像和运行
#### 文件创建
**yml文件**
```yml
# docker-compose
version: "3.3"
services:
fast-gpt:
@@ -130,20 +79,108 @@ services:
environment:
AXIOS_PROXY_HOST: 127.0.0.1
AXIOS_PROXY_PORT: 7890
MY_MAIL:
MAILE_CODE:
TOKEN_KEY:
MONGODB_URI:
OPENAIKEY:
REDIS_URL:
MY_MAIL: 11111111@qq.com
MAILE_CODE: sdasadasfasfad
TOKEN_KEY: sssssssss
MONGODB_URI: mongodb://username:password@0.0.0.0:27017/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false
OPENAIKEY: sk-afadfadfadfsd
REDIS_URL: redis://default:password@0.0.0.0:8100
network_mode: host
restart: always
container_name: fast-gpt
mongodb:
image: mongo:6.0.4
container_name: mongo
restart: always
environment:
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=ROOT_1234
- MONGO_DATA_DIR=/data/db
- MONGO_LOG_DIR=/data/logs
volumes:
- /root/fastgpt/mongo/data:/data/db
- /root/fastgpt/mongo/logs:/data/logs
ports:
- 27017:27017
nginx:
image: nginx:alpine3.17
container_name: nginx
restart: always
network_mode: host
ports:
- "80:80"
volumes:
- /root/fastgpt/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
redis-stack:
image: redis/redis-stack:6.2.6-v6
container_name: redis-stack
restart: unless-stopped
ports:
- "8100:6379"
- "8101:8001"
environment:
- REDIS_ARGS=--requirepass psw1234
volumes:
- /etc/localtime:/etc/localtime:ro
- /root/fastgpt/redis/redis.conf:/redis.conf
- /root/fastgpt/redis/data:/data
```
**redis.conf**
```
## 开启aop持久化
appendonly yes
#default: 持久化文件
appendfilename "appendonly.aof"
#default: 每秒同步一次
appendfsync everysec
```
**nginx.conf**
```
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name test.com;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_vary on;
gzip_types text/plain application/x-javascript text/css application/javascript application/json application/xml;
gzip_disable "MSIE [1-6]\.";
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
```
#### 运行脚本
**redis创建索引**
```bash
FT.CREATE idx:model:data:hash ON HASH PREFIX 1 model:data: SCHEMA modelId TAG userId TAG status TAG q TEXT text TEXT vector VECTOR FLAT 6 DIM 1536 DISTANCE_METRIC COSINE TYPE FLOAT32
```
**run.sh 运行文件**
```bash
#!/bin/bash
# 拉取最新镜像
docker-compose pull
docker-compose up -d
echo "Docker Compose 重新拉取镜像完成!"

View File

@@ -0,0 +1,9 @@
## 常见问题
**内容长度**
单次最长 4000 tokens, 上下文最长 8000 tokens, 上下文超长时会被截断。
**删除和复制**
点击对话头像,可以选择复制或删除该条内容。
**代理出错**
服务器代理不稳定,可以过一会儿再尝试。

40
public/docs/intro.md Normal file
View File

@@ -0,0 +1,40 @@
## 欢迎使用 Fast GPT
[Git 仓库](https://github.com/c121914yu/FastGPT)
### 交流群/问题反馈
扫码满了,加个小号,定时拉
wx号: fastgpt123
![](/imgs/wx300.jpg)
### 快速开始
1. 使用邮箱注册账号。
2. 进入账号页面,添加关联账号,目前只有 openai 的账号可以添加,直接去 openai 官网,把 API Key 粘贴过来。
3. 如果填写了自己的 openai 账号,使用时会直接用你的账号。如果没有填写,需要付费使用平台的账号。
4. 进入模型页,创建一个模型,建议直接用 ChatGPT。
5. 在模型列表点击【对话】,即可使用 API 进行聊天。
### 定制 prompt
1. 进入模型编辑页
2. 调整温度和提示词
3. 使用该模型对话。每次对话时,提示词和温度都会自动注入,方便管理个人的模型。建议把自己日常经常需要使用的 5~10 个方向预设好。
### 知识库
1. 创建模型时选择【知识库】
2. 进入模型编辑页
3. 导入数据,可以选择手动导入,或者选择文件导入。文件导入会自动调用 chatGPT 理解文件内容,并生成知识库。
4. 使用该模型对话。
注意使用知识库模型对话时tokens 消耗会加快。
### 价格表
如果使用了自己的 Api Key不会计费。可以在账号页看到详细账单。单纯使用 chatGPT 模型进行对话,只有一个计费项目。使用知识库时,包含**对话**和**索引**生成两个计费项。
| 计费项 | 价格: 元/ 1K tokens包含上下文|
| --- | --- |
| chatgpt - 对话 | 0.03 |
| 知识库 - 对话 | 0.03 |
| 知识库 - 索引 | 0.004 |
| 文件拆分 | 0.03 |

3
public/docs/shareHint.md Normal file
View File

@@ -0,0 +1,3 @@
你正准备分享对话,请确保分享链接不会滥用,因为它是使用的是你的 API key。
* 分享空白对话:为该模型创建一个空白的聊天分享出去。
* 分享当前对话:会把当前聊天的内容也分享出去,但是要注意不要多个人同时用一个聊天内容。

View File

@@ -0,0 +1,3 @@
## Fast GPT V2.5
* 内容压缩替换中文标点符号和多余符号减少一些上下文tokens。
* 优化 QA 拆分记账。

BIN
public/imgs/wx300.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

1
src/api/common.ts Normal file
View File

@@ -0,0 +1 @@
import { GET, POST, DELETE } from './request';

View File

@@ -23,7 +23,7 @@ const WxConcat = ({ onClose }: { onClose: () => void }) => {
<ModalBody textAlign={'center'}>
<Image
style={{ margin: 'auto' }}
src={'/imgs/wxerweima300.jpg'}
src={'/imgs/wx300.jpg'}
width={200}
height={200}
alt=""
@@ -31,7 +31,7 @@ const WxConcat = ({ onClose }: { onClose: () => void }) => {
<Box mt={2}>
:
<Box as={'span'} userSelect={'all'}>
YNyiqi
fastgpt123
</Box>
</Box>
</ModalBody>

View File

@@ -4,69 +4,3 @@ export enum EmailTypeEnum {
}
export const PRICE_SCALE = 100000;
export const introPage = `
## 欢迎使用 Fast GPT
[Git 仓库](https://github.com/c121914yu/FastGPT)
### 交流群/问题反馈
wx号: YNyiqi
![](/imgs/wxerweima300.jpg)
### 快速开始
1. 使用邮箱注册账号。
2. 进入账号页面,添加关联账号,目前只有 openai 的账号可以添加,直接去 openai 官网,把 API Key 粘贴过来。
3. 如果填写了自己的 openai 账号,使用时会直接用你的账号。如果没有填写,需要付费使用平台的账号。
4. 进入模型页,创建一个模型,建议直接用 ChatGPT。
5. 在模型列表点击【对话】,即可使用 API 进行聊天。
### 定制 prompt
1. 进入模型编辑页
2. 调整温度和提示词
3. 使用该模型对话。每次对话时,提示词和温度都会自动注入,方便管理个人的模型。建议把自己日常经常需要使用的 5~10 个方向预设好。
### 知识库
1. 创建模型时选择【知识库】
2. 进入模型编辑页
3. 导入数据,可以选择手动导入,或者选择文件导入。文件导入会自动调用 chatGPT 理解文件内容,并生成知识库。
4. 使用该模型对话。
注意使用知识库模型对话时tokens 消耗会加快。
### 价格表
如果使用了自己的 Api Key不会计费。可以在账号页看到详细账单。单纯使用 chatGPT 模型进行对话,只有一个计费项目。使用知识库时,包含**对话**和**索引**生成两个计费项。
| 计费项 | 价格: 元/ 1K tokens包含上下文|
| --- | --- |
| chatgpt - 对话 | 0.03 |
| 知识库 - 对话 | 0.03 |
| 知识库 - 索引 | 0.004 |
| 文件拆分 | 0.03 |
`;
export const chatProblem = `
## 常见问题
**内容长度**
单次最长 4000 tokens, 上下文最长 8000 tokens, 上下文超长时会被截断。
**删除和复制**
点击对话头像,可以选择复制或删除该条内容。
**代理出错**
服务器代理不稳定,可以过一会儿再尝试。
`;
export const versionIntro = `
## Fast GPT V2.5
* 内容压缩替换中文标点符号和多余符号减少一些上下文tokens。
* 优化 QA 拆分记账。
`;
export const shareHint = `
你正准备分享对话,请确保分享链接不会滥用,因为它是使用的是你的 API key。
* 分享空白对话:为该模型创建一个空白的聊天分享出去。
* 分享当前对话:会把当前聊天的内容也分享出去,但是要注意不要多个人同时用一个聊天内容。
`;

15
src/hooks/useMarkdown.ts Normal file
View File

@@ -0,0 +1,15 @@
import { useQuery } from '@tanstack/react-query';
export const getMd = async (url: string) => {
const response = await fetch(`/docs/${url}`);
const textContent = await response.text();
return textContent;
};
export const useMarkdown = ({ url }: { url: string }) => {
const { data = '' } = useQuery([url], () => getMd(url));
return {
data
};
};

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { Card, Box, Mark } from '@chakra-ui/react';
import { versionIntro, chatProblem } from '@/constants/common';
import { Card, Box } from '@chakra-ui/react';
import { useMarkdown } from '@/hooks/useMarkdown';
import Markdown from '@/components/Markdown';
const Empty = ({ intro }: { intro: string }) => {
@@ -9,6 +9,9 @@ const Empty = ({ intro }: { intro: string }) => {
{children}
</Box>
);
const { data: chatProblem } = useMarkdown({ url: '/chatProblem.md' });
const { data: versionIntro } = useMarkdown({ url: '/versionIntro.md' });
return (
<Box
minH={'100%'}

View File

@@ -30,9 +30,9 @@ import { getToken } from '@/utils/user';
import MyIcon from '@/components/Icon';
import { useCopyData } from '@/utils/tools';
import Markdown from '@/components/Markdown';
import { shareHint } from '@/constants/common';
import { getChatSiteId } from '@/api/chat';
import WxConcat from '@/components/WxConcat';
import { useMarkdown } from '@/hooks/useMarkdown';
const SlideBar = ({
name,
@@ -55,6 +55,7 @@ const SlideBar = ({
const [hasReady, setHasReady] = useState(false);
const { isOpen: isOpenShare, onOpen: onOpenShare, onClose: onCloseShare } = useDisclosure();
const { isOpen: isOpenWx, onOpen: onOpenWx, onClose: onCloseWx } = useDisclosure();
const { data: shareHint } = useMarkdown({ url: '/chatProblem.md' });
const { isSuccess } = useQuery(['init'], getMyModels, {
cacheTime: 5 * 60 * 1000

View File

@@ -1,12 +1,14 @@
import React from 'react';
import { Card } from '@chakra-ui/react';
import Markdown from '@/components/Markdown';
import { introPage } from '@/constants/common';
import { useMarkdown } from '@/hooks/useMarkdown';
const Home = () => {
const { data } = useMarkdown({ url: '/intro.md' });
return (
<Card p={5} lineHeight={2}>
<Markdown source={introPage} isChatting={false} />
<Markdown source={data} isChatting={false} />
</Card>
);
};

View File

@@ -49,10 +49,6 @@ const ModelPhoneList = ({
<Box flex={'0 0 100px'}>AI模型: </Box>
<Box color={'blackAlpha.500'}>{model.service.modelName}</Box>
</Flex>
<Flex mt={5}>
<Box flex={'0 0 100px'}>: </Box>
<Box color={'blackAlpha.500'}>{model.trainingTimes}</Box>
</Flex>
<Flex mt={5} justifyContent={'flex-end'}>
<Button
mr={3}

View File

@@ -60,11 +60,6 @@ const ModelTable = ({
</Box>
)
},
{
title: '训练次数',
key: 'trainingTimes',
dataIndex: 'trainingTimes'
},
{
title: '操作',
key: 'control',

View File

@@ -25,11 +25,8 @@ export const jsonRes = <T = any>(
msg = error;
} else if (proxyError[error?.code]) {
msg = '服务器代理出错';
} else if (error?.response?.data?.error) {
msg =
openaiError2[error?.response?.data?.error?.type] ||
error?.response?.data?.error?.message ||
'openai 错误';
} else if (openaiError2[error?.response?.data?.error?.type]) {
msg = openaiError2[error?.response?.data?.error?.type];
} else if (openaiError[error?.response?.statusText]) {
msg = openaiError[error.response.statusText];
}