feat: close #663 allow disable user api key input

This commit is contained in:
Yidadaa
2023-05-03 23:49:33 +08:00
parent b1ea26467d
commit 074bd9f045
8 changed files with 57 additions and 23 deletions
+8 -4
View File
@@ -13,7 +13,6 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel.
[演示](https://chat-gpt-next-web.vercel.app/) / [反馈](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [QQ 群](https://user-images.githubusercontent.com/16968934/234462588-e8eff256-f5ca-46ef-8f5f-d7db6d28735a.jpg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg) [演示](https://chat-gpt-next-web.vercel.app/) / [反馈](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [QQ 群](https://user-images.githubusercontent.com/16968934/234462588-e8eff256-f5ca-46ef-8f5f-d7db6d28735a.jpg) / [打赏开发者](https://user-images.githubusercontent.com/16968934/227772541-5bcd52d8-61b7-488c-a203-0330d8006e2b.jpg)
[![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) [![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)
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web) [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web)
@@ -50,6 +49,7 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel.
- UI text customize - UI text customize
## What's New ## What's New
- 🚀 v2.0 is released, now you can create prompt templates, turn your ideas into reality! Read this: [ChatGPT Prompt Engineering Tips: Zero, One and Few Shot Prompting](https://www.allabtai.com/prompt-engineering-tips-zero-one-and-few-shot-prompting/). - 🚀 v2.0 is released, now you can create prompt templates, turn your ideas into reality! Read this: [ChatGPT Prompt Engineering Tips: Zero, One and Few Shot Prompting](https://www.allabtai.com/prompt-engineering-tips-zero-one-and-few-shot-prompting/).
## 主要功能 ## 主要功能
@@ -80,10 +80,9 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel.
- 用户登录、账号管理、消息云同步 - 用户登录、账号管理、消息云同步
## 最新动态 ## 最新动态
- 🚀 v2.0 已经发布,现在你可以使用面具功能快速创建预制对话了! 了解更多: [ChatGPT 提示词高阶技能:零次、一次和少样本提示](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/138)。 - 🚀 v2.0 已经发布,现在你可以使用面具功能快速创建预制对话了! 了解更多: [ChatGPT 提示词高阶技能:零次、一次和少样本提示](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/138)。
## Get Started ## Get Started
> [简体中文 > 如何开始使用](./README_CN.md#开始使用) > [简体中文 > 如何开始使用](./README_CN.md#开始使用)
@@ -163,6 +162,12 @@ Override openai api request base url.
Specify OpenAI organization ID. Specify OpenAI organization ID.
### `HIDE_USER_API_KEY` (optional)
> Default: Empty
If you do not want users to input their own API key, set this environment variable to 1.
## Development ## Development
> [简体中文 > 如何进行二次开发](./README_CN.md#开发) > [简体中文 > 如何进行二次开发](./README_CN.md#开发)
@@ -249,7 +254,6 @@ bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/s
[@WingCH](https://github.com/WingCH) [@WingCH](https://github.com/WingCH)
[@jtung4](https://github.com/jtung4) [@jtung4](https://github.com/jtung4)
### Contributor ### Contributor
[Contributors](https://github.com/Yidadaa/ChatGPT-Next-Web/graphs/contributors) [Contributors](https://github.com/Yidadaa/ChatGPT-Next-Web/graphs/contributors)
+9 -3
View File
@@ -33,6 +33,7 @@
- 在 Vercel 重新选择并部署,[请查看详细教程](./docs/vercel-cn.md#如何新建项目)。 - 在 Vercel 重新选择并部署,[请查看详细教程](./docs/vercel-cn.md#如何新建项目)。
### 打开自动更新 ### 打开自动更新
> 如果你遇到了 Upstream Sync 执行错误,请手动 Sync Fork 一次! > 如果你遇到了 Upstream Sync 执行错误,请手动 Sync Fork 一次!
当你 fork 项目之后,由于 Github 的限制,需要手动去你 fork 后的项目的 Actions 页面启用 Workflows,并启用 Upstream Sync Action,启用之后即可开启每小时定时自动更新: 当你 fork 项目之后,由于 Github 的限制,需要手动去你 fork 后的项目的 Actions 页面启用 Workflows,并启用 Upstream Sync Action,启用之后即可开启每小时定时自动更新:
@@ -89,6 +90,10 @@ OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填
指定 OpenAI 中的组织 ID。 指定 OpenAI 中的组织 ID。
### `HIDE_USER_API_KEY` (可选)
如果你不想让用户自行填入 API Key,将此环境变量设置为 1 即可。
## 开发 ## 开发
> 强烈不建议在本地进行开发或者部署,由于一些技术原因,很难在本地配置好 OpenAI API 代理,除非你能保证可以直连 OpenAI 服务器。 > 强烈不建议在本地进行开发或者部署,由于一些技术原因,很难在本地配置好 OpenAI API 代理,除非你能保证可以直连 OpenAI 服务器。
@@ -106,15 +111,16 @@ OPENAI_API_KEY=<your api key here>
### 本地开发 ### 本地开发
1. 安装 nodejs 18 和 yarn,具体细节请询问 ChatGPT 1. 安装 nodejs 18 和 yarn,具体细节请询问 ChatGPT
2. 执行 `yarn install && yarn dev` 即可。⚠️注意:此命令仅用于本地开发,不要用于部署! 2. 执行 `yarn install && yarn dev` 即可。⚠️ 注意:此命令仅用于本地开发,不要用于部署!
3. 如果你想本地部署,请使用 `yarn install && yarn start` 命令,你可以配合 pm2 来守护进程,防止被杀死,详情询问 ChatGPT。 3. 如果你想本地部署,请使用 `yarn install && yarn start` 命令,你可以配合 pm2 来守护进程,防止被杀死,详情询问 ChatGPT。
## 部署 ## 部署
### 容器部署 (推荐) ### 容器部署 (推荐)
> Docker 版本需要在 20 及其以上,否则会提示找不到镜像。 > Docker 版本需要在 20 及其以上,否则会提示找不到镜像。
> ⚠️注意:docker 版本在大多数时间都会落后最新的版本 1 到 2 天,所以部署后会持续出现“存在更新”的提示,属于正常现象。 > ⚠️ 注意:docker 版本在大多数时间都会落后最新的版本 1 到 2 天,所以部署后会持续出现“存在更新”的提示,属于正常现象。
```shell ```shell
docker pull yidadaa/chatgpt-next-web docker pull yidadaa/chatgpt-next-web
@@ -146,7 +152,7 @@ docker run -d -p 3000:3000 \
bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh) bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)
``` ```
⚠️注意:如果你安装过程中遇到了问题,请使用 docker 部署。 ⚠️ 注意:如果你安装过程中遇到了问题,请使用 docker 部署。
## 鸣谢 ## 鸣谢
+2 -3
View File
@@ -8,6 +8,7 @@ const serverConfig = getServerSideConfig();
// 警告!不要在这里写入任何敏感信息! // 警告!不要在这里写入任何敏感信息!
const DANGER_CONFIG = { const DANGER_CONFIG = {
needCode: serverConfig.needCode, needCode: serverConfig.needCode,
hideUserApiKey: serverConfig.hideUserApiKey,
}; };
declare global { declare global {
@@ -15,9 +16,7 @@ declare global {
} }
export async function POST() { export async function POST() {
return NextResponse.json({ return NextResponse.json(DANGER_CONFIG);
needCode: serverConfig.needCode,
});
} }
export const runtime = "edge"; export const runtime = "edge";
+15 -13
View File
@@ -466,19 +466,21 @@ export function Settings() {
<></> <></>
)} )}
<ListItem {!accessStore.hideUserApiKey ? (
title={Locale.Settings.Token.Title} <ListItem
subTitle={Locale.Settings.Token.SubTitle} title={Locale.Settings.Token.Title}
> subTitle={Locale.Settings.Token.SubTitle}
<PasswordInput >
value={accessStore.token} <PasswordInput
type="text" value={accessStore.token}
placeholder={Locale.Settings.Token.Placeholder} type="text"
onChange={(e) => { placeholder={Locale.Settings.Token.Placeholder}
accessStore.updateToken(e.currentTarget.value); onChange={(e) => {
}} accessStore.updateToken(e.currentTarget.value);
/> }}
</ListItem> />
</ListItem>
) : null}
<ListItem <ListItem
title={Locale.Settings.Usage.Title} title={Locale.Settings.Usage.Title}
+1
View File
@@ -163,6 +163,7 @@ export function SideBar(props: { className?: string }) {
onClick={() => { onClick={() => {
if (config.dontShowMaskSplashScreen) { if (config.dontShowMaskSplashScreen) {
chatStore.newSession(); chatStore.newSession();
navigate(Path.Chat);
} else { } else {
navigate(Path.NewChat); navigate(Path.NewChat);
} }
+2
View File
@@ -7,6 +7,7 @@ declare global {
CODE?: string; CODE?: string;
PROXY_URL?: string; PROXY_URL?: string;
VERCEL?: string; VERCEL?: string;
HIDE_USER_API_KEY?: string; // disable user's api key input
} }
} }
} }
@@ -38,5 +39,6 @@ export const getServerSideConfig = () => {
needCode: ACCESS_CODES.size > 0, needCode: ACCESS_CODES.size > 0,
proxyUrl: process.env.PROXY_URL, proxyUrl: process.env.PROXY_URL,
isVercel: !!process.env.VERCEL, isVercel: !!process.env.VERCEL,
hideUserApiKey: !!process.env.HIDE_USER_API_KEY,
}; };
}; };
+6
View File
@@ -8,6 +8,7 @@ export interface AccessControlStore {
token: string; token: string;
needCode: boolean; needCode: boolean;
hideUserApiKey: boolean;
openaiUrl: string; openaiUrl: string;
updateToken: (_: string) => void; updateToken: (_: string) => void;
@@ -25,6 +26,7 @@ export const useAccessStore = create<AccessControlStore>()(
token: "", token: "",
accessCode: "", accessCode: "",
needCode: true, needCode: true,
hideUserApiKey: false,
openaiUrl: "/api/openai/", openaiUrl: "/api/openai/",
enabledAccessControl() { enabledAccessControl() {
@@ -55,6 +57,10 @@ export const useAccessStore = create<AccessControlStore>()(
.then((res: DangerConfig) => { .then((res: DangerConfig) => {
console.log("[Config] got config from server", res); console.log("[Config] got config from server", res);
set(() => ({ ...res })); set(() => ({ ...res }));
if ((res as any).botHello) {
BOT_HELLO.content = (res as any).botHello;
}
}) })
.catch(() => { .catch(() => {
console.error("[Config] failed to fetch config"); console.error("[Config] failed to fetch config");
+14
View File
@@ -4,6 +4,20 @@ const nextConfig = {
experimental: { experimental: {
appDir: true, appDir: true,
}, },
async rewrites() {
const ret = [];
const apiUrl = process.env.API_URL;
if (apiUrl) {
console.log("[Next] using api url ", apiUrl);
ret.push({
source: "/api/:path*",
destination: `${apiUrl}/:path*`,
});
}
return ret;
},
webpack(config) { webpack(config) {
config.module.rules.push({ config.module.rules.push({
test: /\.svg$/, test: /\.svg$/,