From c8be5e42671e534e3382db67f80560442086772c Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Apr 2023 00:56:56 +0800 Subject: [PATCH 01/12] feat: add docker proxy --- Dockerfile | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 6f7547b21..47373c906 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,6 +3,7 @@ FROM node:18-alpine AS base FROM base AS deps RUN apk add --no-cache libc6-compat +RUN apk --no-cache add proxychains-ng WORKDIR /app @@ -27,6 +28,7 @@ RUN yarn build FROM base AS runner WORKDIR /app +ENV PROXY_URL="" ENV OPENAI_API_KEY="" ENV CODE="" @@ -37,4 +39,12 @@ COPY --from=builder /app/.next/server ./.next/server EXPOSE 3000 -CMD ["node","server.js"] +CMD if [ -n "$PROXY_URL" ]; then \ + protocol=$(echo $PROXY_URL | cut -d: -f1); \ + host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \ + port=$(echo $PROXY_URL | cut -d: -f3); \ + echo "$protocol $host $port" >> /etc/proxychains.conf; \ + proxychains node server.js; \ + else \ + node server.js; \ + fi \ No newline at end of file From 72aa2bcad8a8715388e62bf7c9d7daa8462f03bf Mon Sep 17 00:00:00 2001 From: Yifei Zhang Date: Sun, 9 Apr 2023 13:31:33 +0800 Subject: [PATCH 02/12] Update cn.ts --- app/locales/cn.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 01b236d7f..dacbafc3f 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -126,7 +126,7 @@ const cn = { }, AccessCode: { Title: "访问密码", - SubTitle: "现在是未授权访问状态", + SubTitle: "已开启加密访问", Placeholder: "请输入访问密码", }, Model: "模型 (model)", From 1bb7b4a6536884eb2eb9826a2a40751e224bb0b3 Mon Sep 17 00:00:00 2001 From: yidadaa Date: Sun, 9 Apr 2023 20:35:42 +0800 Subject: [PATCH 03/12] feat: add proxy for docker --- Dockerfile | 18 ++++++++++++++---- scripts/fetch-prompts.mjs | 15 +++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index 47373c906..018396ef3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,12 @@ FROM node:18-alpine AS base FROM base AS deps RUN apk add --no-cache libc6-compat -RUN apk --no-cache add proxychains-ng WORKDIR /app COPY package.json yarn.lock ./ +RUN yarn config set registry 'https://registry.npm.taobao.org' RUN yarn install FROM base AS builder @@ -28,6 +28,8 @@ RUN yarn build FROM base AS runner WORKDIR /app +RUN apk add proxychains-ng + ENV PROXY_URL="" ENV OPENAI_API_KEY="" ENV CODE="" @@ -43,8 +45,16 @@ CMD if [ -n "$PROXY_URL" ]; then \ protocol=$(echo $PROXY_URL | cut -d: -f1); \ host=$(echo $PROXY_URL | cut -d/ -f3 | cut -d: -f1); \ port=$(echo $PROXY_URL | cut -d: -f3); \ - echo "$protocol $host $port" >> /etc/proxychains.conf; \ - proxychains node server.js; \ + conf=/etc/proxychains.conf; \ + echo "strict_chain" >> $conf; \ + echo "proxy_dns" >> $conf; \ + echo "remote_dns_subnet 224" >> $conf; \ + echo "tcp_read_time_out 15000" >> $conf; \ + echo "tcp_connect_time_out 8000" >> $conf; \ + echo "[ProxyList]" >> $conf; \ + echo "$protocol $host $port" >> $conf; \ + cat /etc/proxychains.conf; \ + proxychains -f $conf node server.js; \ else \ node server.js; \ - fi \ No newline at end of file + fi diff --git a/scripts/fetch-prompts.mjs b/scripts/fetch-prompts.mjs index 3c4801443..7f6818d3b 100644 --- a/scripts/fetch-prompts.mjs +++ b/scripts/fetch-prompts.mjs @@ -1,14 +1,13 @@ import fetch from "node-fetch"; import fs from "fs/promises"; -const RAW_CN_URL = - "https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json"; -const CN_URL = - "https://cdn.jsdelivr.net/gh/PlexPt/awesome-chatgpt-prompts-zh@main/prompts-zh.json"; -const RAW_EN_URL = - "https://raw.githubusercontent.com/f/awesome-chatgpt-prompts/main/prompts.csv"; -const EN_URL = - "https://cdn.jsdelivr.net/gh/f/awesome-chatgpt-prompts@main/prompts.csv"; +const RAW_FILE_URL = "https://raw.githubusercontent.com/"; +const MIRRORF_FILE_URL = "https://raw.fgit.ml/"; + +const RAW_CN_URL = "PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json"; +const CN_URL = MIRRORF_FILE_URL + RAW_CN_URL; +const RAW_EN_URL = "f/awesome-chatgpt-prompts/main/prompts.csv"; +const EN_URL = MIRRORF_FILE_URL + RAW_EN_URL; const FILE = "./public/prompts.json"; async function fetchCN() { From 0c92d49f896265b1cb863ec5cd8c8e7fb2b0dceb Mon Sep 17 00:00:00 2001 From: yidadaa Date: Sun, 9 Apr 2023 20:43:34 +0800 Subject: [PATCH 04/12] chore: update readme --- README.md | 33 +++++++++++++++++++++++++++++---- README_CN.md | 23 +++++++++++++++++++++-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 55a6da404..ba4a6dc49 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,8 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel. - 一键导出聊天记录,完整的 Markdown 支持 - 拥有自己的域名?好上加好,绑定后即可在任何地方**无障碍**快速访问 -## 开发计划 +## 开发计划 + - [x] 为每个对话设置系统 Prompt [#138](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/138) - [ ] 允许用户自行编辑内置 Prompt 列表 - [ ] 使用 tauri 打包桌面应用 @@ -58,11 +59,12 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel. - [ ] 插件机制,支持联网搜索、计算器、调用其他平台 api [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165) ### 不会开发的功能 + - 界面文字自定义 - 用户登录、账号管理、消息云同步 - ## Get Started + > [简体中文 > 如何开始使用](./README_CN.md#开始使用) 1. Get [OpenAI API Key](https://platform.openai.com/account/api-keys); @@ -71,9 +73,11 @@ One-Click to deploy well-designed ChatGPT web UI on Vercel. 3. Enjoy :) ## FAQ + [简体中文 > 常见问题](./docs/faq-cn.md) | [English > FAQ](./docs/faq.en.md) ## Keep Updated + > [简体中文 > 如何保持代码更新](./README_CN.md#保持更新) If you have deployed your own project with just one click following the steps above, you may encounter the issue of "Updates Available" constantly showing up. This is because Vercel will create a new project for you by default instead of forking this project, resulting in the inability to detect updates correctly. @@ -87,11 +91,12 @@ We recommend that you follow the steps below to re-deploy: This project will be continuously updated, and after forking the project, the upstream code will be automatically synchronized every day without additional operations. -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. +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. ## Access Password + > [简体中文 > 如何增加访问密码](./README_CN.md#配置页面访问密码) 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: @@ -103,6 +108,7 @@ code1,code2,code3 After adding or modifying this environment variable, please redeploy the project for the changes to take effect. ## Environment Variables + > [简体中文 > 如何配置 api key、访问密码、接口代理](./README_CN.md#环境变量) ### `OPENAI_API_KEY` (required) @@ -128,6 +134,7 @@ Override openai api request base url. Override openai api request protocol. ## Development + > [简体中文 > 如何进行二次开发](./README_CN.md#开发) [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web) @@ -149,13 +156,28 @@ yarn dev ``` ## Deployment + > [简体中文 > 如何部署到私人服务器](./README_CN.md#部署) + ### Docker (Recommended) ```shell docker pull yidadaa/chatgpt-next-web -docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next-web +docker run -d -p 3000:3000 \ + -e OPENAI_API_KEY="sk-xxxx" \ + -e CODE="your-password" \ + yidadaa/chatgpt-next-web +``` + +You can start service behind a proxy: + +```shell +docker run -d -p 3000:3000 \ + -e OPENAI_API_KEY="sk-xxxx" \ + -e CODE="your-password" \ + -e PROXY_URL="http://localhost:7890" \ + yidadaa/chatgpt-next-web ``` ### Shell @@ -163,6 +185,7 @@ docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next- ```shell bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh) ``` + ## Screenshots ![Settings](./docs/images/settings.png) @@ -170,9 +193,11 @@ bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/s ![More](./docs/images/more.png) ## Donation + [Buy Me a Coffee](https://www.buymeacoffee.com/yidadaa) ## Special Thanks + ### Sponsor [@mushan0x0](https://github.com/mushan0x0) diff --git a/README_CN.md b/README_CN.md index efd5d56a1..0833ae1ac 100644 --- a/README_CN.md +++ b/README_CN.md @@ -64,6 +64,7 @@ code1,code2,code3 增加或修改该环境变量后,请**重新部署**项目使改动生效。 ## 环境变量 + > 本项目大多数配置项都通过环境变量来设置。 ### `OPENAI_API_KEY` (必填项) @@ -110,25 +111,42 @@ OPENAI_API_KEY= 2. 执行 `yarn install && yarn dev` 即可。 ## 部署 + ### 容器部署 (推荐) + > 注意:docker 版本在大多数时间都会落后最新的版本 1 到 2 天,所以部署后会持续出现“存在更新”的提示,属于正常现象。 ```shell docker pull yidadaa/chatgpt-next-web -docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next-web +docker run -d -p 3000:3000 \ + -e OPENAI_API_KEY="sk-xxxx" \ + -e CODE="页面访问密码" \ + yidadaa/chatgpt-next-web +``` + +你也可以指定 proxy: + +```shell +docker run -d -p 3000:3000 \ + -e OPENAI_API_KEY="sk-xxxx" \ + -e CODE="页面访问密码" \ + -e PROXY_URL="http://localhost:7890" \ + yidadaa/chatgpt-next-web ``` ### 本地部署 + 在控制台运行下方命令: ```shell bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh) ``` - ## 鸣谢 + ### 捐赠者 + > 仅列出了部分大额打赏,小额打赏(< 100RMB)人数太多,在此不再列出,敬请谅解。 [@mushan0x0](https://github.com/mushan0x0) @@ -141,6 +159,7 @@ bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/s [见项目贡献者列表](https://github.com/Yidadaa/ChatGPT-Next-Web/graphs/contributors) ## 开源协议 + > 反对 996,从我开始。 [Anti 996 License](https://github.com/kattgu7/Anti-996-License/blob/master/LICENSE_CN_EN) From 174c745279f7f27b2283318695060184468641ab Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Apr 2023 23:35:45 +0800 Subject: [PATCH 05/12] fix: #648 password input style --- app/components/settings.module.scss | 7 ++++++- app/components/settings.tsx | 8 ++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/components/settings.module.scss b/app/components/settings.module.scss index 7d40d83b8..830e1baeb 100644 --- a/app/components/settings.module.scss +++ b/app/components/settings.module.scss @@ -19,11 +19,16 @@ cursor: pointer; } -.password-input { +.password-input-container { + max-width: 50%; display: flex; justify-content: flex-end; .password-eye { margin-right: 4px; } + + .password-input { + min-width: 80%; + } } diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 0d1c1d05c..15fe58398 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -60,13 +60,17 @@ function PasswordInput(props: HTMLProps) { } return ( -
+
: } onClick={changeVisibility} className={styles["password-eye"]} /> - +
); } From 4a492264a164fb9f771025fde466a389d1e0e624 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Apr 2023 23:41:16 +0800 Subject: [PATCH 06/12] fix: #641 delete wrong chat list --- app/components/chat-list.tsx | 2 +- app/components/ui-lib.module.scss | 2 ++ app/components/ui-lib.tsx | 2 +- app/store/app.ts | 8 ++++---- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/components/chat-list.tsx b/app/components/chat-list.tsx index ab5d849f1..cab8812c3 100644 --- a/app/components/chat-list.tsx +++ b/app/components/chat-list.tsx @@ -96,7 +96,7 @@ export function ChatList() { index={i} selected={i === selectedIndex} onClick={() => selectSession(i)} - onDelete={chatStore.deleteSession} + onDelete={() => chatStore.deleteSession(i)} /> ))} {provided.placeholder} diff --git a/app/components/ui-lib.module.scss b/app/components/ui-lib.module.scss index 67d13d3e8..457c55049 100644 --- a/app/components/ui-lib.module.scss +++ b/app/components/ui-lib.module.scss @@ -127,6 +127,7 @@ width: 100vw; display: flex; justify-content: center; + pointer-events: none; .toast-content { max-width: 80vw; @@ -141,6 +142,7 @@ margin-bottom: 20px; display: flex; align-items: center; + pointer-events: all; .toast-action { padding-left: 20px; diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx index a72aa868f..3179b2139 100644 --- a/app/components/ui-lib.tsx +++ b/app/components/ui-lib.tsx @@ -156,7 +156,7 @@ export function showToast( }; setTimeout(() => { - close(); + // close(); }, delay); root.render(); diff --git a/app/store/app.ts b/app/store/app.ts index 02fb4b32a..7c68547ff 100644 --- a/app/store/app.ts +++ b/app/store/app.ts @@ -205,7 +205,7 @@ interface ChatStore { moveSession: (from: number, to: number) => void; selectSession: (index: number) => void; newSession: () => void; - deleteSession: () => void; + deleteSession: (index?: number) => void; currentSession: () => ChatSession; onNewMessage: (message: Message) => void; onUserInput: (content: string) => Promise; @@ -326,13 +326,13 @@ export const useChatStore = create()( })); }, - deleteSession() { + deleteSession(i?: number) { const deletedSession = get().currentSession(); - const index = get().currentSessionIndex; + const index = i ?? get().currentSessionIndex; const isLastSession = get().sessions.length === 1; if (!isMobileScreen() || confirm(Locale.Home.DeleteChat)) { get().removeSession(index); - + showToast(Locale.Home.DeleteToast, { text: Locale.Home.Revert, onClick() { From 0e05733bbb9ebe3ee40f23edf41531ea6d4f8d70 Mon Sep 17 00:00:00 2001 From: Yidadaa Date: Sun, 9 Apr 2023 23:51:12 +0800 Subject: [PATCH 07/12] fix: #589 improve unauthorized tips --- app/components/chat.tsx | 9 ++++- app/components/settings.tsx | 65 +++++++++++++++++++------------------ app/components/ui-lib.tsx | 2 +- app/locales/cn.ts | 4 +-- app/store/access.ts | 8 +++-- app/store/app.ts | 26 +++++++++------ 6 files changed, 66 insertions(+), 48 deletions(-) diff --git a/app/components/chat.tsx b/app/components/chat.tsx index c5c257e54..fbac9f2c3 100644 --- a/app/components/chat.tsx +++ b/app/components/chat.tsx @@ -19,6 +19,7 @@ import { BOT_HELLO, ROLES, createMessage, + useAccessStore, } from "../store"; import { @@ -485,11 +486,17 @@ export function Chat(props: { const context: RenderMessage[] = session.context.slice(); + const accessStore = useAccessStore(); + if ( context.length === 0 && session.messages.at(0)?.content !== BOT_HELLO.content ) { - context.push(BOT_HELLO); + const copiedHello = Object.assign({}, BOT_HELLO); + if (!accessStore.isAuthorized()) { + copiedHello.content = Locale.Error.Unauthorized; + } + context.push(copiedHello); } // preview messages diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 15fe58398..bbb28b46e 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -124,8 +124,7 @@ export function Settings(props: { closeSettings: () => void }) { const builtinCount = SearchService.count.builtin; const customCount = promptStore.prompts.size ?? 0; - const showUsage = !!accessStore.token || !!accessStore.accessCode; - + const showUsage = accessStore.isAuthorized(); useEffect(() => { checkUpdate(); showUsage && checkUsage(); @@ -346,37 +345,7 @@ export function Settings(props: { closeSettings: () => void }) { > - - - - updateConfig( - (config) => - (config.disablePromptHint = e.currentTarget.checked), - ) - } - > - - - } - text={Locale.Settings.Prompt.Edit} - onClick={() => showToast(Locale.WIP)} - /> - - {enabledAccessControl ? ( void }) { + + + + updateConfig( + (config) => + (config.disablePromptHint = e.currentTarget.checked), + ) + } + > + + + + } + text={Locale.Settings.Prompt.Edit} + onClick={() => showToast(Locale.WIP)} + /> + + +