Merge pull request #510 from Yidadaa/user-prompt
feat: split docs, clear messages and fix stop response
5
.gitignore
vendored
@ -36,4 +36,7 @@ yarn-error.log*
|
||||
next-env.d.ts
|
||||
dev
|
||||
|
||||
public/prompts.json
|
||||
public/prompts.json
|
||||
|
||||
.vscode
|
||||
.idea
|
4
.vscode/settings.json
vendored
@ -1,4 +0,0 @@
|
||||
{
|
||||
"typescript.tsdk": "node_modules\\typescript\\lib",
|
||||
"typescript.enablePromptUseWorkspaceTsdk": true
|
||||
}
|
151
README.md
@ -1,84 +1,82 @@
|
||||
<div align="center">
|
||||
<img src="./static/icon.svg" alt="预览"/>
|
||||
<img src="./docs/images/icon.svg" alt="icon"/>
|
||||
|
||||
<h1 align="center">ChatGPT Next Web</h1>
|
||||
|
||||
一键免费部署你的私人 ChatGPT 网页应用。
|
||||
|
||||
One-Click to deploy your own ChatGPT web UI.
|
||||
|
||||
[演示 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)
|
||||
一键免费部署你的私人 ChatGPT 网页应用。
|
||||
|
||||
[演示 Demo](https://chat-gpt-next-web.vercel.app/) / [反馈 Issues](https://github.com/Yidadaa/ChatGPT-Next-Web/issues) / [Join 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)
|
||||
|
||||
[![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)
|
||||
|
||||
![主界面](./static/cover.png)
|
||||
![cover](./docs/images/cover.png)
|
||||
|
||||
</div>
|
||||
|
||||
## 主要功能
|
||||
|
||||
- 在 1 分钟内使用 Vercel **免费一键部署**
|
||||
- 精心设计的 UI,响应式设计,支持深色模式
|
||||
- 极快的首屏加载速度(~100kb)
|
||||
- 海量的内置 prompt 列表,来自[中文](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)和[英文](https://github.com/f/awesome-chatgpt-prompts)
|
||||
- 自动压缩上下文聊天记录,在节省 Token 的同时支持超长对话
|
||||
- 一键导出聊天记录,完整的 Markdown 支持
|
||||
- 拥有自己的域名?好上加好,绑定后即可在任何地方**无障碍**快速访问
|
||||
|
||||
## Features
|
||||
|
||||
- **Deploy for free with one-click** on Vercel in under 1 minute
|
||||
- Responsive design, and dark mode
|
||||
- Responsive design, dark mode and PWA
|
||||
- Fast first screen loading speed (~100kb)
|
||||
- Awesome prompts powered by [awesome-chatgpt-prompts-zh](https://github.com/PlexPt/awesome-chatgpt-prompts-zh) and [awesome-chatgpt-prompts](https://github.com/f/awesome-chatgpt-prompts)
|
||||
- Automatically compresses chat history to support long conversations while also saving your tokens
|
||||
- One-click export all chat history with full Markdown support
|
||||
- I18n supported
|
||||
|
||||
## 开发计划 Roadmap
|
||||
## Roadmap
|
||||
|
||||
- System Prompt: pin a user defined prompt as system prompt 为每个对话设置系统 Prompt [#138](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/138)
|
||||
- User Prompt: user can edit and save custom prompts to prompt list 允许用户自行编辑内置 Prompt 列表
|
||||
- Self-host Model: support llama, alpaca, ChatGLM, BELLE etc. 支持自部署的大语言模型
|
||||
- Plugins: support network search, caculator, any other apis etc. 插件机制,支持联网搜索、计算器、调用其他平台 api [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
|
||||
- [x] System Prompt: pin a user defined prompt as system prompt [#138](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/138)
|
||||
- [ ] User Prompt: user can edit and save custom prompts to prompt list
|
||||
- [ ] Desktop App with tauri
|
||||
- [ ] Self-host Model: support llama, alpaca, ChatGLM, BELLE etc.
|
||||
- [ ] Plugins: support network search, caculator, any other apis etc. [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
|
||||
|
||||
### 不会开发的功能 Not in Plan
|
||||
### Not in Plan
|
||||
|
||||
- User login, accounts, cloud sync 用户登录、账号管理、消息云同步
|
||||
- UI text customize 界面文字自定义
|
||||
- User login, accounts, cloud sync
|
||||
- UI text customize
|
||||
|
||||
## 开始使用
|
||||
## 主要功能
|
||||
|
||||
- 在 1 分钟内使用 Vercel **免费一键部署**
|
||||
- 精心设计的 UI,响应式设计,支持深色模式,支持 PWA
|
||||
- 极快的首屏加载速度(~100kb)
|
||||
- 海量的内置 prompt 列表,来自[中文](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)和[英文](https://github.com/f/awesome-chatgpt-prompts)
|
||||
- 自动压缩上下文聊天记录,在节省 Token 的同时支持超长对话
|
||||
- 一键导出聊天记录,完整的 Markdown 支持
|
||||
- 拥有自己的域名?好上加好,绑定后即可在任何地方**无障碍**快速访问
|
||||
|
||||
## 开发计划
|
||||
- [x] 为每个对话设置系统 Prompt [#138](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/138)
|
||||
- [ ] 允许用户自行编辑内置 Prompt 列表
|
||||
- [ ] 使用 tauri 打包桌面应用
|
||||
- [ ] 支持自部署的大语言模型
|
||||
- [ ] 插件机制,支持联网搜索、计算器、调用其他平台 api [#165](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/165)
|
||||
|
||||
### 不会开发的功能
|
||||
- 界面文字自定义
|
||||
- 用户登录、账号管理、消息云同步
|
||||
|
||||
1. 准备好你的 [OpenAI API Key](https://platform.openai.com/account/api-keys);
|
||||
2. 点击右侧按钮开始部署:
|
||||
[![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),直接使用 Github 账号登录即可,记得在环境变量页填入 API Key;
|
||||
3. 部署完毕后,即可开始使用;
|
||||
4. (可选)[绑定自定义域名](https://vercel.com/docs/concepts/projects/domains/add-a-domain):Vercel 分配的域名 DNS 在某些区域被污染了,绑定自定义域名即可直连。
|
||||
|
||||
## Get Started
|
||||
> [简体中文 > 如何开始使用](./README_CN.md#开始使用)
|
||||
|
||||
1. Get [OpenAI API Key](https://platform.openai.com/account/api-keys);
|
||||
2. Click
|
||||
[![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), remember that `CODE` is your page password;
|
||||
3. Enjoy :)
|
||||
|
||||
## 保持更新 Keep Updated
|
||||
## FAQ
|
||||
> [简体中文 > 常见问题](./docs/faq-cn.md)
|
||||
|
||||
如果你按照上述步骤一键部署了自己的项目,可能会发现总是提示“存在更新”的问题,这是由于 Vercel 会默认为你创建一个新项目而不是 fork 本项目,这会导致无法正确地检测更新。
|
||||
推荐你按照下列步骤重新部署:
|
||||
We are sorry that there is currently no English version of the FAQ. English users can use translation tools to access the document. We look forward to receiving your PR for an English version of the documentation.
|
||||
|
||||
- 删除掉原先的 repo;
|
||||
- fork 本项目;
|
||||
- 前往 vercel 控制台,删除掉原先的 project,然后新建 project,选择你刚刚 fork 出来的项目重新进行部署即可;
|
||||
- 在重新部署的过程中,请手动添加名为 `OPENAI_API_KEY` 的环境变量,并填入你的 api key 作为值。
|
||||
|
||||
本项目会持续更新,当你 Fork 项目之后,默认会每天自动同步上游代码,无需额外操作。
|
||||
|
||||
如果你想让手动立即更新,可以查看 [Github 的文档](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) 了解如何让 fork 的项目与上游代码同步。
|
||||
|
||||
你可以 star/watch 本项目或者 follow 作者来及时获得新功能更新通知。
|
||||
## 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.
|
||||
|
||||
@ -95,15 +93,8 @@ If you want to update instantly, you can check out the [Github documentation](ht
|
||||
|
||||
You can star or watch this project or follow author to get release notifictions in time.
|
||||
|
||||
## 配置密码 Password
|
||||
|
||||
本项目提供有限的权限控制功能,请在 Vercel 项目控制面板的环境变量页增加名为 `CODE` 的环境变量,值为用英文逗号分隔的自定义密码:
|
||||
|
||||
```
|
||||
code1,code2,code3
|
||||
```
|
||||
|
||||
增加或修改该环境变量后,请**重新部署**项目使改动生效。
|
||||
## 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:
|
||||
|
||||
@ -113,26 +104,21 @@ code1,code2,code3
|
||||
|
||||
After adding or modifying this environment variable, please redeploy the project for the changes to take effect.
|
||||
|
||||
## 环境变量 Environment Variables
|
||||
## Environment Variables
|
||||
> [简体中文 > 如何配置 api key、访问密码、接口代理](./README_CN.md#环境变量)
|
||||
|
||||
### `OPENAI_API_KEY` (required)
|
||||
|
||||
OpanAI 密钥。
|
||||
|
||||
Your openai api key.
|
||||
|
||||
### `CODE` (optional)
|
||||
|
||||
访问密码,可选,可以使用逗号隔开多个密码。
|
||||
|
||||
Access passsword, separated by comma.
|
||||
|
||||
### `BASE_URL` (optional)
|
||||
|
||||
> Default: `api.openai.com`
|
||||
|
||||
OpenAI 接口代理 URL。
|
||||
|
||||
Override openai api request base url.
|
||||
|
||||
### `PROTOCOL` (optional)
|
||||
@ -141,38 +127,32 @@ Override openai api request base url.
|
||||
|
||||
> Values: `http` | `https`
|
||||
|
||||
OpenAI 接口协议。
|
||||
|
||||
Override openai api request protocol.
|
||||
|
||||
## 开发 Development
|
||||
|
||||
点击下方按钮,开始二次开发:
|
||||
## 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)
|
||||
|
||||
在开始写代码之前,需要在项目根目录新建一个 `.env.local` 文件,里面填入环境变量:
|
||||
|
||||
Before starting development, you must create a new `.env.local` file at project root, and place your api key into it:
|
||||
|
||||
```
|
||||
OPENAI_API_KEY=<your api key here>
|
||||
```
|
||||
|
||||
### 本地开发 Local Development
|
||||
|
||||
> 如果你是中国大陆用户,不建议在本地进行开发,除非你能够独立解决 OpenAI API 本地代理问题。
|
||||
|
||||
1. 安装 nodejs 和 yarn,具体细节请询问 ChatGPT;
|
||||
2. 执行 `yarn install && yarn dev` 即可。
|
||||
|
||||
### 本地部署 Local Deployment
|
||||
### Local Development
|
||||
|
||||
```shell
|
||||
bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)
|
||||
# 1. install nodejs and yarn first
|
||||
# 2. config local env vars in `.env.local`
|
||||
# 3. run
|
||||
yarn install
|
||||
yarn dev
|
||||
```
|
||||
|
||||
### 容器部署 Docker Deployment
|
||||
## Deployment
|
||||
> [简体中文 > 如何部署到私人服务器](./README_CN.md#部署)
|
||||
### Docker (Recommended)
|
||||
|
||||
```shell
|
||||
docker pull yidadaa/chatgpt-next-web
|
||||
@ -180,22 +160,27 @@ docker pull yidadaa/chatgpt-next-web
|
||||
docker run -d -p 3000:3000 -e OPENAI_API_KEY="" -e CODE="" yidadaa/chatgpt-next-web
|
||||
```
|
||||
|
||||
## 截图 Screenshots
|
||||
### Shell
|
||||
|
||||
![设置 Settings](./static/settings.png)
|
||||
```shell
|
||||
bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)
|
||||
```
|
||||
## Screenshots
|
||||
|
||||
![更多展示 More](./static/more.png)
|
||||
![Settings](./docs/images/settings.png)
|
||||
|
||||
![More](./docs/images/more.png)
|
||||
|
||||
|
||||
## 鸣谢 Special Thanks
|
||||
### 捐赠者 Sponsor
|
||||
## Special Thanks
|
||||
### Sponsor
|
||||
|
||||
[@mushan0x0](https://github.com/mushan0x0)
|
||||
[@ClarenceDan](https://github.com/ClarenceDan)
|
||||
[@zhangjia](https://github.com/zhangjia)
|
||||
[@hoochanlon](https://github.com/hoochanlon)
|
||||
|
||||
### 贡献者 Contributor
|
||||
### Contributor
|
||||
|
||||
[Contributors](https://github.com/Yidadaa/ChatGPT-Next-Web/graphs/contributors)
|
||||
|
||||
|
151
README_CN.md
Normal file
@ -0,0 +1,151 @@
|
||||
<div align="center">
|
||||
<img src="./static/icon.svg" alt="预览"/>
|
||||
|
||||
<h1 align="center">ChatGPT Next Web</h1>
|
||||
|
||||
一键免费部署你的私人 ChatGPT 网页应用。
|
||||
|
||||
[演示 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)
|
||||
|
||||
[![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)
|
||||
|
||||
![主界面](./static/cover.png)
|
||||
|
||||
</div>
|
||||
|
||||
## 主要功能
|
||||
|
||||
- 在 1 分钟内使用 Vercel **免费一键部署**
|
||||
- 精心设计的 UI,响应式设计,支持深色模式
|
||||
- 极快的首屏加载速度(~100kb)
|
||||
- 海量的内置 prompt 列表,来自[中文](https://github.com/PlexPt/awesome-chatgpt-prompts-zh)和[英文](https://github.com/f/awesome-chatgpt-prompts)
|
||||
- 自动压缩上下文聊天记录,在节省 Token 的同时支持超长对话
|
||||
- 一键导出聊天记录,完整的 Markdown 支持
|
||||
- 拥有自己的域名?好上加好,绑定后即可在任何地方**无障碍**快速访问
|
||||
|
||||
## 开始使用
|
||||
|
||||
1. 准备好你的 [OpenAI API Key](https://platform.openai.com/account/api-keys);
|
||||
2. 点击右侧按钮开始部署:
|
||||
[![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),直接使用 Github 账号登录即可,记得在环境变量页填入 API Key;
|
||||
3. 部署完毕后,即可开始使用;
|
||||
4. (可选)[绑定自定义域名](https://vercel.com/docs/concepts/projects/domains/add-a-domain):Vercel 分配的域名 DNS 在某些区域被污染了,绑定自定义域名即可直连。
|
||||
|
||||
## 保持更新
|
||||
|
||||
如果你按照上述步骤一键部署了自己的项目,可能会发现总是提示“存在更新”的问题,这是由于 Vercel 会默认为你创建一个新项目而不是 fork 本项目,这会导致无法正确地检测更新。
|
||||
推荐你按照下列步骤重新部署:
|
||||
|
||||
- 删除掉原先的 repo;
|
||||
- fork 本项目;
|
||||
- 前往 vercel 控制台,删除掉原先的 project,然后新建 project,选择你刚刚 fork 出来的项目重新进行部署即可;
|
||||
- 在重新部署的过程中,请手动添加名为 `OPENAI_API_KEY` 的环境变量,并填入你的 api key 作为值。
|
||||
|
||||
本项目会持续更新,当你 Fork 项目之后,默认会每天自动同步上游代码,无需额外操作。
|
||||
|
||||
如果你想让手动立即更新,可以查看 [Github 的文档](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork) 了解如何让 fork 的项目与上游代码同步。
|
||||
|
||||
你可以 star/watch 本项目或者 follow 作者来及时获得新功能更新通知。
|
||||
|
||||
## 配置页面访问密码
|
||||
|
||||
> 配置密码后,用户需要在设置页手动填写访问码才可以正常聊天,否则会通过消息提示未授权状态。
|
||||
|
||||
本项目提供有限的权限控制功能,请在 Vercel 项目控制面板的环境变量页增加名为 `CODE` 的环境变量,值为用英文逗号分隔的自定义密码:
|
||||
|
||||
```
|
||||
code1,code2,code3
|
||||
```
|
||||
|
||||
增加或修改该环境变量后,请**重新部署**项目使改动生效。
|
||||
|
||||
## 环境变量
|
||||
> 本项目大多数配置项都通过环境变量来设置。
|
||||
|
||||
### `OPENAI_API_KEY` (必填项)
|
||||
|
||||
OpanAI 密钥,你在 openai 账户页面申请的 api key。
|
||||
|
||||
### `CODE` (可选)
|
||||
|
||||
访问密码,可选,可以使用逗号隔开多个密码。
|
||||
|
||||
**警告**:如果不填写此项,则任何人都可以直接使用你部署后的网站,可能会导致你的 token 被急速消耗完毕,建议填写此选项。
|
||||
|
||||
### `BASE_URL` (可选)
|
||||
|
||||
> Default: `api.openai.com`
|
||||
|
||||
OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填写此选项。
|
||||
|
||||
### `PROTOCOL` (可选)
|
||||
|
||||
> Default: `https`
|
||||
|
||||
> Values: `http` | `https`
|
||||
|
||||
OpenAI 代理接口协议,如果遇到 ssl 证书问题,请尝试通过此选项设置为 http。
|
||||
|
||||
## 开发
|
||||
|
||||
> 强烈不建议在本地进行开发或者部署,由于一些技术原因,导致很难在本地配置好 OpenAI API 代理,除非你能保证可以直。连 OpenAI 服务器
|
||||
|
||||
点击下方按钮,开始二次开发:
|
||||
|
||||
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/Yidadaa/ChatGPT-Next-Web)
|
||||
|
||||
在开始写代码之前,需要在项目根目录新建一个 `.env.local` 文件,里面填入环境变量:
|
||||
|
||||
```
|
||||
OPENAI_API_KEY=<your api key here>
|
||||
```
|
||||
|
||||
### 本地开发
|
||||
|
||||
1. 安装 nodejs 和 yarn,具体细节请询问 ChatGPT;
|
||||
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
|
||||
```
|
||||
|
||||
### 本地部署
|
||||
在控制台运行下方命令:
|
||||
|
||||
```shell
|
||||
bash <(curl -s https://raw.githubusercontent.com/Yidadaa/ChatGPT-Next-Web/main/scripts/setup.sh)
|
||||
```
|
||||
|
||||
|
||||
## 截图 Screenshots
|
||||
|
||||
![设置](./static/settings.png)
|
||||
|
||||
![更多展示](./static/more.png)
|
||||
|
||||
|
||||
## 鸣谢
|
||||
### 捐赠者
|
||||
> 仅列出了部分大额打赏,小额打赏(< 100RMB)人数太多,在此不再列出,敬请谅解。
|
||||
|
||||
[@mushan0x0](https://github.com/mushan0x0)
|
||||
[@ClarenceDan](https://github.com/ClarenceDan)
|
||||
[@zhangjia](https://github.com/zhangjia)
|
||||
[@hoochanlon](https://github.com/hoochanlon)
|
||||
|
||||
### 贡献者
|
||||
|
||||
[见项目贡献者列表](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)
|
@ -53,6 +53,9 @@ export async function POST(req: NextRequest) {
|
||||
return new Response(stream);
|
||||
} catch (error) {
|
||||
console.error("[Chat Stream]", error);
|
||||
return new Response(
|
||||
["```json\n", JSON.stringify(error, null, " "), "\n```"].join(""),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,6 +63,14 @@
|
||||
font-size: 12px;
|
||||
font-weight: bold;
|
||||
margin-bottom: 10px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
||||
.memory-prompt-action {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
|
||||
.memory-prompt-content {
|
||||
|
@ -12,7 +12,14 @@ import BotIcon from "../icons/bot.svg";
|
||||
import AddIcon from "../icons/add.svg";
|
||||
import DeleteIcon from "../icons/delete.svg";
|
||||
|
||||
import { Message, SubmitKey, useChatStore, BOT_HELLO, ROLES } from "../store";
|
||||
import {
|
||||
Message,
|
||||
SubmitKey,
|
||||
useChatStore,
|
||||
BOT_HELLO,
|
||||
ROLES,
|
||||
createMessage,
|
||||
} from "../store";
|
||||
|
||||
import {
|
||||
copyToClipboard,
|
||||
@ -32,11 +39,14 @@ import { IconButton } from "./button";
|
||||
import styles from "./home.module.scss";
|
||||
import chatStyle from "./chat.module.scss";
|
||||
|
||||
import { Modal, showModal, showToast } from "./ui-lib";
|
||||
import { Input, Modal, showModal, showToast } from "./ui-lib";
|
||||
|
||||
const Markdown = dynamic(async () => memo((await import("./markdown")).Markdown), {
|
||||
loading: () => <LoadingIcon />,
|
||||
});
|
||||
const Markdown = dynamic(
|
||||
async () => memo((await import("./markdown")).Markdown),
|
||||
{
|
||||
loading: () => <LoadingIcon />,
|
||||
},
|
||||
);
|
||||
|
||||
const Emoji = dynamic(async () => (await import("emoji-picker-react")).Emoji, {
|
||||
loading: () => <LoadingIcon />,
|
||||
@ -141,6 +151,16 @@ function PromptToast(props: {
|
||||
title={Locale.Context.Edit}
|
||||
onClose={() => props.setShowModal(false)}
|
||||
actions={[
|
||||
<IconButton
|
||||
key="reset"
|
||||
icon={<CopyIcon />}
|
||||
bordered
|
||||
text={Locale.Memory.Reset}
|
||||
onClick={() =>
|
||||
confirm(Locale.Memory.ResetConfirm) &&
|
||||
chatStore.resetSession()
|
||||
}
|
||||
/>,
|
||||
<IconButton
|
||||
key="copy"
|
||||
icon={<CopyIcon />}
|
||||
@ -151,7 +171,6 @@ function PromptToast(props: {
|
||||
]}
|
||||
>
|
||||
<>
|
||||
{" "}
|
||||
<div className={chatStyle["context-prompt"]}>
|
||||
{context.map((c, i) => (
|
||||
<div className={chatStyle["context-prompt-row"]} key={i}>
|
||||
@ -171,17 +190,18 @@ function PromptToast(props: {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<input
|
||||
<Input
|
||||
value={c.content}
|
||||
type="text"
|
||||
className={chatStyle["context-content"]}
|
||||
onChange={(e) =>
|
||||
rows={1}
|
||||
onInput={(e) =>
|
||||
updateContextPrompt(i, {
|
||||
...c,
|
||||
content: e.target.value as any,
|
||||
content: e.currentTarget.value as any,
|
||||
})
|
||||
}
|
||||
></input>
|
||||
/>
|
||||
<IconButton
|
||||
icon={<DeleteIcon />}
|
||||
className={chatStyle["context-delete-button"]}
|
||||
@ -209,8 +229,24 @@ function PromptToast(props: {
|
||||
</div>
|
||||
<div className={chatStyle["memory-prompt"]}>
|
||||
<div className={chatStyle["memory-prompt-title"]}>
|
||||
{Locale.Memory.Title} ({session.lastSummarizeIndex} of{" "}
|
||||
{session.messages.length})
|
||||
<span>
|
||||
{Locale.Memory.Title} ({session.lastSummarizeIndex} of{" "}
|
||||
{session.messages.length})
|
||||
</span>
|
||||
|
||||
<label className={chatStyle["memory-prompt-action"]}>
|
||||
{Locale.Memory.Send}
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={session.sendMemory}
|
||||
onChange={() =>
|
||||
chatStore.updateCurrentSession(
|
||||
(session) =>
|
||||
(session.sendMemory = !session.sendMemory),
|
||||
)
|
||||
}
|
||||
></input>
|
||||
</label>
|
||||
</div>
|
||||
<div className={chatStyle["memory-prompt-content"]}>
|
||||
{session.memoryPrompt || Locale.Memory.EmptyContent}
|
||||
@ -378,8 +414,8 @@ export function Chat(props: {
|
||||
};
|
||||
|
||||
// stop response
|
||||
const onUserStop = (messageIndex: number) => {
|
||||
ControllerPool.stop(sessionIndex, messageIndex);
|
||||
const onUserStop = (messageId: number) => {
|
||||
ControllerPool.stop(sessionIndex, messageId);
|
||||
};
|
||||
|
||||
// check if should send message
|
||||
@ -409,6 +445,9 @@ export function Chat(props: {
|
||||
chatStore
|
||||
.onUserInput(messages[i].content)
|
||||
.then(() => setIsLoading(false));
|
||||
chatStore.updateCurrentSession((session) =>
|
||||
session.messages.splice(i, 2),
|
||||
);
|
||||
inputRef.current?.focus();
|
||||
return;
|
||||
}
|
||||
@ -433,9 +472,10 @@ export function Chat(props: {
|
||||
isLoading
|
||||
? [
|
||||
{
|
||||
role: "assistant",
|
||||
content: "……",
|
||||
date: new Date().toLocaleString(),
|
||||
...createMessage({
|
||||
role: "assistant",
|
||||
content: "……",
|
||||
}),
|
||||
preview: true,
|
||||
},
|
||||
]
|
||||
@ -445,9 +485,10 @@ export function Chat(props: {
|
||||
userInput.length > 0 && config.sendPreviewBubble
|
||||
? [
|
||||
{
|
||||
role: "user",
|
||||
content: userInput,
|
||||
date: new Date().toLocaleString(),
|
||||
...createMessage({
|
||||
role: "user",
|
||||
content: userInput,
|
||||
}),
|
||||
preview: true,
|
||||
},
|
||||
]
|
||||
@ -460,6 +501,7 @@ export function Chat(props: {
|
||||
useEffect(() => {
|
||||
if (props.sideBarShowing && isMobileScreen()) return;
|
||||
inputRef.current?.focus();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return (
|
||||
@ -563,7 +605,7 @@ export function Chat(props: {
|
||||
{message.streaming ? (
|
||||
<div
|
||||
className={styles["chat-message-top-action"]}
|
||||
onClick={() => onUserStop(i)}
|
||||
onClick={() => onUserStop(message.id ?? i)}
|
||||
>
|
||||
{Locale.Chat.Actions.Stop}
|
||||
</div>
|
||||
|
@ -96,26 +96,18 @@ export function Settings(props: { closeSettings: () => void }) {
|
||||
|
||||
const [usage, setUsage] = useState<{
|
||||
used?: number;
|
||||
subscription?: number;
|
||||
}>();
|
||||
const [loadingUsage, setLoadingUsage] = useState(false);
|
||||
function checkUsage() {
|
||||
setLoadingUsage(true);
|
||||
requestUsage()
|
||||
.then((res) =>
|
||||
setUsage({
|
||||
used: res,
|
||||
}),
|
||||
)
|
||||
.then((res) => setUsage(res))
|
||||
.finally(() => {
|
||||
setLoadingUsage(false);
|
||||
});
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
checkUpdate();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
const accessStore = useAccessStore();
|
||||
const enabledAccessControl = useMemo(
|
||||
() => accessStore.enabledAccessControl(),
|
||||
@ -127,12 +119,13 @@ export function Settings(props: { closeSettings: () => void }) {
|
||||
const builtinCount = SearchService.count.builtin;
|
||||
const customCount = promptStore.prompts.size ?? 0;
|
||||
|
||||
const showUsage = accessStore.token !== "";
|
||||
const showUsage = !!accessStore.token || !!accessStore.accessCode;
|
||||
|
||||
useEffect(() => {
|
||||
if (showUsage) {
|
||||
checkUsage();
|
||||
}
|
||||
}, [showUsage]);
|
||||
checkUpdate();
|
||||
showUsage && checkUsage();
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ErrorBoundary>
|
||||
@ -392,7 +385,10 @@ export function Settings(props: { closeSettings: () => void }) {
|
||||
showUsage
|
||||
? loadingUsage
|
||||
? Locale.Settings.Usage.IsChecking
|
||||
: Locale.Settings.Usage.SubTitle(usage?.used ?? "[?]")
|
||||
: Locale.Settings.Usage.SubTitle(
|
||||
usage?.used ?? "[?]",
|
||||
usage?.subscription ?? "[?]",
|
||||
)
|
||||
: Locale.Settings.Usage.NoAccess
|
||||
}
|
||||
>
|
||||
|
@ -141,6 +141,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
.input {
|
||||
border: var(--border-in-light);
|
||||
border-radius: 10px;
|
||||
padding: 10px;
|
||||
font-family: inherit;
|
||||
background-color: var(--white);
|
||||
color: var(--black);
|
||||
resize: none;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 600px) {
|
||||
.modal-container {
|
||||
width: 90vw;
|
||||
|
@ -2,6 +2,7 @@ import styles from "./ui-lib.module.scss";
|
||||
import LoadingIcon from "../icons/three-dots.svg";
|
||||
import CloseIcon from "../icons/close.svg";
|
||||
import { createRoot } from "react-dom/client";
|
||||
import React from "react";
|
||||
|
||||
export function Popover(props: {
|
||||
children: JSX.Element;
|
||||
@ -140,3 +141,17 @@ export function showToast(content: string, delay = 3000) {
|
||||
|
||||
root.render(<Toast content={content} />);
|
||||
}
|
||||
|
||||
export type InputProps = React.HTMLProps<HTMLTextAreaElement> & {
|
||||
autoHeight?: boolean;
|
||||
rows?: number;
|
||||
};
|
||||
|
||||
export function Input(props: InputProps) {
|
||||
return (
|
||||
<textarea
|
||||
{...props}
|
||||
className={`${styles["input"]} ${props.className}`}
|
||||
></textarea>
|
||||
);
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ export const OWNER = "Yidadaa";
|
||||
export const REPO = "ChatGPT-Next-Web";
|
||||
export const REPO_URL = `https://github.com/${OWNER}/${REPO}`;
|
||||
export const ISSUE_URL = `https://github.com/${OWNER}/${REPO}/issues`;
|
||||
export const UPDATE_URL = `${REPO_URL}#%E4%BF%9D%E6%8C%81%E6%9B%B4%E6%96%B0-keep-updated`;
|
||||
export const UPDATE_URL = `${REPO_URL}#keep-updated`;
|
||||
export const FETCH_COMMIT_URL = `https://api.github.com/repos/${OWNER}/${REPO}/commits?per_page=1`;
|
||||
export const FETCH_TAG_URL = `https://api.github.com/repos/${OWNER}/${REPO}/tags?per_page=1`;
|
||||
|
@ -3,7 +3,7 @@ import { SubmitKey } from "../store/app";
|
||||
const cn = {
|
||||
WIP: "该功能仍在开发中……",
|
||||
Error: {
|
||||
Unauthorized: "现在是未授权状态,请在设置页输入授权码。",
|
||||
Unauthorized: "现在是未授权状态,请在设置页输入访问密码。",
|
||||
},
|
||||
ChatItem: {
|
||||
ChatItemCount: (count: number) => `${count} 条对话`,
|
||||
@ -39,7 +39,10 @@ const cn = {
|
||||
Memory: {
|
||||
Title: "历史记忆",
|
||||
EmptyContent: "尚未记忆",
|
||||
Copy: "全部复制",
|
||||
Send: "发送记忆",
|
||||
Copy: "复制记忆",
|
||||
Reset: "重置对话",
|
||||
ResetConfirm: "重置后将清空当前对话记录以及历史记忆,确认重置?",
|
||||
},
|
||||
Home: {
|
||||
NewChat: "新的聊天",
|
||||
@ -101,22 +104,22 @@ const cn = {
|
||||
},
|
||||
Token: {
|
||||
Title: "API Key",
|
||||
SubTitle: "使用自己的 Key 可绕过授权访问限制",
|
||||
SubTitle: "使用自己的 Key 可绕过密码访问限制",
|
||||
Placeholder: "OpenAI API Key",
|
||||
},
|
||||
Usage: {
|
||||
Title: "账户余额",
|
||||
SubTitle(used: any) {
|
||||
return `本月已使用 $${used}`;
|
||||
Title: "余额查询",
|
||||
SubTitle(used: any, total: any) {
|
||||
return `本月已使用 $${used},订阅总额 $${total}`;
|
||||
},
|
||||
IsChecking: "正在检查…",
|
||||
Check: "重新检查",
|
||||
NoAccess: "输入API Key查看余额",
|
||||
NoAccess: "输入 API Key 或访问密码查看余额",
|
||||
},
|
||||
AccessCode: {
|
||||
Title: "授权码",
|
||||
Title: "访问密码",
|
||||
SubTitle: "现在是未授权访问状态",
|
||||
Placeholder: "请输入授权码",
|
||||
Placeholder: "请输入访问密码",
|
||||
},
|
||||
Model: "模型 (model)",
|
||||
Temperature: {
|
||||
|
@ -41,7 +41,11 @@ const en: LocaleType = {
|
||||
Memory: {
|
||||
Title: "Memory Prompt",
|
||||
EmptyContent: "Nothing yet.",
|
||||
Copy: "Copy All",
|
||||
Send: "Send Memory",
|
||||
Copy: "Copy Memory",
|
||||
Reset: "Reset Session",
|
||||
ResetConfirm:
|
||||
"Resetting will clear the current conversation history and historical memory. Are you sure you want to reset?",
|
||||
},
|
||||
Home: {
|
||||
NewChat: "New Chat",
|
||||
@ -108,8 +112,8 @@ const en: LocaleType = {
|
||||
},
|
||||
Usage: {
|
||||
Title: "Account Balance",
|
||||
SubTitle(used: any) {
|
||||
return `Used this month $${used}`;
|
||||
SubTitle(used: any, total: any) {
|
||||
return `Used this month $${used}, subscription $${total}`;
|
||||
},
|
||||
IsChecking: "Checking...",
|
||||
Check: "Check Again",
|
||||
|
@ -42,6 +42,10 @@ const es: LocaleType = {
|
||||
Title: "Historial de memoria",
|
||||
EmptyContent: "Aún no hay nada.",
|
||||
Copy: "Copiar todo",
|
||||
Send: "Send Memory",
|
||||
Reset: "Reset Session",
|
||||
ResetConfirm:
|
||||
"Resetting will clear the current conversation history and historical memory. Are you sure you want to reset?",
|
||||
},
|
||||
Home: {
|
||||
NewChat: "Nuevo chat",
|
||||
@ -108,8 +112,8 @@ const es: LocaleType = {
|
||||
},
|
||||
Usage: {
|
||||
Title: "Saldo de la cuenta",
|
||||
SubTitle(used: any) {
|
||||
return `Usado $${used}`;
|
||||
SubTitle(used: any, total: any) {
|
||||
return `Usado $${used}, subscription $${total}`;
|
||||
},
|
||||
IsChecking: "Comprobando...",
|
||||
Check: "Comprobar de nuevo",
|
||||
|
@ -42,6 +42,10 @@ const it: LocaleType = {
|
||||
Title: "Prompt di memoria",
|
||||
EmptyContent: "Vuoto.",
|
||||
Copy: "Copia tutto",
|
||||
Send: "Send Memory",
|
||||
Reset: "Reset Session",
|
||||
ResetConfirm:
|
||||
"Resetting will clear the current conversation history and historical memory. Are you sure you want to reset?",
|
||||
},
|
||||
Home: {
|
||||
NewChat: "Nuova Chat",
|
||||
@ -109,8 +113,8 @@ const it: LocaleType = {
|
||||
},
|
||||
Usage: {
|
||||
Title: "Bilancio Account",
|
||||
SubTitle(used: any) {
|
||||
return `Usato in questo mese $${used}`;
|
||||
SubTitle(used: any, total: any) {
|
||||
return `Usato in questo mese $${used}, subscription $${total}`;
|
||||
},
|
||||
IsChecking: "Controllando...",
|
||||
Check: "Controlla ancora",
|
||||
|
@ -41,6 +41,9 @@ const tw: LocaleType = {
|
||||
Title: "上下文記憶 Prompt",
|
||||
EmptyContent: "尚未記憶",
|
||||
Copy: "複製全部",
|
||||
Send: "發送記憶",
|
||||
Reset: "重置對話",
|
||||
ResetConfirm: "重置後將清空當前對話記錄以及歷史記憶,確認重置?",
|
||||
},
|
||||
Home: {
|
||||
NewChat: "新的對話",
|
||||
@ -106,8 +109,8 @@ const tw: LocaleType = {
|
||||
},
|
||||
Usage: {
|
||||
Title: "帳戶餘額",
|
||||
SubTitle(used: any) {
|
||||
return `本月已使用 $${used}`;
|
||||
SubTitle(used: any, total: any) {
|
||||
return `本月已使用 $${used},订阅总额 $${total}`;
|
||||
},
|
||||
IsChecking: "正在檢查…",
|
||||
Check: "重新檢查",
|
||||
|
@ -1,6 +1,5 @@
|
||||
import type { ChatRequest, ChatReponse } from "./api/openai/typing";
|
||||
import { Message, ModelConfig, useAccessStore } from "./store";
|
||||
import Locale from "./locales";
|
||||
import { Message, ModelConfig, useAccessStore, useChatStore } from "./store";
|
||||
import { showToast } from "./components/ui-lib";
|
||||
|
||||
const TIME_OUT_MS = 30000;
|
||||
@ -21,10 +20,12 @@ const makeRequestParam = (
|
||||
sendMessages = sendMessages.filter((m) => m.role !== "assistant");
|
||||
}
|
||||
|
||||
const modelConfig = useChatStore.getState().config.modelConfig;
|
||||
|
||||
return {
|
||||
model: "gpt-3.5-turbo",
|
||||
messages: sendMessages,
|
||||
stream: options?.stream,
|
||||
...modelConfig,
|
||||
};
|
||||
};
|
||||
|
||||
@ -81,31 +82,39 @@ export async function requestUsage() {
|
||||
const startOfMonth = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const startDate = formatDate(startOfMonth);
|
||||
const endDate = formatDate(now);
|
||||
const res = await requestOpenaiClient(
|
||||
`dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`,
|
||||
)(null, "GET");
|
||||
|
||||
try {
|
||||
const response = (await res.json()) as {
|
||||
total_usage: number;
|
||||
error?: {
|
||||
type: string;
|
||||
message: string;
|
||||
};
|
||||
const [used, subs] = await Promise.all([
|
||||
requestOpenaiClient(
|
||||
`dashboard/billing/usage?start_date=${startDate}&end_date=${endDate}`,
|
||||
)(null, "GET"),
|
||||
requestOpenaiClient("dashboard/billing/subscription")(null, "GET"),
|
||||
]);
|
||||
|
||||
const response = (await used.json()) as {
|
||||
total_usage?: number;
|
||||
error?: {
|
||||
type: string;
|
||||
message: string;
|
||||
};
|
||||
};
|
||||
|
||||
if (response.error && response.error.type) {
|
||||
showToast(response.error.message);
|
||||
return;
|
||||
}
|
||||
const total = (await subs.json()) as {
|
||||
hard_limit_usd?: number;
|
||||
};
|
||||
|
||||
if (response.total_usage) {
|
||||
response.total_usage = Math.round(response.total_usage) / 100;
|
||||
}
|
||||
return response.total_usage;
|
||||
} catch (error) {
|
||||
console.error("[Request usage] ", error, res.body);
|
||||
if (response.error && response.error.type) {
|
||||
showToast(response.error.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.total_usage) {
|
||||
response.total_usage = Math.round(response.total_usage) / 100;
|
||||
}
|
||||
|
||||
return {
|
||||
used: response.total_usage,
|
||||
subscription: total.hard_limit_usd,
|
||||
};
|
||||
}
|
||||
|
||||
export async function requestChatStream(
|
||||
@ -204,23 +213,22 @@ export const ControllerPool = {
|
||||
|
||||
addController(
|
||||
sessionIndex: number,
|
||||
messageIndex: number,
|
||||
messageId: number,
|
||||
controller: AbortController,
|
||||
) {
|
||||
const key = this.key(sessionIndex, messageIndex);
|
||||
const key = this.key(sessionIndex, messageId);
|
||||
this.controllers[key] = controller;
|
||||
return key;
|
||||
},
|
||||
|
||||
stop(sessionIndex: number, messageIndex: number) {
|
||||
const key = this.key(sessionIndex, messageIndex);
|
||||
stop(sessionIndex: number, messageId: number) {
|
||||
const key = this.key(sessionIndex, messageId);
|
||||
const controller = this.controllers[key];
|
||||
console.log(controller);
|
||||
controller?.abort();
|
||||
},
|
||||
|
||||
remove(sessionIndex: number, messageIndex: number) {
|
||||
const key = this.key(sessionIndex, messageIndex);
|
||||
remove(sessionIndex: number, messageId: number) {
|
||||
const key = this.key(sessionIndex, messageId);
|
||||
delete this.controllers[key];
|
||||
},
|
||||
|
||||
|
@ -15,8 +15,19 @@ export type Message = ChatCompletionResponseMessage & {
|
||||
date: string;
|
||||
streaming?: boolean;
|
||||
isError?: boolean;
|
||||
id?: number;
|
||||
};
|
||||
|
||||
export function createMessage(override: Partial<Message>): Message {
|
||||
return {
|
||||
id: Date.now(),
|
||||
date: new Date().toLocaleString(),
|
||||
role: "user",
|
||||
content: "",
|
||||
...override,
|
||||
};
|
||||
}
|
||||
|
||||
export enum SubmitKey {
|
||||
Enter = "Enter",
|
||||
CtrlEnter = "Ctrl + Enter",
|
||||
@ -149,6 +160,7 @@ export interface ChatStat {
|
||||
export interface ChatSession {
|
||||
id: number;
|
||||
topic: string;
|
||||
sendMemory: boolean;
|
||||
memoryPrompt: string;
|
||||
context: Message[];
|
||||
messages: Message[];
|
||||
@ -158,11 +170,10 @@ export interface ChatSession {
|
||||
}
|
||||
|
||||
const DEFAULT_TOPIC = Locale.Store.DefaultTopic;
|
||||
export const BOT_HELLO: Message = {
|
||||
export const BOT_HELLO: Message = createMessage({
|
||||
role: "assistant",
|
||||
content: Locale.Store.BotHello,
|
||||
date: "",
|
||||
};
|
||||
});
|
||||
|
||||
function createEmptySession(): ChatSession {
|
||||
const createDate = new Date().toLocaleString();
|
||||
@ -170,6 +181,7 @@ function createEmptySession(): ChatSession {
|
||||
return {
|
||||
id: Date.now(),
|
||||
topic: DEFAULT_TOPIC,
|
||||
sendMemory: true,
|
||||
memoryPrompt: "",
|
||||
context: [],
|
||||
messages: [],
|
||||
@ -202,6 +214,7 @@ interface ChatStore {
|
||||
messageIndex: number,
|
||||
updater: (message?: Message) => void,
|
||||
) => void;
|
||||
resetSession: () => void;
|
||||
getMessagesWithMemory: () => Message[];
|
||||
getMemoryPrompt: () => Message;
|
||||
|
||||
@ -308,18 +321,15 @@ export const useChatStore = create<ChatStore>()(
|
||||
},
|
||||
|
||||
async onUserInput(content) {
|
||||
const userMessage: Message = {
|
||||
const userMessage: Message = createMessage({
|
||||
role: "user",
|
||||
content,
|
||||
date: new Date().toLocaleString(),
|
||||
};
|
||||
});
|
||||
|
||||
const botMessage: Message = {
|
||||
content: "",
|
||||
const botMessage: Message = createMessage({
|
||||
role: "assistant",
|
||||
date: new Date().toLocaleString(),
|
||||
streaming: true,
|
||||
};
|
||||
});
|
||||
|
||||
// get recent messages
|
||||
const recentMessages = get().getMessagesWithMemory();
|
||||
@ -342,7 +352,10 @@ export const useChatStore = create<ChatStore>()(
|
||||
botMessage.streaming = false;
|
||||
botMessage.content = content;
|
||||
get().onNewMessage(botMessage);
|
||||
ControllerPool.remove(sessionIndex, messageIndex);
|
||||
ControllerPool.remove(
|
||||
sessionIndex,
|
||||
botMessage.id ?? messageIndex,
|
||||
);
|
||||
} else {
|
||||
botMessage.content = content;
|
||||
set(() => ({}));
|
||||
@ -358,13 +371,13 @@ export const useChatStore = create<ChatStore>()(
|
||||
userMessage.isError = true;
|
||||
botMessage.isError = true;
|
||||
set(() => ({}));
|
||||
ControllerPool.remove(sessionIndex, messageIndex);
|
||||
ControllerPool.remove(sessionIndex, botMessage.id ?? messageIndex);
|
||||
},
|
||||
onController(controller) {
|
||||
// collect controller for stop/retry
|
||||
ControllerPool.addController(
|
||||
sessionIndex,
|
||||
messageIndex,
|
||||
botMessage.id ?? messageIndex,
|
||||
controller,
|
||||
);
|
||||
},
|
||||
@ -391,7 +404,11 @@ export const useChatStore = create<ChatStore>()(
|
||||
|
||||
const context = session.context.slice();
|
||||
|
||||
if (session.memoryPrompt && session.memoryPrompt.length > 0) {
|
||||
if (
|
||||
session.sendMemory &&
|
||||
session.memoryPrompt &&
|
||||
session.memoryPrompt.length > 0
|
||||
) {
|
||||
const memoryPrompt = get().getMemoryPrompt();
|
||||
context.push(memoryPrompt);
|
||||
}
|
||||
@ -415,6 +432,13 @@ export const useChatStore = create<ChatStore>()(
|
||||
set(() => ({ sessions }));
|
||||
},
|
||||
|
||||
resetSession() {
|
||||
get().updateCurrentSession((session) => {
|
||||
session.messages = [];
|
||||
session.memoryPrompt = "";
|
||||
});
|
||||
},
|
||||
|
||||
summarizeSession() {
|
||||
const session = get().currentSession();
|
||||
|
||||
@ -427,7 +451,8 @@ export const useChatStore = create<ChatStore>()(
|
||||
requestWithPrompt(session.messages, Locale.Store.Prompt.Topic).then(
|
||||
(res) => {
|
||||
get().updateCurrentSession(
|
||||
(session) => (session.topic = trimTopic(res)),
|
||||
(session) =>
|
||||
(session.topic = res ? trimTopic(res) : DEFAULT_TOPIC),
|
||||
);
|
||||
},
|
||||
);
|
||||
@ -506,7 +531,7 @@ export const useChatStore = create<ChatStore>()(
|
||||
}),
|
||||
{
|
||||
name: LOCAL_KEY,
|
||||
version: 1.1,
|
||||
version: 1.2,
|
||||
migrate(persistedState, version) {
|
||||
const state = persistedState as ChatStore;
|
||||
|
||||
@ -514,6 +539,10 @@ export const useChatStore = create<ChatStore>()(
|
||||
state.sessions.forEach((s) => (s.context = []));
|
||||
}
|
||||
|
||||
if (version < 1.2) {
|
||||
state.sessions.forEach((s) => (s.sendMemory = true));
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
},
|
||||
|
@ -126,6 +126,10 @@ select {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
label {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
input {
|
||||
text-align: center;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ import { showToast } from "./components/ui-lib";
|
||||
import Locale from "./locales";
|
||||
|
||||
export function trimTopic(topic: string) {
|
||||
return topic.replace(/[,。!?、,.!?]*$/, "");
|
||||
return topic.replace(/[,。!?”“"、,.!?]*$/, "");
|
||||
}
|
||||
|
||||
export async function copyToClipboard(text: string) {
|
||||
|
52
docs/faq-cn.md
Normal file
@ -0,0 +1,52 @@
|
||||
# 常见问题
|
||||
> We are sorry that there is currently no English version of the FAQ. English users can use translation tools to access this document. We look forward to receiving your PR for an English version of the documentation.
|
||||
|
||||
<a name="change-env-vars" />
|
||||
|
||||
## 如何修改 Vercel 环境变量
|
||||
- 进入 vercel 的控制台页面;
|
||||
- 选中你的 chatgpt next web 项目;
|
||||
- 点击页面头部的 Settings 选项;
|
||||
- 找到侧边栏的 Environment Variables 选项;
|
||||
- 修改对应的值即可。
|
||||
|
||||
<a name="no-stream" />
|
||||
|
||||
## 为什么我部署的版本没有流式响应
|
||||
> 相关讨论:[#386](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/386)
|
||||
|
||||
如果你使用 ngnix 反向代理,需要在配置文件中增加下列代码:
|
||||
```
|
||||
# 不缓存,支持流式输出
|
||||
proxy_cache off; # 关闭缓存
|
||||
proxy_buffering off; # 关闭代理缓冲
|
||||
chunked_transfer_encoding on; # 开启分块传输编码
|
||||
tcp_nopush on; # 开启TCP NOPUSH选项,禁止Nagle算法
|
||||
tcp_nodelay on; # 开启TCP NODELAY选项,禁止延迟ACK算法
|
||||
keepalive_timeout 300; # 设定keep-alive超时时间为65秒
|
||||
```
|
||||
|
||||
如果你是在 netlify 部署,此问题依然等待解决,请耐心等待。
|
||||
|
||||
<a name="error" />
|
||||
|
||||
## 为什么会一直提示“出错了,稍后重试吧”
|
||||
原因可能有很多,请依次排查:
|
||||
- 请先检查你的代码版本是否为最新版本,更新到最新版本后重试;
|
||||
- 请检查 api key 是否设置正确,环境变量名称必须为全大写加下划线;
|
||||
- 请检查 api key 是否可用;
|
||||
- 如果经历了上述步骤依旧无法确定问题,请在 issue 区提交一个新 issue,并附上 vercel 的 runtime log 或者 docker 运行时的 log。
|
||||
|
||||
<a name="docker-update" />
|
||||
|
||||
## 为什么 Docker 部署版本一直提示更新
|
||||
Docker 版本相当于稳定版,latest Docker 总是与 latest release version 一致,目前我们的发版频率是一到两天发一次,所以 Docker 版本会总是落后最新的提交一到两天,这在预期内。
|
||||
|
||||
|
||||
<a name="random-response" />
|
||||
|
||||
## 为什么 ChatGPT 的回复会乱码
|
||||
设置界面 - 模型设置项中,有一项为 `temperature`,如果此值大于 1,那么就有可能造成回复乱码,将其调回 1 以内即可。
|
||||
|
||||
## 如何使用 Azure OpenAI 接口
|
||||
请参考:[#371](https://github.com/Yidadaa/ChatGPT-Next-Web/issues/371)
|
BIN
docs/images/cover.png
Normal file
After Width: | Height: | Size: 376 KiB |
Before Width: | Height: | Size: 4.2 KiB After Width: | Height: | Size: 4.2 KiB |
BIN
docs/images/more.png
Normal file
After Width: | Height: | Size: 278 KiB |
BIN
docs/images/settings.png
Normal file
After Width: | Height: | Size: 154 KiB |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "chatgpt-next-web",
|
||||
"version": "1.1",
|
||||
"version": "1.9.3",
|
||||
"private": false,
|
||||
"license": "Anti 996",
|
||||
"scripts": {
|
||||
|
@ -61,4 +61,5 @@ read -p "Enter CODE: " CODE
|
||||
read -p "Enter PORT: " PORT
|
||||
|
||||
# Build and run the project using the environment variables
|
||||
OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn build && OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn start
|
||||
OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn build
|
||||
OPENAI_API_KEY=$OPENAI_API_KEY CODE=$CODE PORT=$PORT yarn start
|
||||
|
BIN
static/cover.png
Before Width: | Height: | Size: 234 KiB |
BIN
static/more.png
Before Width: | Height: | Size: 218 KiB |
Before Width: | Height: | Size: 88 KiB |