Skip to content

Commit 6ed61f5

Browse files
committed
Merge branch 'main' of https://github.com/Yidadaa/ChatGPT-Next-Web into multi-arch-docker-build
2 parents ad7a365 + 8d6d6bb commit 6ed61f5

19 files changed

Lines changed: 360 additions & 166 deletions

File tree

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
uses: docker/build-push-action@v4
4444
with:
4545
context: .
46-
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
46+
platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8
4747
push: true
4848
tags: ${{ steps.meta.outputs.tags }}
4949
labels: ${{ steps.meta.outputs.labels }}

.lintstagedrc.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"./app/**/*.{js,ts,jsx,tsx,json,html,css,scss,md}": [
3-
"eslint --fix",
4-
"prettier --write"
5-
]
6-
}
2+
"./app/**/*.{js,ts,jsx,tsx,json,html,css,md}": [
3+
"eslint --fix",
4+
"prettier --write"
5+
]
6+
}

README.md

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
One-Click to deploy your own ChatGPT web UI.
99

10-
[演示 Demo](https://chat-gpt-next-web.vercel.app/) / [反馈 Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [加入 Discord](https://discord.gg/zrhvHCr79N) / [QQ 群](https://user-images.githubusercontent.com/16968934/228190818-7dd00845-e9b9-4363-97e5-44c507ac76da.jpeg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg)
10+
[演示 Demo](https://chat-gpt-next-web.vercel.app/) / [反馈 Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [加入 Discord](https://discord.gg/zrhvHCr79N) / [QQ 群](https://user-images.githubusercontent.com/16968934/228190818-7dd00845-e9b9-4363-97e5-44c507ac76da.jpeg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg) / [Donate](#捐赠-donate-usdt)
1111

1212
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FYidadaa%2FChatGPT-Next-Web&env=OPENAI_API_KEY&env=CODE&project-name=chatgpt-next-web&repository-name=ChatGPT-Next-Web)
1313

@@ -78,24 +78,56 @@ This project will be continuously maintained. If you want to keep the code repos
7878

7979
You can star or watch this project or follow author to get release notifictions in time.
8080

81-
## 访问控制 Access Control
81+
## 配置密码 Password
8282

83-
本项目提供有限的权限控制功能,请在环境变量页增加名为 `CODE` 的环境变量,值为用英文逗号分隔的自定义控制码
83+
本项目提供有限的权限控制功能,请在 Vercel 项目控制面板的环境变量页增加名为 `CODE` 的环境变量,值为用英文逗号分隔的自定义密码
8484

8585
```
8686
code1,code2,code3
8787
```
8888

8989
增加或修改该环境变量后,请**重新部署**项目使改动生效。
9090

91-
This project provides limited access control. Please add an environment variable named `CODE` on the environment variables page. The value should be a custom control code separated by comma like this:
91+
This project provides limited access control. Please add an environment variable named `CODE` on the vercel environment variables page. The value should be passwords separated by comma like this:
9292

9393
```
9494
code1,code2,code3
9595
```
9696

9797
After adding or modifying this environment variable, please redeploy the project for the changes to take effect.
9898

99+
## 环境变量 Environment Variables
100+
101+
### `OPENAI_API_KEY` (required)
102+
103+
OpanAI 密钥。
104+
105+
Your openai api key.
106+
107+
### `CODE` (optional)
108+
109+
访问密码,可选,可以使用逗号隔开多个密码。
110+
111+
Access passsword, separated by comma.
112+
113+
### `BASE_URL` (optional)
114+
115+
> Default: `api.openai.com`
116+
117+
OpenAI 接口代理 URL。
118+
119+
Override openai api request base url.
120+
121+
### `PROTOCOL` (optional)
122+
123+
> Default: `https`
124+
125+
> Values: `http` | `https`
126+
127+
OpenAI 接口协议。
128+
129+
Override openai api request protocol.
130+
99131
## 开发 Development
100132

101133
点击下方按钮,开始二次开发:
@@ -118,11 +150,11 @@ OPENAI_API_KEY=<your api key here>
118150
2. 执行 `yarn install && yarn dev` 即可。
119151

120152
### 本地部署 Local Deployment
153+
121154
```shell
122155
bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)
123156
```
124157

125-
126158
### 容器部署 Docker Deployment
127159

128160
```shell
@@ -137,15 +169,12 @@ docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next-
137169

138170
![更多展示 More](./static/more.png)
139171

140-
## 说明 Attention
141172

142-
本项目的演示地址所用的 OpenAI 账户的免费额度将于 2023-04-01 过期,届时将无法通过演示地址在线体验。
143-
144-
如果你想贡献出自己的 API Key,可以通过作者主页的邮箱发送给作者,并标注过期时间。
145-
146-
The free trial of the OpenAI account used by the demo will expire on April 1, 2023, and the demo will not be available at that time.
147-
148-
If you would like to contribute your API key, you can email it to the author and indicate the expiration date of the API key.
173+
## 捐赠 Donate USDT
174+
> BNB Smart Chain (BEP 20)
175+
```
176+
0x67cD02c7EB62641De576a1fA3EdB32eA0c3ffD89
177+
```
149178

150179
## 鸣谢 Special Thanks
151180

@@ -157,6 +186,7 @@ If you would like to contribute your API key, you can email it to the author and
157186
[@hoochanlon](https://github.com/hoochanlon)
158187

159188
### 贡献者 Contributor
189+
160190
[Contributors](https://github.com/Yidadaa/ChatGPT-Next-Web/graphs/contributors)
161191

162192
## LICENSE

app/api/chat-stream/route.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
import { createParser } from "eventsource-parser";
22
import { NextRequest } from "next/server";
3+
import { requestOpenai } from "../common";
34

45
async function createStream(req: NextRequest) {
56
const encoder = new TextEncoder();
67
const decoder = new TextDecoder();
78

8-
let apiKey = process.env.OPENAI_API_KEY;
9-
10-
const userApiKey = req.headers.get("token");
11-
if (userApiKey) {
12-
apiKey = userApiKey;
13-
console.log("[Stream] using user api key");
14-
}
15-
16-
const res = await fetch("https://api.openai.com/v1/chat/completions", {
17-
headers: {
18-
"Content-Type": "application/json",
19-
Authorization: `Bearer ${apiKey}`,
20-
},
21-
method: "POST",
22-
body: req.body,
23-
});
9+
const res = await requestOpenai(req);
2410

2511
const stream = new ReadableStream({
2612
async start(controller) {

app/api/chat/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/api/chat/route.ts

Lines changed: 0 additions & 29 deletions
This file was deleted.

app/api/common.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { NextRequest } from "next/server";
2+
3+
const OPENAI_URL = "api.openai.com";
4+
const DEFAULT_PROTOCOL = "https";
5+
const PROTOCOL = process.env.PROTOCOL ?? DEFAULT_PROTOCOL;
6+
const BASE_URL = process.env.BASE_URL ?? OPENAI_URL;
7+
8+
export async function requestOpenai(req: NextRequest) {
9+
const apiKey = req.headers.get("token");
10+
const openaiPath = req.headers.get("path");
11+
12+
console.log("[Proxy] ", openaiPath);
13+
14+
return fetch(`${PROTOCOL}://${BASE_URL}/${openaiPath}`, {
15+
headers: {
16+
"Content-Type": "application/json",
17+
Authorization: `Bearer ${apiKey}`,
18+
},
19+
method: req.method,
20+
body: req.body,
21+
});
22+
}

app/api/openai/route.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
import { requestOpenai } from "../common";
3+
4+
async function makeRequest(req: NextRequest) {
5+
try {
6+
const res = await requestOpenai(req);
7+
return new Response(res.body);
8+
} catch (e) {
9+
console.error("[OpenAI] ", req.body, e);
10+
return NextResponse.json(
11+
{
12+
error: true,
13+
msg: JSON.stringify(e),
14+
},
15+
{
16+
status: 500,
17+
},
18+
);
19+
}
20+
}
21+
22+
export async function POST(req: NextRequest) {
23+
return makeRequest(req);
24+
}
25+
26+
export async function GET(req: NextRequest) {
27+
return makeRequest(req);
28+
}

app/components/home.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@
221221
margin-bottom: 100px;
222222
}
223223

224+
.chat-body-title {
225+
cursor: pointer;
226+
227+
&:hover {
228+
text-decoration: underline;
229+
}
230+
}
231+
224232
.chat-message {
225233
display: flex;
226234
flex-direction: row;

0 commit comments

Comments
 (0)