mirror of
https://github.com/QYG2297248353/appstore-1panel.git
synced 2024-11-10 21:16:55 +08:00
refactor: chatgpt-web 部分内容优化
This commit is contained in:
parent
bcf99e2e64
commit
056e7aaa50
@ -4,38 +4,6 @@
|
||||
|
||||
更多功能:[chatgpt-web-plus](https://github.com/Chanzhaoyu/chatgpt-web-plus)
|
||||
|
||||
![cover](https://github.com/Chanzhaoyu/chatgpt-web/raw/main/docs/c1.png)
|
||||
![cover2](https://github.com/Chanzhaoyu/chatgpt-web/raw/main/docs/c2.png)
|
||||
|
||||
- [ChatGPT Web](#chatgpt-web)
|
||||
- [介绍](#介绍)
|
||||
- [待实现路线](#待实现路线)
|
||||
- [前置要求](#前置要求)
|
||||
- [Node](#node)
|
||||
- [PNPM](#pnpm)
|
||||
- [填写密钥](#填写密钥)
|
||||
- [安装依赖](#安装依赖)
|
||||
- [后端](#后端)
|
||||
- [前端](#前端)
|
||||
- [测试环境运行](#测试环境运行)
|
||||
- [后端服务](#后端服务)
|
||||
- [前端网页](#前端网页)
|
||||
- [环境变量](#环境变量)
|
||||
- [打包](#打包)
|
||||
- [使用 Docker](#使用-docker)
|
||||
- [Docker 参数示例](#docker-参数示例)
|
||||
- [Docker build \& Run](#docker-build--run)
|
||||
- [Docker compose](#docker-compose)
|
||||
- [防止爬虫抓取](#防止爬虫抓取)
|
||||
- [使用 Railway 部署](#使用-railway-部署)
|
||||
- [Railway 环境变量](#railway-环境变量)
|
||||
- [手动打包](#手动打包)
|
||||
- [后端服务](#后端服务-1)
|
||||
- [前端网页](#前端网页-1)
|
||||
- [常见问题](#常见问题)
|
||||
- [参与贡献](#参与贡献)
|
||||
- [赞助](#赞助)
|
||||
- [License](#license)
|
||||
## 介绍
|
||||
|
||||
支持双模型,提供了两种非官方 `ChatGPT API` 方法
|
||||
@ -62,294 +30,5 @@
|
||||
3. 使用 `Web API` 请填写 `OPENAI_ACCESS_TOKEN` 字段 [(获取 accessToken)](https://chat.openai.com/api/auth/session)
|
||||
4. 同时存在时以 `OpenAI API Key` 优先
|
||||
|
||||
环境变量:
|
||||
|
||||
全部参数变量请查看或[这里](#环境变量)
|
||||
|
||||
```
|
||||
/service/.env.example
|
||||
```
|
||||
|
||||
## 待实现路线
|
||||
[✓] 双模型
|
||||
|
||||
[✓] 多会话储存和上下文逻辑
|
||||
|
||||
[✓] 对代码等消息类型的格式化美化处理
|
||||
|
||||
[✓] 访问权限控制
|
||||
|
||||
[✓] 数据导入、导出
|
||||
|
||||
[✓] 保存消息到本地图片
|
||||
|
||||
[✓] 界面多语言
|
||||
|
||||
[✓] 界面主题
|
||||
|
||||
[✗] More...
|
||||
|
||||
## 前置要求
|
||||
|
||||
### Node
|
||||
|
||||
`node` 需要 `^16 || ^18 || ^19` 版本(`node >= 14` 需要安装 [fetch polyfill](https://github.com/developit/unfetch#usage-as-a-polyfill)),使用 [nvm](https://github.com/nvm-sh/nvm) 可管理本地多个 `node` 版本
|
||||
|
||||
```shell
|
||||
node -v
|
||||
```
|
||||
|
||||
### PNPM
|
||||
如果你没有安装过 `pnpm`
|
||||
```shell
|
||||
npm install pnpm -g
|
||||
```
|
||||
|
||||
### 填写密钥
|
||||
获取 `Openai Api Key` 或 `accessToken` 并填写本地环境变量 [跳转](#介绍)
|
||||
|
||||
```
|
||||
# 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=
|
||||
```
|
||||
|
||||
## 安装依赖
|
||||
|
||||
> 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。
|
||||
|
||||
### 后端
|
||||
|
||||
进入文件夹 `/service` 运行以下命令
|
||||
|
||||
```shell
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### 前端
|
||||
根目录下运行以下命令
|
||||
```shell
|
||||
pnpm bootstrap
|
||||
```
|
||||
|
||||
## 测试环境运行
|
||||
### 后端服务
|
||||
|
||||
进入文件夹 `/service` 运行以下命令
|
||||
|
||||
```shell
|
||||
pnpm start
|
||||
```
|
||||
|
||||
### 前端网页
|
||||
根目录下运行以下命令
|
||||
```shell
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
|
||||
`API` 可用:
|
||||
|
||||
- `OPENAI_API_KEY` 和 `OPENAI_ACCESS_TOKEN` 二选一
|
||||
- `OPENAI_API_MODEL` 设置模型,可选,默认:`gpt-3.5-turbo`
|
||||
- `OPENAI_API_BASE_URL` 设置接口地址,可选,默认:`https://api.openai.com`
|
||||
- `OPENAI_API_DISABLE_DEBUG` 设置接口关闭 debug 日志,可选,默认:empty 不关闭
|
||||
|
||||
`ACCESS_TOKEN` 可用:
|
||||
|
||||
- `OPENAI_ACCESS_TOKEN` 和 `OPENAI_API_KEY` 二选一,同时存在时,`OPENAI_API_KEY` 优先
|
||||
- `API_REVERSE_PROXY` 设置反向代理,可选,默认:`https://ai.fakeopen.com/api/conversation`,[社区](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)(注意:只有这两个是推荐,其他第三方来源,请自行甄别)
|
||||
|
||||
通用:
|
||||
|
||||
- `AUTH_SECRET_KEY` 访问权限密钥,可选
|
||||
- `MAX_REQUEST_PER_HOUR` 每小时最大请求次数,可选,默认无限
|
||||
- `TIMEOUT_MS` 超时,单位毫秒,可选
|
||||
- `SOCKS_PROXY_HOST` 和 `SOCKS_PROXY_PORT` 一起时生效,可选
|
||||
- `SOCKS_PROXY_PORT` 和 `SOCKS_PROXY_HOST` 一起时生效,可选
|
||||
- `HTTPS_PROXY` 支持 `http`,`https`, `socks5`,可选
|
||||
- `ALL_PROXY` 支持 `http`,`https`, `socks5`,可选
|
||||
|
||||
## 打包
|
||||
|
||||
### 使用 Docker
|
||||
|
||||
#### Docker 参数示例
|
||||
|
||||
![docker](https://github.com/Chanzhaoyu/chatgpt-web/raw/main/docs/docker.png)
|
||||
|
||||
#### Docker build & Run
|
||||
|
||||
```bash
|
||||
docker build -t chatgpt-web .
|
||||
|
||||
# 前台运行
|
||||
docker run --name chatgpt-web --rm -it -p 127.0.0.1:3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||
|
||||
# 后台运行
|
||||
docker run --name chatgpt-web -d -p 127.0.0.1:3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||
|
||||
# 运行地址
|
||||
http://localhost:3002/
|
||||
```
|
||||
|
||||
#### Docker compose
|
||||
|
||||
[Hub 地址](https://hub.docker.com/repository/docker/chenzhaoyu94/chatgpt-web/general)
|
||||
|
||||
```yml
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
app:
|
||||
image: chenzhaoyu94/chatgpt-web # 总是使用 latest ,更新时重新 pull 该 tag 镜像即可
|
||||
ports:
|
||||
- 127.0.0.1:3002:3002
|
||||
environment:
|
||||
# 二选一
|
||||
OPENAI_API_KEY: sk-xxx
|
||||
# 二选一
|
||||
OPENAI_ACCESS_TOKEN: xxx
|
||||
# API接口地址,可选,设置 OPENAI_API_KEY 时可用
|
||||
OPENAI_API_BASE_URL: xxx
|
||||
# API模型,可选,设置 OPENAI_API_KEY 时可用,https://platform.openai.com/docs/models
|
||||
# gpt-4, gpt-4-0314, gpt-4-0613, gpt-4-32k, gpt-4-32k-0314, gpt-4-32k-0613, gpt-3.5-turbo-16k, gpt-3.5-turbo-16k-0613, gpt-3.5-turbo, gpt-3.5-turbo-0301, gpt-3.5-turbo-0613, text-davinci-003, text-davinci-002, code-davinci-002
|
||||
OPENAI_API_MODEL: xxx
|
||||
# 反向代理,可选
|
||||
API_REVERSE_PROXY: xxx
|
||||
# 访问权限密钥,可选
|
||||
AUTH_SECRET_KEY: xxx
|
||||
# 每小时最大请求次数,可选,默认无限
|
||||
MAX_REQUEST_PER_HOUR: 0
|
||||
# 超时,单位毫秒,可选
|
||||
TIMEOUT_MS: 60000
|
||||
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||
SOCKS_PROXY_HOST: xxx
|
||||
# Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效
|
||||
SOCKS_PROXY_PORT: xxx
|
||||
# HTTPS 代理,可选,支持 http,https,socks5
|
||||
HTTPS_PROXY: http://xxx:7890
|
||||
```
|
||||
- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用
|
||||
- `OPENAI_API_MODEL` 可选,设置 `OPENAI_API_KEY` 时可用
|
||||
|
||||
#### 防止爬虫抓取
|
||||
|
||||
**nginx**
|
||||
|
||||
将下面配置填入nginx配置文件中,可以参考 `docker-compose/nginx/nginx.conf` 文件中添加反爬虫的方法
|
||||
|
||||
```
|
||||
# 防止爬虫抓取
|
||||
if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot")
|
||||
{
|
||||
return 403;
|
||||
}
|
||||
```
|
||||
|
||||
### 使用 Railway 部署
|
||||
|
||||
[![Deploy on Railway](https://railway.app/button.svg)](https://railway.app/new/template/yytmgc)
|
||||
|
||||
#### Railway 环境变量
|
||||
|
||||
| 环境变量名称 | 必填 | 备注 |
|
||||
| --------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- |
|
||||
| `PORT` | 必填 | 默认 `3002`
|
||||
| `AUTH_SECRET_KEY` | 可选 | 访问权限密钥 |
|
||||
| `MAX_REQUEST_PER_HOUR` | 可选 | 每小时最大请求次数,可选,默认无限 |
|
||||
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒 |
|
||||
| `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) |
|
||||
| `OPENAI_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) |
|
||||
| `OPENAI_API_BASE_URL` | 可选,`OpenAI API` 时可用 | `API`接口地址 |
|
||||
| `OPENAI_API_MODEL` | 可选,`OpenAI API` 时可用 | `API`模型 |
|
||||
| `API_REVERSE_PROXY` | 可选,`Web API` 时可用 | `Web API` 反向代理地址 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) |
|
||||
| `SOCKS_PROXY_HOST` | 可选,和 `SOCKS_PROXY_PORT` 一起时生效 | Socks代理 |
|
||||
| `SOCKS_PROXY_PORT` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理端口 |
|
||||
| `SOCKS_PROXY_USERNAME` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理用户名 |
|
||||
| `SOCKS_PROXY_PASSWORD` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理密码 |
|
||||
| `HTTPS_PROXY` | 可选 | HTTPS 代理,支持 http,https, socks5 |
|
||||
| `ALL_PROXY` | 可选 | 所有代理 代理,支持 http,https, socks5 |
|
||||
|
||||
> 注意: `Railway` 修改环境变量会重新 `Deploy`
|
||||
|
||||
### 手动打包
|
||||
#### 后端服务
|
||||
> 如果你不需要本项目的 `node` 接口,可以省略如下操作
|
||||
|
||||
复制 `service` 文件夹到你有 `node` 服务环境的服务器上。
|
||||
|
||||
```shell
|
||||
# 安装
|
||||
pnpm install
|
||||
|
||||
# 打包
|
||||
pnpm build
|
||||
|
||||
# 运行
|
||||
pnpm prod
|
||||
```
|
||||
|
||||
PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
|
||||
|
||||
#### 前端网页
|
||||
|
||||
1、修改根目录下 `.env` 文件中的 `VITE_GLOB_API_URL` 为你的实际后端接口地址
|
||||
|
||||
2、根目录下运行以下命令,然后将 `dist` 文件夹内的文件复制到你网站服务的根目录下
|
||||
|
||||
[参考信息](https://cn.vitejs.dev/guide/static-deploy.html#building-the-app)
|
||||
|
||||
```shell
|
||||
pnpm build
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
Q: 为什么 `Git` 提交总是报错?
|
||||
|
||||
A: 因为有提交信息验证,请遵循 [Commit 指南](https://github.com/Chanzhaoyu/chatgpt-web/blob/main/CONTRIBUTING.md)
|
||||
|
||||
Q: 如果只使用前端页面,在哪里改请求接口?
|
||||
|
||||
A: 根目录下 `.env` 文件中的 `VITE_GLOB_API_URL` 字段。
|
||||
|
||||
Q: 文件保存时全部爆红?
|
||||
|
||||
A: `vscode` 请安装项目推荐插件,或手动安装 `Eslint` 插件。
|
||||
|
||||
Q: 前端没有打字机效果?
|
||||
|
||||
A: 一种可能原因是经过 Nginx 反向代理,开启了 buffer,则 Nginx 会尝试从后端缓冲一定大小的数据再发送给浏览器。请尝试在反代参数后添加 `proxy_buffering off;`,然后重载 Nginx。其他 web server 配置同理。
|
||||
|
||||
## 参与贡献
|
||||
|
||||
贡献之前请先阅读 [贡献指南](https://github.com/Chanzhaoyu/chatgpt-web/blob/main/CONTRIBUTING.md)
|
||||
|
||||
感谢所有做过贡献的人!
|
||||
|
||||
<a href="https://github.com/Chanzhaoyu/chatgpt-web/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=Chanzhaoyu/chatgpt-web" />
|
||||
</a>
|
||||
|
||||
## 赞助
|
||||
|
||||
如果你觉得这个项目对你有帮助,并且情况允许的话,可以给我一点点支持,总之非常感谢支持~
|
||||
|
||||
<div style="display: flex; gap: 20px;">
|
||||
<div style="text-align: center">
|
||||
<img style="max-width: 100%" src="https://github.com/Chanzhaoyu/chatgpt-web/raw/main/docs/wechat.png" alt="微信" />
|
||||
<p>WeChat Pay</p>
|
||||
</div>
|
||||
<div style="text-align: center">
|
||||
<img style="max-width: 100%" src="https://github.com/Chanzhaoyu/chatgpt-web/raw/main/docs/alipay.png" alt="支付宝" />
|
||||
<p>Alipay</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
## License
|
||||
MIT © [ChenZhaoYu](https://github.com/Chanzhaoyu/chatgpt-web/blob/main/license)
|
||||
|
@ -12,42 +12,42 @@ additionalProperties:
|
||||
edit: true
|
||||
envKey: ACCESS_TOKEN
|
||||
labelEn: OPENAI ACCESS TOKEN (fill in at least one with OPENAI API KEY)(https://chat.openai.com/api/auth/session)
|
||||
labelZh: OPENAI ACCESS TOKEN(与OPENAI API KEY至少填一个)(https://chat.openai.com/api/auth/session)
|
||||
labelZh: OPENAI ACCESS TOKEN (与OPENAI API KEY至少填一个)(https://chat.openai.com/api/auth/session)
|
||||
required: false
|
||||
type: text
|
||||
- default: https://bypass.duti.tech/api/conversation
|
||||
edit: true
|
||||
envKey: REVERSE_PROXY
|
||||
labelEn: API reverse proxy, optional (enabled by default when OPENAI ACCESS TOKEN, need to pay attention to availability)
|
||||
labelZh: API反向代理,可选(OPENAI ACCESS TOKEN时默认启用,需要注意可用性)
|
||||
labelEn: API reverse proxy (optional)(enabled by default when OPENAI ACCESS TOKEN, need to pay attention to availability)
|
||||
labelZh: API 反向代理 (可选)(OPENAI ACCESS TOKEN 时默认启用,需要注意可用性)
|
||||
required: false
|
||||
type: text
|
||||
- default: ''
|
||||
edit: true
|
||||
envKey: API_KEY
|
||||
labelEn: OPENAI API KEY (fill in at least one with OPENAI ACCESS TOKEN)
|
||||
labelZh: OPENAI API KEY(与OPENAI ACCESS TOKEN至少填一个)
|
||||
labelZh: OPENAI API KEY (与 OPENAI ACCESS TOKEN 至少填一个)
|
||||
required: false
|
||||
type: text
|
||||
- default: gpt-3.5-turbo
|
||||
edit: true
|
||||
envKey: API_MODEL
|
||||
labelEn: API model, optional, available when setting OPENAI API KEY(https://platform.openai.com/docs/models)
|
||||
labelZh: API模型,可选,设置OPENAI API KEY时可用(https://platform.openai.com/docs/models)
|
||||
labelEn: API model (optional)(available when setting OPENAI API KEY)(https://platform.openai.com/docs/models)
|
||||
labelZh: API 模型 (可选)(设置 OPENAI API KEY 时可用)(https://platform.openai.com/docs/models)
|
||||
required: false
|
||||
type: text
|
||||
- default: https://api.openai.com
|
||||
edit: true
|
||||
envKey: API_BASE_URL
|
||||
labelEn: API interface address, optional, available when setting OPENAI API KEY
|
||||
labelZh: API接口地址,可选,设置OPENAI API KEY时可用
|
||||
labelEn: API interface address (optional)(available when setting OPENAI API KEY)
|
||||
labelZh: API接口地址 (可选)(设置 OPENAI API KEY 时可用)
|
||||
required: false
|
||||
type: text
|
||||
- default: chatgptweb
|
||||
edit: true
|
||||
envKey: SECRET_KEY
|
||||
labelEn: Access rights key, optional (recommended)
|
||||
labelZh: 访问权限密钥,可选(强烈建议填写)
|
||||
labelEn: Access rights key (optional)((recommended)
|
||||
labelZh: 访问权限密钥 (可选)(强烈建议填写)
|
||||
random: true
|
||||
required: false
|
||||
rule: paramComplexity
|
||||
@ -55,49 +55,49 @@ additionalProperties:
|
||||
- default: '0'
|
||||
edit: true
|
||||
envKey: REQUEST_LIMIT
|
||||
labelEn: Maximum number of requests per hour, optional, default unlimited
|
||||
labelZh: 每小时最大请求次数,可选,默认无限
|
||||
labelEn: Maximum number of requests per hour (optional)(default unlimited)
|
||||
labelZh: 每小时最大请求次数 (可选)(默认无限)
|
||||
required: false
|
||||
type: text
|
||||
- default: '60000'
|
||||
edit: true
|
||||
envKey: TIMEOUT
|
||||
labelEn: Timeout, in milliseconds, optional
|
||||
labelZh: 超时,单位毫秒,可选
|
||||
labelEn: Timeout(in milliseconds) (optional)
|
||||
labelZh: 超时时间(单位毫秒) (可选)
|
||||
required: false
|
||||
type: text
|
||||
- default: ''
|
||||
edit: true
|
||||
envKey: PROXY_HOST
|
||||
labelEn: Socks proxy address, optional, effective when combined with Socks proxy port
|
||||
labelZh: Socks代理地址,可选,和Socks代理端口一起时生效
|
||||
labelEn: Socks proxy address (optional)(effective when combined with Socks proxy port)
|
||||
labelZh: Socks 代理地址 (可选)(和 Socks 代理端口一起时生效)
|
||||
required: false
|
||||
type: text
|
||||
- default: ''
|
||||
edit: true
|
||||
envKey: PROXY_PORT
|
||||
labelEn: Socks proxy port, optional, effective when combined with Socks proxy address
|
||||
labelZh: Socks代理端口,可选,和Socks代理地址一起时生效
|
||||
labelEn: Socks proxy port (optional)(effective when combined with Socks proxy address)
|
||||
labelZh: Socks 代理端口 (可选)(和 Socks 代理地址一起时生效)
|
||||
required: false
|
||||
type: text
|
||||
- default: ''
|
||||
edit: true
|
||||
envKey: PROXY_USERNAME
|
||||
labelEn: Socks proxy user name, optional, effective when combined with Socks proxy address
|
||||
labelZh: Socks代理用户名,可选,和Socks代理地址一起时生效
|
||||
labelEn: Socks proxy user name (optional)(effective when combined with Socks proxy address)
|
||||
labelZh: Socks 代理用户名 (可选)(和 Socks 代理地址一起时生效)
|
||||
required: false
|
||||
type: text
|
||||
- default: ''
|
||||
edit: true
|
||||
envKey: PROXY_PASSWORD
|
||||
labelEn: Socks proxy password, optional, effective when combined with Socks proxy address
|
||||
labelZh: Socks代理密码,可选,和Socks代理地址一起时生效
|
||||
labelEn: Socks proxy password (optional)(effective when combined with Socks proxy address)
|
||||
labelZh: Socks 代理密码 (可选)(和 Socks 代理地址一起时生效)
|
||||
required: false
|
||||
type: text
|
||||
- default: ''
|
||||
edit: true
|
||||
envKey: HTTPS_PROXY
|
||||
labelEn: HTTPS proxy, optional, supports http, https, socks5
|
||||
labelZh: HTTPS代理,可选,支持http,https,socks5
|
||||
labelEn: HTTPS proxy (optional)(supports http、https、socks5)
|
||||
labelZh: HTTPS代理 (可选)(支持 http、https、socks5)
|
||||
required: false
|
||||
type: text
|
||||
|
Loading…
Reference in New Issue
Block a user