Skip to content

Commit

Permalink
Merge pull request ChatGPTNextWeb#812 from Yidadaa/bugfix-0415
Browse files Browse the repository at this point in the history
refactor: remove protocol env vars
  • Loading branch information
Yidadaa committed Apr 14, 2023
2 parents f5a05da + ad274b7 commit e0f6c80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,15 @@ We recommend that you follow the steps below to re-deploy:
- Choose and deploy in Vercel again, [please see the detailed tutorial](./docs/vercel-cn.md).

### Enable Automatic Updates

After forking the project, due to the limitations imposed by Github, you need to manually enable Workflows and Upstream Sync Action on the Actions page of the forked project. Once enabled, automatic updates will be scheduled every hour:

![Automatic Updates](./docs/images/enable-actions.jpg)

![Enable Automatic Updates](./docs/images/enable-actions-sync.jpg)

### Manually Updating Code

If you want to update instantly, you can check out the [Github documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) to learn how to synchronize a forked project with upstream code.

You can star or watch this project or follow author to get release notifictions in time.
Expand Down Expand Up @@ -134,17 +136,11 @@ Access passsword, separated by comma.

### `BASE_URL` (optional)

> Default: `api.openai.com`
Override openai api request base url.
> Default: `https://api.openai.com`
### `PROTOCOL` (optional)
> Examples: `http:https://your-openai-proxy.com`
> Default: `https`
> Values: `http` | `https`
Override openai api request protocol.
Override openai api request base url.

## Development

Expand Down
13 changes: 5 additions & 8 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- 在 Vercel 重新选择并部署,[请查看详细教程](./docs/vercel-cn.md#如何新建项目)

### 打开自动更新

当你 fork 项目之后,由于 Github 的限制,需要手动去你 fork 后的项目的 Actions 页面启用 Workflows,并启用 Upstream Sync Action,启用之后即可开启每小时定时自动更新:

![自动更新](./docs/images/enable-actions.jpg)
Expand Down Expand Up @@ -85,17 +86,13 @@ OpanAI 密钥,你在 openai 账户页面申请的 api key。

### `BASE_URL` (可选)

> Default: `api.openai.com`
OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填写此选项。
> Default: `https://api.openai.com`
### `PROTOCOL` (可选)
> Examples: `http:https://your-openai-proxy.com`
> Default: `https`
> Values: `http` | `https`
OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填写此选项。

OpenAI 代理接口协议,如果遇到 ssl 证书问题,请尝试通过此选项设置为 http。
> 如果遇到 ssl 证书问题,请将 `BASE_URL` 的协议设置为 http。
## 开发

Expand Down
9 changes: 8 additions & 1 deletion app/api/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ export async function requestOpenai(req: NextRequest) {
const apiKey = req.headers.get("token");
const openaiPath = req.headers.get("path");

let baseUrl = BASE_URL;

if (!baseUrl.startsWith("http")) {
baseUrl = `${PROTOCOL}:https://${baseUrl}`;
}

console.log("[Proxy] ", openaiPath);
console.log("[Base Url]", baseUrl);

return fetch(`${PROTOCOL}:https://${BASE_URL}/${openaiPath}`, {
return fetch(`${baseUrl}/${openaiPath}`, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${apiKey}`,
Expand Down

0 comments on commit e0f6c80

Please sign in to comment.