Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
2d74fa8e
authored
May 04, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: auth error.perf: prompt,process img
parent
c8799053
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
33 deletions
+57
-33
README.md
+45
-28
docs/imgs/KBProcess.jpg
+0
-0
src/pages/model/detail/components/ModelEditForm.tsx
+9
-2
src/service/utils/auth.ts
+1
-1
src/service/utils/chat/claude.ts
+2
-2
No files found.
README.md
View file @
2d74fa8e
# Fast GPT
# Fast GPT
Fast GPT 允许你使用自己的 openai API KEY 来快速的调用 openai 接口,目前集成了 gpt35 和 embedding. 可构建自己的知识库。
Fast GPT 允许你使用自己的 openai API KEY 来快速的调用 openai 接口,目前集成了 gpt35 和 embedding. 可构建自己的知识库。
## 知识库原理
## 知识库原理


## 开发
## 开发
**配置环境变量**
**配置环境变量**
```
bash
```
bash
# proxy(可选)
# proxy(可选)
AXIOS_PROXY_HOST
=
127.0.0.1
AXIOS_PROXY_HOST
=
127.0.0.1
...
@@ -32,15 +35,17 @@ OPENAIKEY=sk-xxx
...
@@ -32,15 +35,17 @@ OPENAIKEY=sk-xxx
# mongo连接地址
# mongo连接地址
MONGODB_URI
=
mongodb://username:password@0.0.0.0:27017/test?authSource
=
admin
MONGODB_URI
=
mongodb://username:password@0.0.0.0:27017/test?authSource
=
admin
# mongo数据库名称
# mongo数据库名称
MONGODB_NAME
=
xxx
MONGODB_NAME
=
xxx
# pg 数据库相关内容,和 docker-compose 对上
# pg 数据库相关内容,和 docker-compose
pg 部分
对上
PG_HOST
=
0.0.0.0
PG_HOST
=
0.0.0.0
PG_PORT
=
8102
PG_PORT
=
8102
PG_USER
=
xxx
PG_USER
=
fastgpt
PG_PASSWORD
=
xxx
PG_PASSWORD
=
1234
PG_DB_NAME
=
xxx
PG_DB_NAME
=
fastgpt
```
```
**运行**
**运行**
```
```
pnpm dev
pnpm dev
```
```
...
@@ -48,13 +53,17 @@ pnpm dev
...
@@ -48,13 +53,17 @@ pnpm dev
## 部署
## 部署
### 代理环境(国外服务器可忽略)
### 代理环境(国外服务器可忽略)
1.
[
clash 方案
](
./docs/proxy/clash.md
)
- 仅需一台服务器(需要有 clash)
1.
[
clash 方案
](
./docs/proxy/clash.md
)
- 仅需一台服务器(需要有 clash)
2.
[
nginx 方案
](
./docs/proxy/nginx.md
)
- 需要一台国外服务器
2.
[
nginx 方案
](
./docs/proxy/nginx.md
)
- 需要一台国外服务器
3.
[
cloudflare 方案
](
./docs/proxy/cloudflare.md
)
- 需要有域名(每日免费 10w 次代理请求)
3.
[
cloudflare 方案
](
./docs/proxy/cloudflare.md
)
- 需要有域名(每日免费 10w 次代理请求)
### docker 部署
### docker 部署
#### 1. 安装 docker 和 docker-compose
#### 1. 安装 docker 和 docker-compose
这个不同系统略有区别,百度安装下。验证安装成功后进行下一步。下面给出一个例子:
这个不同系统略有区别,百度安装下。验证安装成功后进行下一步。下面给出一个例子:
```
bash
```
bash
# 安装docker
# 安装docker
curl
-L
https://get.daocloud.io/docker | sh
curl
-L
https://get.daocloud.io/docker | sh
...
@@ -67,11 +76,12 @@ docker -v
...
@@ -67,11 +76,12 @@ docker -v
docker-compose
-v
docker-compose
-v
```
```
#### 2. 创建 3 个初始化文件
#### 2. 创建3个初始化文件
手动创建或者直接把 deploy 里内容复制过去
手动创建或者直接把 deploy 里内容复制过去
**/root/fast-gpt/pg/init.sql**
**/root/fast-gpt/pg/init.sql**
```
sql
```
sql
set
-
e
set
-
e
psql
-
v
ON_ERROR_STOP
=
1
--username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
psql
-
v
ON_ERROR_STOP
=
1
--username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
...
@@ -95,6 +105,7 @@ EOSQL
...
@@ -95,6 +105,7 @@ EOSQL
```
```
**/root/fast-gpt/nginx/nginx.conf**
**/root/fast-gpt/nginx/nginx.conf**
```
conf
```
conf
user
nginx
;
user
nginx
;
worker_processes
auto
;
worker_processes
auto
;
...
@@ -110,7 +121,7 @@ http {
...
@@ -110,7 +121,7 @@ http {
client_header_buffer_size
32
k
;
client_header_buffer_size
32
k
;
large_client_header_buffers
4
32
k
;
large_client_header_buffers
4
32
k
;
client_max_body_size
50
M
;
client_max_body_size
50
M
;
gzip
on
;
gzip
on
;
gzip_min_length
1
k
;
gzip_min_length
1
k
;
gzip_buffers
4
8
k
;
gzip_buffers
4
8
k
;
...
@@ -136,7 +147,7 @@ http {
...
@@ -136,7 +147,7 @@ http {
proxy_pass
http
://
localhost
:
3000
;
proxy_pass
http
://
localhost
:
3000
;
proxy_set_header
Host
$
host
;
proxy_set_header
Host
$
host
;
proxy_set_header
X
-
Real
-
IP
$
remote_addr
;
proxy_set_header
X
-
Real
-
IP
$
remote_addr
;
proxy_set_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
proxy_set_header
X
-
Forwarded
-
For
$
proxy_add_x_forwarded_for
;
}
}
}
}
server
{
server
{
...
@@ -148,8 +159,9 @@ http {
...
@@ -148,8 +159,9 @@ http {
```
```
**/root/fast-gpt/docker-compose.yml**
**/root/fast-gpt/docker-compose.yml**
```
yml
```
yml
version
:
"
3.3"
version
:
'
3.3'
services
:
services
:
fast-gpt
:
fast-gpt
:
image
:
c121914yu/fast-gpt:latest
image
:
c121914yu/fast-gpt:latest
...
@@ -161,24 +173,24 @@ services:
...
@@ -161,24 +173,24 @@ services:
# - AXIOS_PROXY_PORT=7890
# - AXIOS_PROXY_PORT=7890
# - OPENAI_BASE_URL=https://api.openai.com/v1
# - OPENAI_BASE_URL=https://api.openai.com/v1
# - OPENAI_BASE_URL_AUTH=可选的安全凭证
# - OPENAI_BASE_URL_AUTH=可选的安全凭证
-
MY_MAIL=xxxx@qq.com
-
MY_MAIL=xxxx@qq.com
-
MAILE_CODE=xxxx
-
MAILE_CODE=xxxx
-
aliAccessKeyId=xxxx
-
aliAccessKeyId=xxxx
-
aliAccessKeySecret=xxxx
-
aliAccessKeySecret=xxxx
-
aliSignName=xxxxx
-
aliSignName=xxxxx
-
aliTemplateCode=SMS_xxxx
-
aliTemplateCode=SMS_xxxx
-
TOKEN_KEY=xxxx
-
TOKEN_KEY=xxxx
-
queueTask=1
-
queueTask=1
-
parentUrl=https://hostname/api/openapi/startEvents
-
parentUrl=https://hostname/api/openapi/startEvents
-
MONGODB_URI=mongodb://username:passsword@0.0.0.0:27017/?authSource=admin
-
MONGODB_URI=mongodb://username:passsword@0.0.0.0:27017/?authSource=admin
-
MONGODB_NAME=xxx
-
MONGODB_NAME=xxx
-
PG_HOST=0.0.0.0
-
PG_HOST=0.0.0.0
-
PG_PORT=8100
-
PG_PORT=8100
-
PG_USER=
xxx
-
PG_USER=
fastgpt
-
PG_PASSWORD=
xxx
-
PG_PASSWORD=
1234
-
PG_DB_NAME=
xxx
-
PG_DB_NAME=
fastgpt
-
OPENAIKEY=sk-xxxxx
-
OPENAIKEY=sk-xxxxx
nginx
:
nginx
:
image
:
nginx:alpine3.17
image
:
nginx:alpine3.17
container_name
:
nginx
container_name
:
nginx
restart
:
always
restart
:
always
...
@@ -195,9 +207,9 @@ services:
...
@@ -195,9 +207,9 @@ services:
ports
:
ports
:
-
8100:5432
-
8100:5432
environment
:
environment
:
-
POSTGRES_USER=
xxx
-
POSTGRES_USER=
fastgpt
-
POSTGRES_PASSWORD=
xxx
-
POSTGRES_PASSWORD=
1234
-
POSTGRES_DB=
xxx
-
POSTGRES_DB=
fastgpt
volumes
:
volumes
:
-
/root/fast-gpt/pg/data:/var/lib/postgresql/data
-
/root/fast-gpt/pg/data:/var/lib/postgresql/data
-
/root/fast-gpt/pg/init.sql:/docker-entrypoint-initdb.d/init.sh
-
/root/fast-gpt/pg/init.sql:/docker-entrypoint-initdb.d/init.sh
...
@@ -218,8 +230,10 @@ services:
...
@@ -218,8 +230,10 @@ services:
```
```
#### 3. 运行 docker-compose
#### 3. 运行 docker-compose
下面是一个辅助脚本,也可以直接 docker-compose up -d
下面是一个辅助脚本,也可以直接 docker-compose up -d
**run.sh 运行文件**
**run.sh 运行文件**
```
bash
```
bash
#!/bin/bash
#!/bin/bash
docker-compose pull
docker-compose pull
...
@@ -242,15 +256,18 @@ do
...
@@ -242,15 +256,18 @@ do
done
done
```
```
## 其他优化点
## 其他优化点
### Git Action 自动打包镜像
### Git Action 自动打包镜像
.github里拥有一个 git 提交到 main 分支时自动打包 amd64 和 arm64 镜像的 actions。你仅需要提前在 git 配置好 session。
1.
创建账号 session: 头像 -> settings -> 最底部 Developer settings -> Personal access tokens -> tokens(classic) -> 创建新 session,把一些看起来需要的权限勾上。
.github 里拥有一个 git 提交到 main 分支时自动打包 amd64 和 arm64 镜像的 actions。你仅需要提前在 git 配置好 session。
2.
添加 session 到仓库: 仓库 -> settings -> Secrets and variables -> Actions -> 创建secret
3.
填写 secret: Name-GH_PAT, Secret-第一步的tokens
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 可能的问题
### Mac 可能的问题
> 因为教程有部分镜像不兼容arm64,所以写个文档指导新手如何快速在mac上面搭建fast-gpt[如何在mac上面部署fastgpt](./docs/mac.md)
> 因为教程有部分镜像不兼容 arm64,所以写个文档指导新手如何快速在 mac 上面搭建 fast-gpt[如何在 mac 上面部署 fastgpt](./docs/mac.md)
docs/imgs/KBProcess.jpg
View file @
2d74fa8e
69 KB
|
W:
|
H:
111 KB
|
W:
|
H:
2-up
Swipe
Onion skin
src/pages/model/detail/components/ModelEditForm.tsx
View file @
2d74fa8e
...
@@ -26,7 +26,7 @@ import { formatPrice } from '@/utils/user';
...
@@ -26,7 +26,7 @@ import { formatPrice } from '@/utils/user';
import
{
useConfirm
}
from
'@/hooks/useConfirm'
;
import
{
useConfirm
}
from
'@/hooks/useConfirm'
;
import
{
useSelectFile
}
from
'@/hooks/useSelectFile'
;
import
{
useSelectFile
}
from
'@/hooks/useSelectFile'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
fileToBase64
,
compressImg
}
from
'@/utils/file'
;
import
{
compressImg
}
from
'@/utils/file'
;
const
ModelEditForm
=
({
const
ModelEditForm
=
({
formHooks
,
formHooks
,
...
@@ -112,7 +112,14 @@ const ModelEditForm = ({
...
@@ -112,7 +112,14 @@ const ModelEditForm = ({
<
Box
flex=
{
'0 0 80px'
}
w=
{
0
}
>
<
Box
flex=
{
'0 0 80px'
}
w=
{
0
}
>
对话模型:
对话模型:
</
Box
>
</
Box
>
<
Select
isDisabled=
{
!
isOwner
}
{
...
register
('
chat
.
chatModel
')}
>
<
Select
isDisabled=
{
!
isOwner
}
{
...
register
('
chat
.
chatModel
',
{
onChange
()
{
setRefresh
((
state
)
=
>
!state);
}
})}
>
{
chatModelList
.
map
((
item
)
=>
(
{
chatModelList
.
map
((
item
)
=>
(
<
option
key=
{
item
.
chatModel
}
value=
{
item
.
chatModel
}
>
<
option
key=
{
item
.
chatModel
}
value=
{
item
.
chatModel
}
>
{
item
.
name
}
{
item
.
name
}
...
...
src/service/utils/auth.ts
View file @
2d74fa8e
...
@@ -73,7 +73,7 @@ export const getApiKey = async ({
...
@@ -73,7 +73,7 @@ export const getApiKey = async ({
// 平台账号余额校验
// 平台账号余额校验
if
(
formatPrice
(
user
.
balance
)
<=
0
)
{
if
(
formatPrice
(
user
.
balance
)
<=
0
)
{
return
Promise
.
reject
(
ERROR_ENUM
.
unAuthorization
);
return
Promise
.
reject
(
ERROR_ENUM
.
insufficientQuota
);
}
}
return
{
return
{
...
...
src/service/utils/chat/claude.ts
View file @
2d74fa8e
...
@@ -25,9 +25,9 @@ export const lafClaudChat = async ({
...
@@ -25,9 +25,9 @@ export const lafClaudChat = async ({
.
filter
((
item
)
=>
item
.
obj
===
'System'
)
.
filter
((
item
)
=>
item
.
obj
===
'System'
)
.
map
((
item
)
=>
item
.
value
)
.
map
((
item
)
=>
item
.
value
)
.
join
(
'\n'
);
.
join
(
'\n'
);
const
systemPromptText
=
systemPrompt
?
`\n知识库内容:'
${
systemPrompt
}
'\n
我的问题:
`
:
''
;
const
systemPromptText
=
systemPrompt
?
`\n知识库内容:'
${
systemPrompt
}
'\n`
:
''
;
const
prompt
=
systemPromptText
+
messages
[
messages
.
length
-
1
].
value
;
const
prompt
=
`
${
systemPromptText
}
我的问题:'
${
messages
[
messages
.
length
-
1
].
value
}
'`
;
const
lafResponse
=
await
axios
.
post
(
const
lafResponse
=
await
axios
.
post
(
'https://hnvacz.laf.run/claude-gpt'
,
'https://hnvacz.laf.run/claude-gpt'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment