部署 Chatgpt_web

系统:Ubuntu20.04

拉取源码:
1
git clone https://github.com/Chanzhaoyu/chatgpt-web.git
安装 node / pnpm
1
2
3
4
5
6
7
8
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs

# 验证
node -v

# 安装 pnpm
npm install pnpm -g
安装依赖
1
2
3
4
5
# 进入文件夹 /service 运行以下命令
pnpm install

# 根目录下运行以下命令
pnpm bootstrap
填写密钥
1
2
3
4
5
6
7
# service/.env 文件

# OpenAI API Key - https://platform.openai.com/overview
OPENAI_API_KEY=

# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
OPENAI_ACCESS_TOKEN=
使用 systemd 管理应用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
root@iZt4nbaxzkx16mx9901qpqZ:/etc/systemd/system# cat chatgpt.service 
[Unit]
Description=chatgpt

[Service]
Type=simple
WorkingDirectory=/root/chatgpt-web-main
ExecStart=pnpm dev
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target

1
2
3
4
5
6
7
8
9
10
11
12
13
root@iZt4nbaxzkx16mx9901qpqZ:/etc/systemd/system# cat chatgpt_api.service 
[Unit]
Description=chatgpt_api

[Service]
Type=simple
WorkingDirectory=/root/chatgpt-web-main/service
ExecStart=pnpm start
Restart=always
RestartSec=3

[Install]
WantedBy=multi-user.target
启动应用
1
2
3
4
5
6
7
8
9
10
# 加载配置
systemctl daemon-reload

# 启动应用
systemctl start chatgpt_api.service
systemctl start chatgpt.service

# 设置开机自启
systemctl enable chatgpt_api.service
systemctl enable chatgpt.service