Compare commits
184 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eff787a2b7 | ||
|
|
8616526136 | ||
|
|
32e3963390 | ||
|
|
7d52e6dd1e | ||
|
|
ba41015df8 | ||
|
|
f084460d1c | ||
|
|
a4ef23d603 | ||
|
|
d3daa654a7 | ||
|
|
9576edf26f | ||
|
|
5b74ac9cc6 | ||
|
|
444e2ec2e8 | ||
|
|
60b7874f65 | ||
|
|
07cac12dac | ||
|
|
4f3bfd1d4a | ||
|
|
451a456f58 | ||
|
|
5fe1e20e4a | ||
|
|
54381ed2e2 | ||
|
|
ffd4da91cf | ||
|
|
a2ffa3cb3a | ||
|
|
ecc2afd164 | ||
|
|
45cbfbf002 | ||
|
|
a689406b28 | ||
|
|
2ff82b1249 | ||
|
|
8e1b4edc91 | ||
|
|
dea74e242e | ||
|
|
162f561523 | ||
|
|
50e672e79b | ||
|
|
c8fa086565 | ||
|
|
cd91cb1afd | ||
|
|
e6db6a58f0 | ||
|
|
ab08df9823 | ||
|
|
8619ac4667 | ||
|
|
de34d97529 | ||
|
|
0cdacfdb2f | ||
|
|
976713490a | ||
|
|
002a57704f | ||
|
|
9dd3655b81 | ||
|
|
d1de182451 | ||
|
|
dee84e9307 | ||
|
|
0fdf75eba0 | ||
|
|
2293969070 | ||
|
|
f7f87e266f | ||
|
|
f95af40ab8 | ||
|
|
20d6135658 | ||
|
|
f19998d59b | ||
|
|
21cf1bdd9e | ||
|
|
f234aebaec | ||
|
|
32ebbec8ad | ||
|
|
42e320fe35 | ||
|
|
94e23bb916 | ||
|
|
21fb4f817c | ||
|
|
2c509c329f | ||
|
|
4769c31d09 | ||
|
|
89712aada7 | ||
|
|
3e9db49aad | ||
|
|
2dcd292dd4 | ||
|
|
90f6989445 | ||
|
|
1406292405 | ||
|
|
628187f5c3 | ||
|
|
cc91e95eed | ||
|
|
abbdcf9c51 | ||
|
|
b6fd9ae766 | ||
|
|
1e2f893ef6 | ||
|
|
10058f151c | ||
|
|
09359c3c46 | ||
|
|
ba83856173 | ||
|
|
b84f7e4c72 | ||
|
|
c0f8e4316e | ||
|
|
bf5c0cdf04 | ||
|
|
66cecb6049 | ||
|
|
808ae600c2 | ||
|
|
f40048fb08 | ||
|
|
ac9536ab87 | ||
|
|
938c91f635 | ||
|
|
4ab9f709de | ||
|
|
cb90d81c69 | ||
|
|
fda6c6bb6a | ||
|
|
6216d84ecd | ||
|
|
ea887ad755 | ||
|
|
c98a2a3cb8 | ||
|
|
06f41c3758 | ||
|
|
3f4cb5c900 | ||
|
|
405aeaa2a5 | ||
|
|
fd28468778 | ||
|
|
4128d319ed | ||
|
|
4a06b3943c | ||
|
|
77cdcb7798 | ||
|
|
ee542a01f7 | ||
|
|
30372c2e70 | ||
|
|
6646695849 | ||
|
|
e9db25a970 | ||
|
|
63f4d7d77c | ||
|
|
20255ddce4 | ||
|
|
bbd8ff773b | ||
|
|
c8518b7789 | ||
|
|
bf015d35f7 | ||
|
|
eab39b7f88 | ||
|
|
981c036542 | ||
|
|
91f51b6338 | ||
|
|
26de5359ef | ||
|
|
0423b87530 | ||
|
|
58464b2cee | ||
|
|
e23e1df3ce | ||
|
|
2c3bc77eb2 | ||
|
|
52b43868eb | ||
|
|
7930ec5dab | ||
|
|
7835740159 | ||
|
|
c8745f2e21 | ||
|
|
0b8b58f85c | ||
|
|
c09a4f6c75 | ||
|
|
d9761ed0e5 | ||
|
|
cb8e2cf814 | ||
|
|
f73aa5f9e1 | ||
|
|
c617205a8c | ||
|
|
79eeb51537 | ||
|
|
b2977d8c44 | ||
|
|
8dab963628 | ||
|
|
79dd6c5e18 | ||
|
|
da75ca944c | ||
|
|
4458e744cc | ||
|
|
d2ae2c4f54 | ||
|
|
cf8e2dd7b6 | ||
|
|
701ef0e6e1 | ||
|
|
de34af8747 | ||
|
|
33c02cfe10 | ||
|
|
b03f804e35 | ||
|
|
b6e5c59a9c | ||
|
|
797cc7461b | ||
|
|
58547d1b58 | ||
|
|
c933a851f4 | ||
|
|
86fcbbff0b | ||
|
|
5d1f8519c2 | ||
|
|
3c21068150 | ||
|
|
cd03a71ef1 | ||
|
|
1d74717beb | ||
|
|
e35abb1c98 | ||
|
|
b4b0f65158 | ||
|
|
910c19b02e | ||
|
|
32049fbf18 | ||
|
|
817a4842ac | ||
|
|
0cd120ec5b | ||
|
|
007763f7d7 | ||
|
|
3debaec4b2 | ||
|
|
35f353c1f7 | ||
|
|
3ac6746930 | ||
|
|
9b556e4833 | ||
|
|
071283c007 | ||
|
|
854261ef86 | ||
|
|
633e9ad8e2 | ||
|
|
47dd6c9801 | ||
|
|
0eb9df6d31 | ||
|
|
8bfbe6f7df | ||
|
|
43e8635e7f | ||
|
|
b7542c70cb | ||
|
|
b594ec5de1 | ||
|
|
9a9b154040 | ||
|
|
12681b1a05 | ||
|
|
9f4f6304c7 | ||
|
|
93c63d9195 | ||
|
|
361494d444 | ||
|
|
2f69cfd10b | ||
|
|
0086f17df4 | ||
|
|
befad1cbe1 | ||
|
|
6cafc07e0d | ||
|
|
feb167e2da | ||
|
|
847623e22a | ||
|
|
dd522eb404 | ||
|
|
73c9ac4d8f | ||
|
|
727562f495 | ||
|
|
d7464642a7 | ||
|
|
951636869b | ||
|
|
39f718ef16 | ||
|
|
72df35c929 | ||
|
|
cf7a56a015 | ||
|
|
5ca1b4557a | ||
|
|
11544ff24b | ||
|
|
f910b5f8a4 | ||
|
|
98e75c0c5c | ||
|
|
06fd5a861c | ||
|
|
fc0d2073aa | ||
|
|
2c816afbd2 | ||
|
|
1bf2399a45 | ||
|
|
ddec57f562 | ||
|
|
63af4a8e97 |
3
.commitlintrc.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": ["@commitlint/config-conventional"]
|
||||
}
|
||||
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
||||
**/node_modules
|
||||
*/node_modules
|
||||
node_modules
|
||||
Dockerfile
|
||||
.*
|
||||
*/.*
|
||||
5
.env
@@ -1,5 +0,0 @@
|
||||
# OpenAI API Key
|
||||
OPENAI_API_KEY='xxxx'
|
||||
|
||||
# Glob API URL
|
||||
VITE_GLOB_API_URL='http://localhost:3002'
|
||||
4
.env.example
Normal file
@@ -0,0 +1,4 @@
|
||||
# Glob API URL
|
||||
VITE_GLOB_API_URL=/api
|
||||
|
||||
VITE_APP_API_BASE_URL=http://localhost:3002/
|
||||
@@ -1 +0,0 @@
|
||||
components.d.ts
|
||||
41
.github/workflows/build_docker.yml
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
name: build_docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
release:
|
||||
types: [created] # 表示在创建新的 Release 时触发
|
||||
|
||||
jobs:
|
||||
build_docker:
|
||||
name: Build docker
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- run: |
|
||||
echo "本次构建的版本为:${GITHUB_REF_NAME} (但是这个变量目前上下文中无法获取到)"
|
||||
echo 本次构建的版本为:${{ github.ref_name }}
|
||||
env
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v4
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
platforms: linux/amd64,linux/arm64
|
||||
tags: |
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/chatgpt-web:${{ github.ref_name }}
|
||||
${{ secrets.DOCKERHUB_USERNAME }}/chatgpt-web:latest
|
||||
47
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Setup
|
||||
run: npm i -g @antfu/ni
|
||||
|
||||
- name: Install
|
||||
run: nci
|
||||
|
||||
- name: Lint
|
||||
run: nr lint:fix
|
||||
|
||||
typecheck:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Set node
|
||||
uses: actions/setup-node@v3
|
||||
with:
|
||||
node-version: 18.x
|
||||
|
||||
- name: Setup
|
||||
run: npm i -g @antfu/ni
|
||||
|
||||
- name: Install
|
||||
run: nci
|
||||
|
||||
- name: Typecheck
|
||||
run: nr type-check
|
||||
4
.gitignore
vendored
@@ -27,3 +27,7 @@ coverage
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# Environment variables files
|
||||
/service/.env
|
||||
/.env
|
||||
|
||||
4
.husky/commit-msg
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npx --no -- commitlint --edit
|
||||
4
.husky/pre-commit
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env sh
|
||||
. "$(dirname -- "$0")/_/husky.sh"
|
||||
|
||||
npx lint-staged
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"semi": false,
|
||||
"singleQuote": true
|
||||
}
|
||||
32
.vscode/settings.json
vendored
@@ -1,4 +1,6 @@
|
||||
{
|
||||
"prettier.enable": false,
|
||||
"editor.formatOnSave": false,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
},
|
||||
@@ -21,16 +23,42 @@
|
||||
"axios",
|
||||
"bumpp",
|
||||
"chatgpt",
|
||||
"chenzhaoyu",
|
||||
"commitlint",
|
||||
"davinci",
|
||||
"dockerhub",
|
||||
"esno",
|
||||
"GPTAPI",
|
||||
"highlightjs",
|
||||
"hljs",
|
||||
"iconify",
|
||||
"katex",
|
||||
"katexmath",
|
||||
"linkify",
|
||||
"logprobs",
|
||||
"mdhljs",
|
||||
"nodata",
|
||||
"OPENAI",
|
||||
"pinia",
|
||||
"Popconfirm",
|
||||
"rushstack",
|
||||
"Sider",
|
||||
"tailwindcss",
|
||||
"traptitech",
|
||||
"tsup",
|
||||
"Typecheck",
|
||||
"unplugin",
|
||||
"VITE",
|
||||
"vueuse"
|
||||
]
|
||||
"vueuse",
|
||||
"Zhao"
|
||||
],
|
||||
"i18n-ally.enabledParsers": [
|
||||
"ts"
|
||||
],
|
||||
"i18n-ally.sortKeys": true,
|
||||
"i18n-ally.keepFulfilled": true,
|
||||
"i18n-ally.localesPaths": [
|
||||
"src/locales"
|
||||
],
|
||||
"i18n-ally.keystyle": "nested"
|
||||
}
|
||||
|
||||
378
CHANGELOG.md
@@ -1,3 +1,381 @@
|
||||
## v2.10.1
|
||||
|
||||
`2023-03-09`
|
||||
|
||||
注意:删除了 `.env` 文件改用 `.env.example` 代替,如果是手动部署的同学现在需要手动创建 `.env` 文件并从 `.env.example` 中复制需要的变量,并且 `.env` 文件现在会在 `Git` 提交中被忽略,原因如下:
|
||||
|
||||
- 在项目中添加 `.env` 从一开始就是个错误的示范
|
||||
- 如果是 `Fork` 项目进行修改测试总是会被 `Git` 修改提示给打扰
|
||||
- 感谢 [yi-ge](https://github.com/Chanzhaoyu/chatgpt-web/pull/395) 的提醒和修改
|
||||
|
||||
|
||||
这两天开始,官方已经开始对第三方代理进行了拉闸, `accessToken` 即将或已经开始可能会不可使用。异常 `API` 使用也开始封号,封号缘由不明,如果出现使用 `API` 提示错误,请查看后端控制台信息,或留意邮箱。
|
||||
|
||||
## Feature
|
||||
- 感谢 [CornerSkyless](https://github.com/Chanzhaoyu/chatgpt-web/pull/393) 添加是否发送上下文开关功能
|
||||
|
||||
## Enhancement
|
||||
- 感谢 [nagaame](https://github.com/Chanzhaoyu/chatgpt-web/pull/415) 优化`docker`打包镜像文件过大的问题
|
||||
- 感谢 [xieccc](https://github.com/Chanzhaoyu/chatgpt-web/pull/404) 新增 `API` 模型配置变量 `OPENAI_API_MODEL`
|
||||
- 感谢 [acongee](https://github.com/Chanzhaoyu/chatgpt-web/pull/394) 优化输出时滚动条问题
|
||||
|
||||
## BugFix
|
||||
- 感谢 [CornerSkyless](https://github.com/Chanzhaoyu/chatgpt-web/pull/392) 修复导出图片会丢失头像的问题
|
||||
- 修复深色模式导出图片的样式问题
|
||||
|
||||
|
||||
|
||||
## v2.10.0
|
||||
|
||||
`2023-03-07`
|
||||
|
||||
- 老规矩,手动部署的同学需要删除 `node_modules` 安装包重新安装降低出错概率,其他部署不受影响,但是可能会有缓存问题。
|
||||
- 虽然说了更新放缓,但是 `issues` 不看, `PR` 不改我睡不着,我的邮箱从每天早上`8`点到凌晨`12`永远在滴滴滴,所以求求各位,超时的`issues`自己关闭下哈,我真的需要缓冲一下。
|
||||
- 演示图片请看最后
|
||||
|
||||
## Feature
|
||||
- 添加权限功能,用法:`service/.env` 中的 `AUTH_SECRET_KEY` 变量添加密码
|
||||
- 感谢 [PeterDaveHello](https://github.com/Chanzhaoyu/chatgpt-web/pull/348) 添加「繁体中文」翻译
|
||||
- 感谢 [GermMC](https://github.com/Chanzhaoyu/chatgpt-web/pull/369) 添加聊天记录导入、导出、清空的功能
|
||||
- 感谢 [CornerSkyless](https://github.com/Chanzhaoyu/chatgpt-web/pull/374) 添加会话保存为本地图片的功能
|
||||
|
||||
|
||||
## Enhancement
|
||||
- 感谢 [CornerSkyless](https://github.com/Chanzhaoyu/chatgpt-web/pull/363) 添加 `ctrl+enter` 发送消息
|
||||
- 现在新消息只有在结束了之后才滚动到底部,而不是之前的强制性
|
||||
- 优化部分代码
|
||||
|
||||
## BugFix
|
||||
- 转义状态码前端显示,防止直接暴露 `key`(我可能需要更多的状态码补充)
|
||||
|
||||
## Other
|
||||
- 更新依赖到最新
|
||||
|
||||
## 演示
|
||||
> 不是界面最新效果,有美化改动
|
||||
|
||||
权限
|
||||
|
||||

|
||||
|
||||
聊天记录导出
|
||||
|
||||

|
||||
|
||||
保存图片到本地
|
||||
|
||||

|
||||
|
||||
## v2.9.3
|
||||
|
||||
`2023-03-06`
|
||||
|
||||
## Enhancement
|
||||
- 感谢 [ChandlerVer5](https://github.com/Chanzhaoyu/chatgpt-web/pull/305) 使用 `markdown-it` 替换 `marked`,解决代码块闪烁的问题
|
||||
- 感谢 [shansing](https://github.com/Chanzhaoyu/chatgpt-web/pull/277) 改善文档
|
||||
- 感谢 [nalf3in](https://github.com/Chanzhaoyu/chatgpt-web/pull/293) 添加英文翻译
|
||||
|
||||
## BugFix
|
||||
- 感谢[sepcnt ](https://github.com/Chanzhaoyu/chatgpt-web/pull/279) 修复切换记录时编辑状态未关闭的问题
|
||||
- 修复复制代码的兼容性报错问题
|
||||
- 修复部分优化小问题
|
||||
|
||||
## v2.9.2
|
||||
|
||||
`2023-03-04`
|
||||
|
||||
手动部署的同学,务必删除根目录和`service`中的`node_modules`重新安装依赖,降低出现问题的概率,自动部署的不需要做改动。
|
||||
|
||||
### Feature
|
||||
- 感谢 [hyln9](https://github.com/Chanzhaoyu/chatgpt-web/pull/247) 添加对渲染 `LaTex` 数学公式的支持
|
||||
- 感谢 [ottocsb](https://github.com/Chanzhaoyu/chatgpt-web/pull/227) 添加支持 `webAPP` (苹果添加到主页书签访问)支持
|
||||
- 添加 `OPENAI_API_BASE_URL` 可选环境变量[#249]
|
||||
## Enhancement
|
||||
- 优化在高分屏上主题内容的最大宽度[#257]
|
||||
- 现在文字按单词截断[#215][#225]
|
||||
### BugFix
|
||||
- 修复动态生成时代码块不能被复制的问题[#251][#260]
|
||||
- 修复 `iOS` 移动端输入框不会被键盘顶起的问题[#256]
|
||||
- 修复控制台渲染警告
|
||||
## Other
|
||||
- 更新依赖至最新
|
||||
- 修改 `README` 内容
|
||||
|
||||
## v2.9.1
|
||||
|
||||
`2023-03-02`
|
||||
|
||||
### Feature
|
||||
- 代码块添加当前代码语言显示和复制功能[#197][#196]
|
||||
- 完善多语言,现在可以切换中英文显示
|
||||
|
||||
## Enhancement
|
||||
- 由[Zo3i](https://github.com/Chanzhaoyu/chatgpt-web/pull/187) 完善 `docker-compose` 部署文档
|
||||
|
||||
### BugFix
|
||||
- 由 [ottocsb](https://github.com/Chanzhaoyu/chatgpt-web/pull/200) 修复头像修改不同步的问题
|
||||
## Other
|
||||
- 更新依赖至最新
|
||||
- 修改 `README` 内容
|
||||
## v2.9.0
|
||||
|
||||
`2023-03-02`
|
||||
|
||||
### Feature
|
||||
- 现在能复制带格式的消息文本
|
||||
- 新设计的设定页面,可以自定义姓名、描述、头像(链接方式)
|
||||
- 新增`403`和`404`页面以便扩展
|
||||
|
||||
## Enhancement
|
||||
- 更新 `chatgpt` 使 `ChatGPTAPI` 支持 `gpt-3.5-turbo-0301`(默认)
|
||||
- 取消了前端超时限制设定
|
||||
|
||||
## v2.8.3
|
||||
|
||||
`2023-03-01`
|
||||
|
||||
### Feature
|
||||
- 消息已输出内容不会因为中断而消失[#167]
|
||||
- 添加复制消息按钮[#133]
|
||||
|
||||
### Other
|
||||
- `README` 添加声明内容
|
||||
|
||||
## v2.8.2
|
||||
|
||||
`2023-02-28`
|
||||
### Enhancement
|
||||
- 代码主题调整为 `One Dark - light|dark` 适配深色模式
|
||||
### BugFix
|
||||
- 修复普通文本代码渲染和深色模式下的问题[#139][#154]
|
||||
|
||||
## v2.8.1
|
||||
|
||||
`2023-02-27`
|
||||
|
||||
### BugFix
|
||||
- 修复 `API` 版本不是 `Markdown` 时,普通 `HTML` 代码会被渲染的问题 [#146]
|
||||
|
||||
## v2.8.0
|
||||
|
||||
`2023-02-27`
|
||||
|
||||
- 感谢 [puppywang](https://github.com/Chanzhaoyu/chatgpt-web/commit/628187f5c3348bda0d0518f90699a86525d19018) 修复了 `2.7.0` 版本中关于流输出数据的问题(使用 `nginx` 需要自行配置 `octet-stream` 相关内容)
|
||||
|
||||
- 关于为什么使用 `octet-stream` 而不是 `sse`,是因为更好的兼容之前的模式。
|
||||
|
||||
- 建议更新到此版本获得比较完整的体验
|
||||
|
||||
### Enhancement
|
||||
- 优化了部份代码和类型提示
|
||||
- 输入框添加换行提示
|
||||
- 移动端输入框现在回车为换行,而不是直接提交
|
||||
- 移动端双击标题返回顶部,箭头返回底部
|
||||
|
||||
### BugFix
|
||||
- 流输出数据下的问题[#122]
|
||||
- 修复了 `API Key` 下部份代码不换行的问题
|
||||
- 修复移动端深色模式部份样式问题[#123][#126]
|
||||
- 修复主题模式图标不一致的问题[#126]
|
||||
|
||||
## v2.7.3
|
||||
|
||||
`2023-02-25`
|
||||
|
||||
### Feature
|
||||
- 适配系统深色模式 [#118](https://github.com/Chanzhaoyu/chatgpt-web/issues/103)
|
||||
### BugFix
|
||||
- 修复用户消息能被渲染为 `HTML` 问题 [#117](https://github.com/Chanzhaoyu/chatgpt-web/issues/117)
|
||||
|
||||
## v2.7.2
|
||||
|
||||
`2023-02-24`
|
||||
### Enhancement
|
||||
- 消息使用 [github-markdown-css](https://www.npmjs.com/package/github-markdown-css) 进行美化,现在支持全语法
|
||||
- 移除测试无用函数
|
||||
|
||||
## v2.7.1
|
||||
|
||||
`2023-02-23`
|
||||
|
||||
因为消息流在 `accessToken` 中存在解析失败和消息不完整等一系列的问题,调整回正常消息形式
|
||||
|
||||
### Feature
|
||||
- 现在可以中断请求过长没有答复的消息
|
||||
- 现在可以删除单条消息
|
||||
- 设置中显示当前版本信息
|
||||
|
||||
### BugFix
|
||||
- 回退 `2.7.0` 的消息不稳定的问题
|
||||
|
||||
## v2.7.0
|
||||
|
||||
`2023-02-23`
|
||||
|
||||
### Feature
|
||||
- 使用消息流返回信息,反应更迅速
|
||||
|
||||
### Enhancement
|
||||
- 样式的一点小改动
|
||||
|
||||
## v2.6.2
|
||||
|
||||
`2023-02-22`
|
||||
### BugFix
|
||||
- 还原修改代理导致的异常问题
|
||||
|
||||
## v2.6.1
|
||||
|
||||
`2023-02-22`
|
||||
|
||||
### Feature
|
||||
- 新增 `Railway` 部署模版
|
||||
|
||||
### BugFix
|
||||
- 手动打包 `Proxy` 问题
|
||||
|
||||
## v2.6.0
|
||||
|
||||
`2023-02-21`
|
||||
### Feature
|
||||
- 新增对 `网页 accessToken` 调用 `ChatGPT`,更智能不过不太稳定 [#51](https://github.com/Chanzhaoyu/chatgpt-web/issues/51)
|
||||
- 前端页面设置按钮显示查看当前后端服务配置
|
||||
|
||||
### Enhancement
|
||||
- 新增 `TIMEOUT_MS` 环境变量设定后端超时时常(单位:毫秒)[#62](https://github.com/Chanzhaoyu/chatgpt-web/issues/62)
|
||||
|
||||
## v2.5.2
|
||||
|
||||
`2023-02-21`
|
||||
### Feature
|
||||
- 增加对 `markdown` 格式的支持 [Demo](https://github.com/Chanzhaoyu/chatgpt-web/pull/77)
|
||||
### BugFix
|
||||
- 重载会话时滚动条保持
|
||||
|
||||
## v2.5.1
|
||||
|
||||
`2023-02-21`
|
||||
|
||||
### Enhancement
|
||||
- 调整路由模式为 `hash`
|
||||
- 调整新增会话添加到
|
||||
- 调整移动端样式
|
||||
|
||||
|
||||
## v2.5.0
|
||||
|
||||
`2023-02-20`
|
||||
|
||||
### Feature
|
||||
- 会话 `loading` 现在显示为光标动画
|
||||
- 会话现在可以再次生成回复
|
||||
- 会话异常可以再次进行请求
|
||||
- 所有删除选项添加确认操作
|
||||
|
||||
### Enhancement
|
||||
- 调整 `chat` 为路由页面而不是组件形式
|
||||
- 更新依赖至最新
|
||||
- 调整移动端体验
|
||||
|
||||
### BugFix
|
||||
- 修复移动端左侧菜单显示不完整的问题
|
||||
|
||||
## v2.4.1
|
||||
|
||||
`2023-02-18`
|
||||
|
||||
### Enhancement
|
||||
- 调整部份移动端上的样式
|
||||
- 输入框支持换行
|
||||
|
||||
## v2.4.0
|
||||
|
||||
`2023-02-17`
|
||||
|
||||
### Feature
|
||||
- 响应式支持移动端
|
||||
### Enhancement
|
||||
- 修改部份描述错误
|
||||
|
||||
## v2.3.3
|
||||
|
||||
`2023-02-16`
|
||||
|
||||
### Feature
|
||||
- 添加 `README` 部份说明和贡献列表
|
||||
- 添加 `docker` 镜像
|
||||
- 添加 `GitHub Action` 自动化构建
|
||||
|
||||
### BugFix
|
||||
- 回退依赖更新导致的 [Eslint 报错](https://github.com/eslint/eslint/issues/16896)
|
||||
|
||||
## v2.3.2
|
||||
|
||||
`2023-02-16`
|
||||
|
||||
### Enhancement
|
||||
- 更新依赖至最新
|
||||
- 优化部份内容
|
||||
|
||||
## v2.3.1
|
||||
|
||||
`2023-02-15`
|
||||
|
||||
### BugFix
|
||||
- 修复多会话状态下一些意想不到的问题
|
||||
|
||||
## v2.3.0
|
||||
|
||||
`2023-02-15`
|
||||
### Feature
|
||||
- 代码类型信息高亮显示
|
||||
- 支持 `node ^16` 版本
|
||||
- 移动端响应式初步支持
|
||||
- `vite` 中 `proxy` 代理
|
||||
|
||||
### Enhancement
|
||||
- 调整超时处理范围
|
||||
|
||||
### BugFix
|
||||
- 修复取消请求错误提示会添加到信息中
|
||||
- 修复部份情况下提交请求不可用
|
||||
- 修复侧边栏宽度变化闪烁的问题
|
||||
|
||||
## v2.2.0
|
||||
|
||||
`2023-02-14`
|
||||
### Feature
|
||||
- 会话和上下文本地储存
|
||||
- 侧边栏本地储存
|
||||
|
||||
## v2.1.0
|
||||
|
||||
`2023-02-14`
|
||||
### Enhancement
|
||||
- 更新依赖至最新
|
||||
- 联想功能移动至前端提交,后端只做转发
|
||||
|
||||
### BugFix
|
||||
- 修复部份项目检测有关 `Bug`
|
||||
- 修复清除上下文按钮失效
|
||||
|
||||
## v2.0.0
|
||||
|
||||
`2023-02-13`
|
||||
### Refactor
|
||||
重构并优化大部分内容
|
||||
|
||||
## v1.0.5
|
||||
|
||||
`2023-02-12`
|
||||
|
||||
### Enhancement
|
||||
- 输入框焦点,连续提交
|
||||
|
||||
### BugFix
|
||||
- 修复信息框样式问题
|
||||
- 修复中文输入法提交问题
|
||||
|
||||
## v1.0.4
|
||||
|
||||
`2023-02-11`
|
||||
|
||||
49
CONTRIBUTING.en.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# Contribution Guide
|
||||
Thank you for your valuable time. Your contributions will make this project better! Before submitting a contribution, please take some time to read the getting started guide below.
|
||||
|
||||
## Semantic Versioning
|
||||
This project follows semantic versioning. We release patch versions for important bug fixes, minor versions for new features or non-important changes, and major versions for significant and incompatible changes.
|
||||
|
||||
Each major change will be recorded in the `changelog`.
|
||||
|
||||
## Submitting Pull Request
|
||||
1. Fork [this repository](https://github.com/Chanzhaoyu/chatgpt-web) and create a branch from `main`. For new feature implementations, submit a pull request to the `feature` branch. For other changes, submit to the `main` branch.
|
||||
2. Install the `pnpm` tool using `npm install pnpm -g`.
|
||||
3. Install the `Eslint` plugin for `VSCode`, or enable `eslint` functionality for other editors such as `WebStorm`.
|
||||
4. Execute `pnpm bootstrap` in the root directory.
|
||||
5. Execute `pnpm install` in the `/service/` directory.
|
||||
6. Make changes to the codebase. If applicable, ensure that appropriate testing has been done.
|
||||
7. Execute `pnpm lint:fix` in the root directory to perform a code formatting check.
|
||||
8. Execute `pnpm type-check` in the root directory to perform a type check.
|
||||
9. Submit a git commit, following the [Commit Guidelines](#commit-guidelines).
|
||||
10. Submit a `pull request`. If there is a corresponding `issue`, please link it using the [linking-a-pull-request-to-an-issue keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword).
|
||||
|
||||
## Commit Guidelines
|
||||
|
||||
Commit messages should follow the [conventional-changelog standard](https://www.conventionalcommits.org/en/v1.0.0/):
|
||||
|
||||
```bash
|
||||
<type>[optional scope]: <description>
|
||||
|
||||
[optional body]
|
||||
|
||||
[optional footer]
|
||||
```
|
||||
|
||||
### Commit Types
|
||||
|
||||
The following is a list of commit types:
|
||||
|
||||
- feat: New feature or functionality
|
||||
- fix: Bug fix
|
||||
- docs: Documentation update
|
||||
- style: Code style or component style update
|
||||
- refactor: Code refactoring, no new features or bug fixes introduced
|
||||
- perf: Performance optimization
|
||||
- test: Unit test
|
||||
- chore: Other commits that do not modify src or test files
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./license)
|
||||
49
CONTRIBUTING.md
Normal file
@@ -0,0 +1,49 @@
|
||||
# 贡献指南
|
||||
感谢你的宝贵时间。你的贡献将使这个项目变得更好!在提交贡献之前,请务必花点时间阅读下面的入门指南。
|
||||
|
||||
## 语义化版本
|
||||
该项目遵循语义化版本。我们对重要的漏洞修复发布修订号,对新特性或不重要的变更发布次版本号,对重大且不兼容的变更发布主版本号。
|
||||
|
||||
每个重大更改都将记录在 `changelog` 中。
|
||||
|
||||
## 提交 Pull Request
|
||||
1. Fork [此仓库](https://github.com/Chanzhaoyu/chatgpt-web),从 `main` 创建分支。新功能实现请发 pull request 到 `feature` 分支。其他更改发到 `main` 分支。
|
||||
2. 使用 `npm install pnpm -g` 安装 `pnpm` 工具。
|
||||
3. `vscode` 安装了 `Eslint` 插件,其它编辑器如 `webStorm` 打开了 `eslint` 功能。
|
||||
4. 根目录下执行 `pnpm bootstrap`。
|
||||
5. `/service/` 目录下执行 `pnpm install`。
|
||||
6. 对代码库进行更改。如果适用的话,请确保进行了相应的测试。
|
||||
7. 请在根目录下执行 `pnpm lint:fix` 进行代码格式检查。
|
||||
8. 请在根目录下执行 `pnpm type-check` 进行类型检查。
|
||||
9. 提交 git commit, 请同时遵守 [Commit 规范](#commit-指南)
|
||||
10. 提交 `pull request`, 如果有对应的 `issue`,请进行[关联](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword)。
|
||||
|
||||
## Commit 指南
|
||||
|
||||
Commit messages 请遵循[conventional-changelog 标准](https://www.conventionalcommits.org/en/v1.0.0/):
|
||||
|
||||
```bash
|
||||
<类型>[可选 范围]: <描述>
|
||||
|
||||
[可选 正文]
|
||||
|
||||
[可选 脚注]
|
||||
```
|
||||
|
||||
### Commit 类型
|
||||
|
||||
以下是 commit 类型列表:
|
||||
|
||||
- feat: 新特性或功能
|
||||
- fix: 缺陷修复
|
||||
- docs: 文档更新
|
||||
- style: 代码风格或者组件样式更新
|
||||
- refactor: 代码重构,不引入新功能和缺陷修复
|
||||
- perf: 性能优化
|
||||
- test: 单元测试
|
||||
- chore: 其他不修改 src 或测试文件的提交
|
||||
|
||||
|
||||
## License
|
||||
|
||||
[MIT](./license)
|
||||
28
Dockerfile
Normal file
@@ -0,0 +1,28 @@
|
||||
# build front-end
|
||||
FROM node:lts-alpine AS builder
|
||||
|
||||
COPY ./ /app
|
||||
WORKDIR /app
|
||||
|
||||
RUN apk add --no-cache git \
|
||||
&& npm install pnpm -g \
|
||||
&& pnpm install \
|
||||
&& pnpm run build \
|
||||
&& rm -rf /root/.npm /root/.pnpm-store /usr/local/share/.cache /tmp/*
|
||||
|
||||
# service
|
||||
FROM node:lts-alpine
|
||||
|
||||
COPY /service /app
|
||||
COPY --from=builder /app/dist /app/public
|
||||
|
||||
WORKDIR /app
|
||||
RUN apk add --no-cache git \
|
||||
&& npm install pnpm -g \
|
||||
&& pnpm install --only=production \
|
||||
&& rm -rf /root/.npm /root/.pnpm-store /usr/local/share/.cache /tmp/*
|
||||
|
||||
|
||||
EXPOSE 3002
|
||||
|
||||
CMD ["pnpm", "run", "start"]
|
||||
327
README.en.md
Normal file
@@ -0,0 +1,327 @@
|
||||
# ChatGPT Web
|
||||
|
||||
<div style="font-size: 1.5rem;">
|
||||
<a href="./README.md">中文</a> |
|
||||
<a href="./README.en.md">English</a>
|
||||
</div>
|
||||
</br>
|
||||
|
||||
> Disclaimer: This project is only released on GitHub, under the MIT License, free and for open-source learning purposes. There will be no account selling, paid services, discussion groups, or forums. Beware of fraud.
|
||||
|
||||

|
||||

|
||||
|
||||
- [ChatGPT Web](#chatgpt-web)
|
||||
- [Introduction](#introduction)
|
||||
- [Roadmap](#roadmap)
|
||||
- [Prerequisites](#prerequisites)
|
||||
- [Node](#node)
|
||||
- [PNPM](#pnpm)
|
||||
- [Fill in the Keys](#fill-in-the-keys)
|
||||
- [Install Dependencies](#install-dependencies)
|
||||
- [Backend](#backend)
|
||||
- [Frontend](#frontend)
|
||||
- [Run in Test Environment](#run-in-test-environment)
|
||||
- [Backend Service](#backend-service)
|
||||
- [Frontend Webpage](#frontend-webpage)
|
||||
- [Packaging](#packaging)
|
||||
- [Using Docker](#using-docker)
|
||||
- [Docker Parameter Example](#docker-parameter-example)
|
||||
- [Docker Build \& Run](#docker-build--run)
|
||||
- [Docker Compose](#docker-compose)
|
||||
- [Deployment with Railway](#deployment-with-railway)
|
||||
- [Railway Environment Variables](#railway-environment-variables)
|
||||
- [Manual packaging](#manual-packaging)
|
||||
- [Backend service](#backend-service-1)
|
||||
- [Frontend webpage](#frontend-webpage-1)
|
||||
- [Frequently Asked Questions](#frequently-asked-questions)
|
||||
- [Contributing](#contributing)
|
||||
- [Sponsorship](#sponsorship)
|
||||
- [License](#license)
|
||||
|
||||
## Introduction
|
||||
|
||||
Supports dual models, provides two unofficial `ChatGPT API` methods:
|
||||
|
||||
| Method | Free? | Reliability | Quality |
|
||||
| --------------------------------------------- | ------ | ----------- | ------- |
|
||||
| `ChatGPTAPI(gpt-3.5-turbo-0301)` | No | Reliable | Relatively clumsy |
|
||||
| `ChatGPTUnofficialProxyAPI(Web accessToken)` | Yes | Relatively unreliable | Smart |
|
||||
|
||||
Comparison:
|
||||
1. `ChatGPTAPI` uses `gpt-3.5-turbo-0301` to simulate `ChatGPT` through the official `OpenAI` completion `API` (the most reliable method, but it is not free and does not use models specifically tuned for chat).
|
||||
2. `ChatGPTUnofficialProxyAPI` accesses `ChatGPT`'s backend `API` via an unofficial proxy server to bypass `Cloudflare` (uses the real `ChatGPT`, is very lightweight, but depends on third-party servers and has rate limits).
|
||||
|
||||
[Details](https://github.com/Chanzhaoyu/chatgpt-web/issues/138)
|
||||
|
||||
Switching Methods:
|
||||
1. Go to the `service/.env.example` file and copy the contents to the `service/.env` file.
|
||||
2. For `OpenAI API Key`, fill in the `OPENAI_API_KEY` field [(Get apiKey)](https://platform.openai.com/overview).
|
||||
3. For `Web API`, fill in the `OPENAI_ACCESS_TOKEN` field [(Get accessToken)](https://chat.openai.com/api/auth/session).
|
||||
4. When both are present, `OpenAI API Key` takes precedence.
|
||||
|
||||
Reverse Proxy:
|
||||
|
||||
Available when using `ChatGPTUnofficialProxyAPI`.[Details](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)
|
||||
|
||||
```shell
|
||||
# service/.env
|
||||
API_REVERSE_PROXY=
|
||||
```
|
||||
|
||||
Environment Variables:
|
||||
|
||||
For all parameter variables, check [here](#docker-parameter-example) or see:
|
||||
|
||||
```
|
||||
/service/.env
|
||||
```
|
||||
|
||||
## Roadmap
|
||||
[✓] Dual models
|
||||
|
||||
[✓] Multiple session storage and context logic
|
||||
|
||||
[✓] Formatting and beautifying code-like message types
|
||||
|
||||
[✓] Access rights control
|
||||
|
||||
[✓] Data import and export
|
||||
|
||||
[✓] Save message to local image
|
||||
|
||||
[✓] Multilingual interface
|
||||
|
||||
[✓] Interface themes
|
||||
|
||||
[✗] More...
|
||||
|
||||
## Prerequisites
|
||||
|
||||
### Node
|
||||
|
||||
`node` requires version `^16 || ^18` (`node >= 14` requires installation of [fetch polyfill](https://github.com/developit/unfetch#usage-as-a-polyfill)), and multiple local `node` versions can be managed using [nvm](https://github.com/nvm-sh/nvm).
|
||||
|
||||
```shell
|
||||
node -v
|
||||
```
|
||||
|
||||
### PNPM
|
||||
If you have not installed `pnpm` before:
|
||||
```shell
|
||||
npm install pnpm -g
|
||||
```
|
||||
|
||||
### Fill in the Keys
|
||||
|
||||
Get `Openai Api Key` or `accessToken` and fill in the local environment variables [jump](#introduction)
|
||||
|
||||
```
|
||||
# service/.env file
|
||||
|
||||
# OpenAI API Key - https://platform.openai.com/overview
|
||||
OPENAI_API_KEY=
|
||||
|
||||
# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
|
||||
OPENAI_ACCESS_TOKEN=
|
||||
```
|
||||
|
||||
## Install Dependencies
|
||||
|
||||
> To make it easier for `backend developers` to understand, we did not use the front-end `workspace` mode, but stored it in different folders. If you only need to do secondary development of the front-end page, delete the `service` folder.
|
||||
|
||||
### Backend
|
||||
|
||||
Enter the `/service` folder and run the following command
|
||||
|
||||
```shell
|
||||
pnpm install
|
||||
```
|
||||
|
||||
### Frontend
|
||||
Run the following command in the root directory
|
||||
```shell
|
||||
pnpm bootstrap
|
||||
```
|
||||
|
||||
## Run in Test Environment
|
||||
### Backend Service
|
||||
|
||||
Enter the `/service` folder and run the following command
|
||||
|
||||
```shell
|
||||
pnpm start
|
||||
```
|
||||
|
||||
### Frontend Webpage
|
||||
Run the following command in the root directory
|
||||
```shell
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
## Packaging
|
||||
|
||||
### Using Docker
|
||||
|
||||
#### Docker Parameter Example
|
||||
|
||||
- `OPENAI_API_KEY` one of two
|
||||
- `OPENAI_ACCESS_TOKEN` one of two, `OPENAI_API_KEY` takes precedence when both are present
|
||||
- `OPENAI_API_BASE_URL` optional, available when `OPENAI_API_KEY` is set
|
||||
- `OPENAI_API_MODEL` optional, available when `OPENAI_API_KEY` is set
|
||||
- `API_REVERSE_PROXY` optional, available when `OPENAI_ACCESS_TOKEN` is set [Reference](#introduction)
|
||||
- `AUTH_SECRET_KEY` Access Password,optional
|
||||
- `TIMEOUT_MS` timeout, in milliseconds, optional
|
||||
- `SOCKS_PROXY_HOST` optional, effective with SOCKS_PROXY_PORT
|
||||
- `SOCKS_PROXY_PORT` optional, effective with SOCKS_PROXY_HOST
|
||||
|
||||

|
||||
|
||||
#### Docker Build & Run
|
||||
|
||||
```bash
|
||||
docker build -t chatgpt-web .
|
||||
|
||||
# foreground operation
|
||||
docker run --name chatgpt-web --rm -it -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||
|
||||
# background operation
|
||||
docker run --name chatgpt-web -d -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||
|
||||
# running address
|
||||
http://localhost:3002/
|
||||
```
|
||||
|
||||
#### Docker Compose
|
||||
|
||||
[Hub Address](https://hub.docker.com/repository/docker/chenzhaoyu94/chatgpt-web/general)
|
||||
|
||||
```yml
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
app:
|
||||
image: chenzhaoyu94/chatgpt-web # always use latest, pull the tag image again when updating
|
||||
ports:
|
||||
- 3002:3002
|
||||
environment:
|
||||
# one of two
|
||||
OPENAI_API_KEY: xxxxxx
|
||||
# one of two
|
||||
OPENAI_ACCESS_TOKEN: xxxxxx
|
||||
# api interface url, optional, available when OPENAI_API_KEY is set
|
||||
OPENAI_API_BASE_URL: xxxx
|
||||
# api model, optional, available when OPENAI_API_KEY is set
|
||||
OPENAI_API_MODEL: xxxx
|
||||
# reverse proxy, optional
|
||||
API_REVERSE_PROXY: xxx
|
||||
# access password,optional
|
||||
AUTH_SECRET_KEY: xxx
|
||||
# timeout, in milliseconds, optional
|
||||
TIMEOUT_MS: 60000
|
||||
# socks proxy, optional, effective with SOCKS_PROXY_PORT
|
||||
SOCKS_PROXY_HOST: xxxx
|
||||
# socks proxy port, optional, effective with SOCKS_PROXY_HOST
|
||||
SOCKS_PROXY_PORT: xxxx
|
||||
```
|
||||
The `OPENAI_API_BASE_URL` is optional and only used when setting the `OPENAI_API_KEY`.
|
||||
The `OPENAI_API_MODEL` is optional and only used when setting the `OPENAI_API_KEY`.
|
||||
|
||||
### Deployment with Railway
|
||||
|
||||
[](https://railway.app/new/template/yytmgc)
|
||||
|
||||
#### Railway Environment Variables
|
||||
|
||||
| Environment Variable | Required | Description |
|
||||
| -------------------- | -------- | ------------------------------------------------------------------------------------------------- |
|
||||
| `PORT` | Required | Default: `3002` |
|
||||
| `AUTH_SECRET_KEY` | Optional | access password |
|
||||
| `TIMEOUT_MS` | Optional | Timeout in milliseconds |
|
||||
| `OPENAI_API_KEY` | Optional | Required for `OpenAI API`. `apiKey` can be obtained from [here](https://platform.openai.com/overview). |
|
||||
| `OPENAI_ACCESS_TOKEN`| Optional | Required for `Web API`. `accessToken` can be obtained from [here](https://chat.openai.com/api/auth/session).|
|
||||
| `OPENAI_API_BASE_URL` | Optional, only for `OpenAI API` | API endpoint. |
|
||||
| `OPENAI_API_MODEL` | Optional, only for `OpenAI API` | API model. |
|
||||
| `API_REVERSE_PROXY` | Optional, only for `Web API` | Reverse proxy address for `Web API`. [Details](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) |
|
||||
| `SOCKS_PROXY_HOST` | Optional, effective with `SOCKS_PROXY_PORT` | Socks proxy. |
|
||||
| `SOCKS_PROXY_PORT` | Optional, effective with `SOCKS_PROXY_HOST` | Socks proxy port. |
|
||||
|
||||
> Note: Changing environment variables in Railway will cause re-deployment.
|
||||
|
||||
### Manual packaging
|
||||
|
||||
#### Backend service
|
||||
|
||||
> If you don't need the `node` interface of this project, you can skip the following steps.
|
||||
|
||||
Copy the `service` folder to a server that has a `node` service environment.
|
||||
|
||||
```shell
|
||||
# Install
|
||||
pnpm install
|
||||
|
||||
# Build
|
||||
pnpm build
|
||||
|
||||
# Run
|
||||
pnpm prod
|
||||
```
|
||||
|
||||
PS: You can also run `pnpm start` directly on the server without packaging.
|
||||
|
||||
#### Frontend webpage
|
||||
|
||||
1. Refer to the root directory `.env.example` file content to create `.env` file, modify `VITE_APP_API_BASE_URL` in `.env` at the root directory to your actual backend interface address.
|
||||
2. Run the following command in the root directory and then copy the files in the `dist` folder to the root directory of your website service.
|
||||
|
||||
[Reference information](https://cn.vitejs.dev/guide/static-deploy.html#building-the-app)
|
||||
|
||||
```shell
|
||||
pnpm build
|
||||
```
|
||||
|
||||
## Frequently Asked Questions
|
||||
|
||||
Q: Why does Git always report an error when committing?
|
||||
|
||||
A: Because there is submission information verification, please follow the [Commit Guidelines](./CONTRIBUTING.en.md).
|
||||
|
||||
Q: Where to change the request interface if only the frontend page is used?
|
||||
|
||||
A: The `VITE_GLOB_API_URL` field in the `.env` file at the root directory.
|
||||
|
||||
Q: All red when saving the file?
|
||||
|
||||
A: For `vscode`, please install the recommended plug-in of the project or manually install the `Eslint` plug-in.
|
||||
|
||||
Q: Why doesn't the frontend have a typewriter effect?
|
||||
|
||||
A: One possible reason is that after Nginx reverse proxying, buffering is turned on, and Nginx will try to buffer a certain amount of data from the backend before sending it to the browser. Please try adding `proxy_buffering off;` after the reverse proxy parameter and then reloading Nginx. Other web server configurations are similar.
|
||||
|
||||
## Contributing
|
||||
|
||||
Please read the [Contributing Guidelines](./CONTRIBUTING.en.md) before contributing.
|
||||
|
||||
Thanks to all the contributors!
|
||||
|
||||
<a href="https://github.com/Chanzhaoyu/chatgpt-web/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=Chanzhaoyu/chatgpt-web" />
|
||||
</a>
|
||||
|
||||
## Sponsorship
|
||||
|
||||
If you find this project helpful and circumstances permit, you can give me a little support. Thank you very much for your support~
|
||||
|
||||
<div style="display: flex; gap: 20px;">
|
||||
<div style="text-align: center">
|
||||
<img style="max-width: 100%" src="./docs/wechat.png" alt="WeChat" />
|
||||
<p>WeChat Pay</p>
|
||||
</div>
|
||||
<div style="text-align: center">
|
||||
<img style="max-width: 100%" src="./docs/alipay.png" alt="Alipay" />
|
||||
<p>Alipay</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
## License
|
||||
MIT © [ChenZhaoYu](./license)
|
||||
321
README.md
@@ -1,39 +1,322 @@
|
||||
# ChatGPT Web Bot
|
||||
# ChatGPT Web
|
||||
|
||||
English | [中文](./README.zh-CN.md)
|
||||
<div style="font-size: 1.5rem;">
|
||||
<a href="./README.md">中文</a> |
|
||||
<a href="./README.en.md">English</a>
|
||||
</div>
|
||||
</br>
|
||||
|
||||
ChartGPT demo page built with express and vue3
|
||||
> 声明:此项目只发布于 Github,基于 MIT 协议,免费且作为开源学习使用。并且不会有任何形式的卖号、付费服务、讨论群、讨论组等行为。谨防受骗。
|
||||
|
||||

|
||||
## Usage
|
||||
> Make sure `node >= 18`
|
||||

|
||||

|
||||
|
||||
If pnpm is not installed
|
||||
- [ChatGPT Web](#chatgpt-web)
|
||||
- [介绍](#介绍)
|
||||
- [待实现路线](#待实现路线)
|
||||
- [前置要求](#前置要求)
|
||||
- [Node](#node)
|
||||
- [PNPM](#pnpm)
|
||||
- [填写密钥](#填写密钥)
|
||||
- [安装依赖](#安装依赖)
|
||||
- [后端](#后端)
|
||||
- [前端](#前端)
|
||||
- [测试环境运行](#测试环境运行)
|
||||
- [后端服务](#后端服务)
|
||||
- [前端网页](#前端网页)
|
||||
- [打包](#打包)
|
||||
- [使用 Docker](#使用-docker)
|
||||
- [Docker 参数示例](#docker-参数示例)
|
||||
- [Docker build \& Run](#docker-build--run)
|
||||
- [Docker compose](#docker-compose)
|
||||
- [使用 Railway 部署](#使用-railway-部署)
|
||||
- [Railway 环境变量](#railway-环境变量)
|
||||
- [手动打包](#手动打包)
|
||||
- [后端服务](#后端服务-1)
|
||||
- [前端网页](#前端网页-1)
|
||||
- [常见问题](#常见问题)
|
||||
- [参与贡献](#参与贡献)
|
||||
- [赞助](#赞助)
|
||||
- [License](#license)
|
||||
## 介绍
|
||||
|
||||
支持双模型,提供了两种非官方 `ChatGPT API` 方法
|
||||
|
||||
| 方式 | 免费? | 可靠性 | 质量 |
|
||||
| --------------------------------------------- | ------ | ---------- | ---- |
|
||||
| `ChatGPTAPI(gpt-3.5-turbo-0301)` | 否 | 可靠 | 相对较笨 |
|
||||
| `ChatGPTUnofficialProxyAPI(网页 accessToken)` | 是 | 相对不可靠 | 聪明 |
|
||||
|
||||
对比:
|
||||
1. `ChatGPTAPI` 使用 `gpt-3.5-turbo-0301` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型)
|
||||
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(使用真实的的`ChatGPT`,非常轻量级,但依赖于第三方服务器,并且有速率限制)
|
||||
|
||||
[查看详情](https://github.com/Chanzhaoyu/chatgpt-web/issues/138)
|
||||
|
||||
切换方式:
|
||||
1. 进入 `service/.env.example` 文件,复制内容到 `service/.env` 文件
|
||||
2. 使用 `OpenAI API Key` 请填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)
|
||||
3. 使用 `Web API` 请填写 `OPENAI_ACCESS_TOKEN` 字段 [(获取 accessToken)](https://chat.openai.com/api/auth/session)
|
||||
4. 同时存在时以 `OpenAI API Key` 优先
|
||||
|
||||
反向代理:
|
||||
|
||||
`ChatGPTUnofficialProxyAPI`时可用,[详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)
|
||||
|
||||
```shell
|
||||
# service/.env
|
||||
API_REVERSE_PROXY=
|
||||
```
|
||||
|
||||
环境变量:
|
||||
|
||||
全部参数变量请查看或[这里](#docker-参数示例)
|
||||
|
||||
```
|
||||
/service/.env
|
||||
```
|
||||
|
||||
## 待实现路线
|
||||
[✓] 双模型
|
||||
|
||||
[✓] 多会话储存和上下文逻辑
|
||||
|
||||
[✓] 对代码等消息类型的格式化美化处理
|
||||
|
||||
[✓] 访问权限控制
|
||||
|
||||
[✓] 数据导入、导出
|
||||
|
||||
[✓] 保存消息到本地图片
|
||||
|
||||
[✓] 界面多语言
|
||||
|
||||
[✓] 界面主题
|
||||
|
||||
[✗] More...
|
||||
|
||||
## 前置要求
|
||||
|
||||
### Node
|
||||
|
||||
`node` 需要 `^16 || ^18` 版本(`node >= 14` 需要安装 [fetch polyfill](https://github.com/developit/unfetch#usage-as-a-polyfill)),使用 [nvm](https://github.com/nvm-sh/nvm) 可管理本地多个 `node` 版本
|
||||
|
||||
```shell
|
||||
node -v
|
||||
```
|
||||
|
||||
### PNPM
|
||||
如果你没有安装过 `pnpm`
|
||||
```shell
|
||||
npm install pnpm -g
|
||||
```
|
||||
|
||||
install node deps
|
||||
### 填写密钥
|
||||
获取 `Openai Api Key` 或 `accessToken` 并填写本地环境变量 [跳转](#介绍)
|
||||
|
||||
```
|
||||
# service/.env 文件
|
||||
|
||||
# OpenAI API Key - https://platform.openai.com/overview
|
||||
OPENAI_API_KEY=
|
||||
|
||||
# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
|
||||
OPENAI_ACCESS_TOKEN=
|
||||
```
|
||||
|
||||
## 安装依赖
|
||||
|
||||
> 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。
|
||||
|
||||
### 后端
|
||||
|
||||
进入文件夹 `/service` 运行以下命令
|
||||
|
||||
```shell
|
||||
pnpm install
|
||||
```
|
||||
|
||||
Sign up for an [OpenAI API key](https://platform.openai.com/overview) and store it in your environment.
|
||||
|
||||
```
|
||||
# .env
|
||||
OPENAI_API_KEY="Your Key"
|
||||
```
|
||||
|
||||
Run service
|
||||
### 前端
|
||||
根目录下运行以下命令
|
||||
```shell
|
||||
pnpm run service
|
||||
pnpm bootstrap
|
||||
```
|
||||
|
||||
Run web
|
||||
## 测试环境运行
|
||||
### 后端服务
|
||||
|
||||
进入文件夹 `/service` 运行以下命令
|
||||
|
||||
```shell
|
||||
pnpm run dev
|
||||
pnpm start
|
||||
```
|
||||
|
||||
### 前端网页
|
||||
根目录下运行以下命令
|
||||
```shell
|
||||
pnpm dev
|
||||
```
|
||||
|
||||
## 打包
|
||||
|
||||
### 使用 Docker
|
||||
|
||||
#### Docker 参数示例
|
||||
|
||||
- `OPENAI_API_KEY` 二选一
|
||||
- `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先
|
||||
- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用
|
||||
- `OPENAI_API_MODEL` 可选,设置 `OPENAI_API_KEY` 时可用
|
||||
- `API_REVERSE_PROXY` 可选,设置 `OPENAI_ACCESS_TOKEN` 时可用 [参考](#介绍)
|
||||
- `AUTH_SECRET_KEY` 访问权限密钥,可选
|
||||
- `TIMEOUT_MS` 超时,单位毫秒,可选
|
||||
- `SOCKS_PROXY_HOST` 可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||
- `SOCKS_PROXY_PORT` 可选,和 SOCKS_PROXY_HOST 一起时生效
|
||||
|
||||

|
||||
|
||||
#### Docker build & Run
|
||||
|
||||
```bash
|
||||
docker build -t chatgpt-web .
|
||||
|
||||
# 前台运行
|
||||
docker run --name chatgpt-web --rm -it -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||
|
||||
# 后台运行
|
||||
docker run --name chatgpt-web -d -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||
|
||||
# 运行地址
|
||||
http://localhost:3002/
|
||||
```
|
||||
|
||||
#### Docker compose
|
||||
|
||||
[Hub 地址](https://hub.docker.com/repository/docker/chenzhaoyu94/chatgpt-web/general)
|
||||
|
||||
```yml
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
app:
|
||||
image: chenzhaoyu94/chatgpt-web # 总是使用 latest ,更新时重新 pull 该 tag 镜像即可
|
||||
ports:
|
||||
- 3002:3002
|
||||
environment:
|
||||
# 二选一
|
||||
OPENAI_API_KEY: xxxxxx
|
||||
# 二选一
|
||||
OPENAI_ACCESS_TOKEN: xxxxxx
|
||||
# API接口地址,可选,设置 OPENAI_API_KEY 时可用
|
||||
OPENAI_API_BASE_URL: xxxx
|
||||
# API模型,可选,设置 OPENAI_API_KEY 时可用
|
||||
OPENAI_API_MODEL: xxxx
|
||||
# 反向代理,可选
|
||||
API_REVERSE_PROXY: xxx
|
||||
# 访问权限密钥,可选
|
||||
AUTH_SECRET_KEY: xxx
|
||||
# 超时,单位毫秒,可选
|
||||
TIMEOUT_MS: 60000
|
||||
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||
SOCKS_PROXY_HOST: xxxx
|
||||
# Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效
|
||||
SOCKS_PROXY_PORT: xxxx
|
||||
```
|
||||
- `OPENAI_API_BASE_URL` 可选,设置 `OPENAI_API_KEY` 时可用
|
||||
- `OPENAI_API_MODEL` 可选,设置 `OPENAI_API_KEY` 时可用
|
||||
### 使用 Railway 部署
|
||||
|
||||
[](https://railway.app/new/template/yytmgc)
|
||||
|
||||
#### Railway 环境变量
|
||||
|
||||
| 环境变量名称 | 必填 | 备注 |
|
||||
| --------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- |
|
||||
| `PORT` | 必填 | 默认 `3002`
|
||||
| `AUTH_SECRET_KEY` | 可选 | 访问权限密钥 |
|
||||
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒 |
|
||||
| `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) |
|
||||
| `OPENAI_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) |
|
||||
| `OPENAI_API_BASE_URL` | 可选,`OpenAI API` 时可用 | `API`接口地址 |
|
||||
| `OPENAI_API_MODEL` | 可选,`OpenAI API` 时可用 | `API`模型 |
|
||||
| `API_REVERSE_PROXY` | 可选,`Web API` 时可用 | `Web API` 反向代理地址 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) |
|
||||
| `SOCKS_PROXY_HOST` | 可选,和 `SOCKS_PROXY_PORT` 一起时生效 | Socks代理 |
|
||||
| `SOCKS_PROXY_PORT` | 可选,和 `SOCKS_PROXY_HOST` 一起时生效 | Socks代理端口 |
|
||||
|
||||
> 注意: `Railway` 修改环境变量会重新 `Deploy`
|
||||
|
||||
### 手动打包
|
||||
#### 后端服务
|
||||
> 如果你不需要本项目的 `node` 接口,可以省略如下操作
|
||||
|
||||
复制 `service` 文件夹到你有 `node` 服务环境的服务器上。
|
||||
|
||||
```shell
|
||||
# 安装
|
||||
pnpm install
|
||||
|
||||
# 打包
|
||||
pnpm build
|
||||
|
||||
# 运行
|
||||
pnpm prod
|
||||
```
|
||||
|
||||
PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
|
||||
|
||||
#### 前端网页
|
||||
|
||||
1、参考根目录下 `.env.example` 文件内容创建 `.env` 文件,修改 `VITE_APP_API_BASE_URL` 为你的实际后端接口地址
|
||||
|
||||
2、根目录下运行以下命令,然后将 `dist` 文件夹内的文件复制到你网站服务的根目录下
|
||||
|
||||
[参考信息](https://cn.vitejs.dev/guide/static-deploy.html#building-the-app)
|
||||
|
||||
```shell
|
||||
pnpm build
|
||||
```
|
||||
|
||||
## 常见问题
|
||||
Q: 为什么 `Git` 提交总是报错?
|
||||
|
||||
A: 因为有提交信息验证,请遵循 [Commit 指南](./CONTRIBUTING.md)
|
||||
|
||||
Q: 如果只使用前端页面,在哪里改请求接口?
|
||||
|
||||
A: 根目录下 `.env` 文件中的 `VITE_GLOB_API_URL` 字段。
|
||||
|
||||
Q: 文件保存时全部爆红?
|
||||
|
||||
A: `vscode` 请安装项目推荐插件,或手动安装 `Eslint` 插件。
|
||||
|
||||
Q: 前端没有打字机效果?
|
||||
|
||||
A: 一种可能原因是经过 Nginx 反向代理,开启了 buffer,则 Nginx 会尝试从后端缓冲一定大小的数据再发送给浏览器。请尝试在反代参数后添加 `proxy_buffering off;`,然后重载 Nginx。其他 web server 配置同理。
|
||||
|
||||
## 参与贡献
|
||||
|
||||
贡献之前请先阅读 [贡献指南](./CONTRIBUTING.md)
|
||||
|
||||
感谢所有做过贡献的人!
|
||||
|
||||
<a href="https://github.com/Chanzhaoyu/chatgpt-web/graphs/contributors">
|
||||
<img src="https://contrib.rocks/image?repo=Chanzhaoyu/chatgpt-web" />
|
||||
</a>
|
||||
|
||||
## 赞助
|
||||
|
||||
如果你觉得这个项目对你有帮助,并且情况允许的话,可以给我一点点支持,总之非常感谢支持~
|
||||
|
||||
<div style="display: flex; gap: 20px;">
|
||||
<div style="text-align: center">
|
||||
<img style="max-width: 100%" src="./docs/wechat.png" alt="微信" />
|
||||
<p>WeChat Pay</p>
|
||||
</div>
|
||||
<div style="text-align: center">
|
||||
<img style="max-width: 100%" src="./docs/alipay.png" alt="支付宝" />
|
||||
<p>Alipay</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
## License
|
||||
MIT © [ChenZhaoYu](./license)
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
# ChatGPT Web Bot
|
||||
|
||||
[English](./README.md) | 中文
|
||||
|
||||
使用 express 和 vue3 搭建的 ChartGPT 演示网页
|
||||
|
||||

|
||||
|
||||
## 使用
|
||||
> Make sure `node >= 18`
|
||||
|
||||
如果你没有安装过 `pnpm`
|
||||
```shell
|
||||
npm install pnpm -g
|
||||
```
|
||||
|
||||
安装依赖
|
||||
```shell
|
||||
pnpm install
|
||||
```
|
||||
|
||||
获取 [OpenAI API key](https://platform.openai.com/overview) 到本地环境变量
|
||||
|
||||
```
|
||||
# .env
|
||||
OPENAI_API_KEY="Your Key"
|
||||
```
|
||||
|
||||
运行服务
|
||||
```shell
|
||||
pnpm run service
|
||||
```
|
||||
|
||||
运行网页
|
||||
```shell
|
||||
pnpm run dev
|
||||
```
|
||||
|
||||
## License
|
||||
MIT © [ChenZhaoYu](./license)
|
||||
1
config/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './proxy'
|
||||
16
config/proxy.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { ProxyOptions } from 'vite'
|
||||
|
||||
export function createViteProxy(isOpenProxy: boolean, viteEnv: ImportMetaEnv) {
|
||||
if (!isOpenProxy)
|
||||
return
|
||||
|
||||
const proxy: Record<string, string | ProxyOptions> = {
|
||||
'/api': {
|
||||
target: viteEnv.VITE_APP_API_BASE_URL,
|
||||
changeOrigin: true,
|
||||
rewrite: path => path.replace('/api/', '/'),
|
||||
},
|
||||
}
|
||||
|
||||
return proxy
|
||||
}
|
||||
37
docker-compose/docker-compose.yml
Normal file
@@ -0,0 +1,37 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
app:
|
||||
image: chenzhaoyu94/chatgpt-web # 总是使用latest,更新时重新pull该tag镜像即可
|
||||
ports:
|
||||
- 3002:3002
|
||||
environment:
|
||||
# 二选一
|
||||
OPENAI_API_KEY: xxxx
|
||||
# 二选一
|
||||
OPENAI_ACCESS_TOKEN: xxxxxx
|
||||
# API接口地址,可选,设置 OPENAI_API_KEY 时可用
|
||||
OPENAI_API_BASE_URL: xxxx
|
||||
# API模型,可选,设置 OPENAI_API_KEY 时可用
|
||||
OPENAI_API_MODEL: xxxx
|
||||
# 反向代理,可选
|
||||
API_REVERSE_PROXY: xxx
|
||||
# 访问权限密钥,可选
|
||||
AUTH_SECRET_KEY: xxx
|
||||
# 超时,单位毫秒,可选
|
||||
TIMEOUT_MS: 60000
|
||||
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||
SOCKS_PROXY_HOST: xxxx
|
||||
# Socks代理端口,可选,和 SOCKS_PROXY_HOST 一起时生效
|
||||
SOCKS_PROXY_PORT: xxxx
|
||||
nginx:
|
||||
build: nginx
|
||||
image: chatgpt/nginx
|
||||
ports:
|
||||
- '80:80'
|
||||
expose:
|
||||
- '80'
|
||||
volumes:
|
||||
- ./nginx/html/:/etc/nginx/html/
|
||||
links:
|
||||
- app
|
||||
10
docker-compose/nginx/Dockerfile
Normal file
@@ -0,0 +1,10 @@
|
||||
FROM hub.c.163.com/library/nginx
|
||||
|
||||
MAINTAINER jo "tionsin@live.com"
|
||||
|
||||
RUN rm -rf /etc/nginx/conf.d/default.conf
|
||||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
|
||||
COPY ./html/ /usr/share/nginx/html/
|
||||
EXPOSE 80
|
||||
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
20
docker-compose/nginx/nginx.conf
Normal file
@@ -0,0 +1,20 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
charset utf-8;
|
||||
error_page 500 502 503 504 /50x.html;
|
||||
location = / {
|
||||
root /usr/share/nginx/html;
|
||||
index index.html index.htm;
|
||||
}
|
||||
|
||||
location /api {
|
||||
proxy_set_header X-Real-IP $remote_addr; #转发用户IP
|
||||
proxy_pass http://app:3002;
|
||||
}
|
||||
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header REMOTE-HOST $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
15
docker-compose/readme.md
Normal file
@@ -0,0 +1,15 @@
|
||||
### docker-compose 部署教程
|
||||
- 将打包好的前端文件放到 `nginx/html` 目录下
|
||||
- ```shell
|
||||
# 打包启动
|
||||
docker-compose build
|
||||
docker-compose up -d
|
||||
```
|
||||
- ```shell
|
||||
# 查看运行状态
|
||||
docker ps
|
||||
```
|
||||
- ```shell
|
||||
# 结束运行
|
||||
docker-compose down
|
||||
```
|
||||
BIN
docs/alipay.png
Normal file
|
After Width: | Height: | Size: 61 KiB |
BIN
docs/c1-2.8.0.png
Normal file
|
After Width: | Height: | Size: 123 KiB |
BIN
docs/c1.png
Normal file
|
After Width: | Height: | Size: 282 KiB |
BIN
docs/c2-2.8.0.png
Normal file
|
After Width: | Height: | Size: 396 KiB |
BIN
docs/c2.png
Normal file
|
After Width: | Height: | Size: 128 KiB |
BIN
docs/cover.png
|
Before Width: | Height: | Size: 94 KiB |
BIN
docs/docker.png
Normal file
|
After Width: | Height: | Size: 108 KiB |
BIN
docs/wechat.png
Normal file
|
After Width: | Height: | Size: 80 KiB |
132
index.html
@@ -1,71 +1,83 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-cmn-Hans">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>ChatGPT Web</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app">
|
||||
<style>
|
||||
.loading-wrap {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||
<meta content="yes" name="apple-mobile-web-app-capable"/>
|
||||
<link rel="apple-touch-icon" href="/favicon.ico">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover" />
|
||||
<title>ChatGPT Web</title>
|
||||
</head>
|
||||
|
||||
.balls {
|
||||
width: 4em;
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
<body class="dark:bg-black">
|
||||
<div id="app">
|
||||
<style>
|
||||
.loading-wrap {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
}
|
||||
|
||||
.balls div {
|
||||
width: 0.8em;
|
||||
height: 0.8em;
|
||||
border-radius: 50%;
|
||||
background-color: #4b9e5f;
|
||||
}
|
||||
.balls {
|
||||
width: 4em;
|
||||
display: flex;
|
||||
flex-flow: row nowrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.balls div:nth-of-type(1) {
|
||||
transform: translateX(-100%);
|
||||
animation: left-swing 0.5s ease-in alternate infinite;
|
||||
}
|
||||
.balls div {
|
||||
width: 0.8em;
|
||||
height: 0.8em;
|
||||
border-radius: 50%;
|
||||
background-color: #4b9e5f;
|
||||
}
|
||||
|
||||
.balls div:nth-of-type(3) {
|
||||
transform: translateX(-95%);
|
||||
animation: right-swing 0.5s ease-out alternate infinite;
|
||||
}
|
||||
.balls div:nth-of-type(1) {
|
||||
transform: translateX(-100%);
|
||||
animation: left-swing 0.5s ease-in alternate infinite;
|
||||
}
|
||||
|
||||
@keyframes left-swing {
|
||||
50%,
|
||||
100% {
|
||||
transform: translateX(95%);
|
||||
}
|
||||
}
|
||||
.balls div:nth-of-type(3) {
|
||||
transform: translateX(-95%);
|
||||
animation: right-swing 0.5s ease-out alternate infinite;
|
||||
}
|
||||
|
||||
@keyframes right-swing {
|
||||
50% {
|
||||
transform: translateX(-95%);
|
||||
}
|
||||
@keyframes left-swing {
|
||||
|
||||
100% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="loading-wrap">
|
||||
<div class="balls">
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
</div>
|
||||
</div>
|
||||
50%,
|
||||
100% {
|
||||
transform: translateX(95%);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes right-swing {
|
||||
50% {
|
||||
transform: translateX(-95%);
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateX(100%);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
body {
|
||||
background: #121212;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<div class="loading-wrap">
|
||||
<div class="balls">
|
||||
<div></div>
|
||||
<div></div>
|
||||
<div></div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
63
package.json
@@ -1,49 +1,68 @@
|
||||
{
|
||||
"name": "chatgpt-web",
|
||||
"version": "1.0.4",
|
||||
"version": "2.10.1",
|
||||
"private": false,
|
||||
"description": "ChatGPT Web Bot",
|
||||
"author": "ChenZhaoYu <chenzhaoyu1994@gami.com>",
|
||||
"description": "ChatGPT Web",
|
||||
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
||||
"keywords": [
|
||||
"chatgpt-web",
|
||||
"chatgpt",
|
||||
"chatbot",
|
||||
"web",
|
||||
"vue"
|
||||
],
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"service": "esno ./service/index.ts",
|
||||
"build": "run-p type-check build-only",
|
||||
"preview": "vite preview",
|
||||
"build-only": "vite build",
|
||||
"type-check": "vue-tsc --noEmit",
|
||||
"lint": "eslint . --fix --ignore-path .gitignore",
|
||||
"release": "bumpp package.json --commit --push --tag"
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"bootstrap": "pnpm install && pnpm run common:prepare",
|
||||
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml",
|
||||
"common:prepare": "husky install"
|
||||
},
|
||||
"dependencies": {
|
||||
"@traptitech/markdown-it-katex": "^3.6.0",
|
||||
"@vueuse/core": "^9.13.0",
|
||||
"highlight.js": "^11.7.0",
|
||||
"html2canvas": "^1.4.1",
|
||||
"katex": "^0.16.4",
|
||||
"markdown-it": "^13.0.1",
|
||||
"naive-ui": "^2.34.3",
|
||||
"vue": "^3.2.47"
|
||||
"pinia": "^2.0.32",
|
||||
"vue": "^3.2.47",
|
||||
"vue-i18n": "^9.2.2",
|
||||
"vue-router": "^4.1.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^0.35.2",
|
||||
"@antfu/eslint-config": "^0.35.3",
|
||||
"@commitlint/cli": "^17.4.4",
|
||||
"@commitlint/config-conventional": "^17.4.4",
|
||||
"@iconify/vue": "^4.1.0",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/node": "^18.13.0",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"@types/katex": "^0.16.0",
|
||||
"@types/markdown-it": "^12.2.3",
|
||||
"@types/node": "^18.14.6",
|
||||
"@vitejs/plugin-vue": "^4.0.0",
|
||||
"autoprefixer": "^10.4.13",
|
||||
"axios": "^1.3.2",
|
||||
"bumpp": "^8.2.1",
|
||||
"chatgpt": "^4.2.0",
|
||||
"dotenv": "^16.0.3",
|
||||
"eslint": "^8.34.0",
|
||||
"esno": "^0.16.3",
|
||||
"express": "^4.18.2",
|
||||
"axios": "^1.3.4",
|
||||
"crypto-js": "^4.1.1",
|
||||
"eslint": "^8.35.0",
|
||||
"husky": "^8.0.3",
|
||||
"less": "^4.1.3",
|
||||
"lint-staged": "^13.1.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"postcss": "^8.4.21",
|
||||
"prettier": "^2.8.4",
|
||||
"tailwindcss": "^3.2.6",
|
||||
"rimraf": "^4.2.0",
|
||||
"tailwindcss": "^3.2.7",
|
||||
"typescript": "~4.9.5",
|
||||
"vite": "^4.1.1",
|
||||
"vue-tsc": "^1.0.24"
|
||||
"vite": "^4.1.4",
|
||||
"vue-tsc": "^1.2.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{ts,tsx,vue}": [
|
||||
"pnpm lint:fix"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
2560
pnpm-lock.yaml
generated
BIN
public/favicon.ico
Normal file
|
After Width: | Height: | Size: 41 KiB |
26
service/.env.example
Normal file
@@ -0,0 +1,26 @@
|
||||
# OpenAI API Key - https://platform.openai.com/overview
|
||||
OPENAI_API_KEY=
|
||||
|
||||
# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
|
||||
OPENAI_ACCESS_TOKEN=
|
||||
|
||||
# OpenAI API Base URL - https://api.openai.com
|
||||
OPENAI_API_BASE_URL=
|
||||
|
||||
# OpenAI API Model - https://platform.openai.com/docs/models
|
||||
OPENAI_API_MODEL=
|
||||
|
||||
# Reverse Proxy
|
||||
API_REVERSE_PROXY=
|
||||
|
||||
# timeout
|
||||
TIMEOUT_MS=100000
|
||||
|
||||
# Secret key
|
||||
AUTH_SECRET_KEY=
|
||||
|
||||
# Socks Proxy Host
|
||||
SOCKS_PROXY_HOST=
|
||||
|
||||
# Socks Proxy Port
|
||||
SOCKS_PROXY_PORT=
|
||||
5
service/.eslintrc.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"root": true,
|
||||
"ignorePatterns": ["build"],
|
||||
"extends": ["@antfu"]
|
||||
}
|
||||
31
service/.gitignore
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
build
|
||||
1
service/.npmrc
Normal file
@@ -0,0 +1 @@
|
||||
enable-pre-post-scripts=true
|
||||
3
service/.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"recommendations": ["dbaeumer.vscode-eslint"]
|
||||
}
|
||||
22
service/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"prettier.enable": false,
|
||||
"editor.formatOnSave": false,
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": true
|
||||
},
|
||||
"eslint.validate": [
|
||||
"javascript",
|
||||
"typescript",
|
||||
"json",
|
||||
"jsonc",
|
||||
"json5",
|
||||
"yaml"
|
||||
],
|
||||
"cSpell.words": [
|
||||
"antfu",
|
||||
"chatgpt",
|
||||
"esno",
|
||||
"GPTAPI",
|
||||
"OPENAI"
|
||||
]
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
import dotenv from 'dotenv'
|
||||
import { ChatGPTAPI } from 'chatgpt'
|
||||
|
||||
interface ChatContext {
|
||||
conversationId?: string
|
||||
parentMessageId?: string
|
||||
}
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const apiKey = process.env.OPENAI_API_KEY
|
||||
|
||||
if (apiKey === undefined)
|
||||
throw new Error('OPENAI_API_KEY is not defined')
|
||||
|
||||
const chatContext = new Set<ChatContext>()
|
||||
|
||||
/**
|
||||
* More Info: https://github.com/transitive-bullshit/chatgpt-api
|
||||
*/
|
||||
const api = new ChatGPTAPI({ apiKey })
|
||||
|
||||
async function chatReply(message: string) {
|
||||
if (!message)
|
||||
return
|
||||
|
||||
// Get the last context from the chat context
|
||||
// If there is a last context, add it to the options
|
||||
let options = {}
|
||||
const lastContext = Array.from(chatContext).pop()
|
||||
if (lastContext) {
|
||||
const { conversationId, parentMessageId } = lastContext
|
||||
options = { conversationId, parentMessageId }
|
||||
}
|
||||
|
||||
// Send the message to the API
|
||||
const response = await api.sendMessage(message, { ...options })
|
||||
|
||||
const { conversationId, id } = response
|
||||
|
||||
// Add the new context to the chat context
|
||||
if (conversationId && id)
|
||||
chatContext.add({ conversationId, parentMessageId: id })
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
async function clearChatContext() {
|
||||
// Clear the chat context
|
||||
chatContext.clear()
|
||||
return Promise.resolve({ message: 'Chat context cleared' })
|
||||
}
|
||||
|
||||
export { chatReply, clearChatContext }
|
||||
@@ -1,26 +0,0 @@
|
||||
import express from 'express'
|
||||
import { chatReply, clearChatContext } from './chatgpt'
|
||||
|
||||
const app = express()
|
||||
|
||||
app.use(express.json())
|
||||
|
||||
app.all('*', (req, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*')
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type')
|
||||
res.header('Access-Control-Allow-Methods', '*')
|
||||
next()
|
||||
})
|
||||
|
||||
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))
|
||||
|
||||
app.post('/chat', async (req, res) => {
|
||||
const { message } = req.body
|
||||
const response = await chatReply(message)
|
||||
res.send(response)
|
||||
})
|
||||
|
||||
app.post('/clear', async (req, res) => {
|
||||
const response = await clearChatContext()
|
||||
res.send(response)
|
||||
})
|
||||
44
service/package.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "chatgpt-web-service",
|
||||
"version": "1.0.0",
|
||||
"private": false,
|
||||
"description": "ChatGPT Web Service",
|
||||
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
||||
"keywords": [
|
||||
"chatgpt-web",
|
||||
"chatgpt",
|
||||
"chatbot",
|
||||
"express"
|
||||
],
|
||||
"engines": {
|
||||
"node": "^16 || ^18"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "esno ./src/index.ts",
|
||||
"dev": "esno watch ./src/index.ts",
|
||||
"prod": "esno ./build/index.js",
|
||||
"build": "pnpm clean && tsup",
|
||||
"clean": "rimraf build",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix",
|
||||
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml"
|
||||
},
|
||||
"dependencies": {
|
||||
"chatgpt": "^5.0.8",
|
||||
"dotenv": "^16.0.3",
|
||||
"esno": "^0.16.3",
|
||||
"express": "^4.18.2",
|
||||
"isomorphic-fetch": "^3.0.0",
|
||||
"node-fetch": "^3.3.0",
|
||||
"socks-proxy-agent": "^7.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^0.35.3",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/node": "^18.14.6",
|
||||
"eslint": "^8.35.0",
|
||||
"rimraf": "^4.3.0",
|
||||
"tsup": "^6.6.3",
|
||||
"typescript": "^4.9.5"
|
||||
}
|
||||
}
|
||||
3668
service/pnpm-lock.yaml
generated
Normal file
132
service/src/chatgpt/index.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import * as dotenv from 'dotenv'
|
||||
import 'isomorphic-fetch'
|
||||
import type { ChatGPTAPIOptions, ChatMessage, SendMessageOptions } from 'chatgpt'
|
||||
import { ChatGPTAPI, ChatGPTUnofficialProxyAPI } from 'chatgpt'
|
||||
import { SocksProxyAgent } from 'socks-proxy-agent'
|
||||
import fetch from 'node-fetch'
|
||||
import { sendResponse } from '../utils'
|
||||
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
|
||||
|
||||
const ErrorCodeMessage: Record<string, string> = {
|
||||
401: '[OpenAI] 提供错误的API密钥 | Incorrect API key provided',
|
||||
403: '[OpenAI] 服务器拒绝访问,请稍后再试 | Server refused to access, please try again later',
|
||||
502: '[OpenAI] 错误的网关 | Bad Gateway',
|
||||
503: '[OpenAI] 服务器繁忙,请稍后再试 | Server is busy, please try again later',
|
||||
504: '[OpenAI] 网关超时 | Gateway Time-out',
|
||||
500: '[OpenAI] 服务器繁忙,请稍后再试 | Internal Server Error',
|
||||
}
|
||||
|
||||
dotenv.config()
|
||||
|
||||
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
||||
|
||||
let apiModel: ApiModel
|
||||
|
||||
if (!process.env.OPENAI_API_KEY && !process.env.OPENAI_ACCESS_TOKEN)
|
||||
throw new Error('Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable')
|
||||
|
||||
let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
||||
|
||||
(async () => {
|
||||
// More Info: https://github.com/transitive-bullshit/chatgpt-api
|
||||
|
||||
if (process.env.OPENAI_API_KEY) {
|
||||
const options: ChatGPTAPIOptions = {
|
||||
apiKey: process.env.OPENAI_API_KEY,
|
||||
completionParams: {
|
||||
model: process.env.OPENAI_API_MODEL ?? 'gpt-3.5-turbo',
|
||||
},
|
||||
debug: false,
|
||||
}
|
||||
|
||||
if (process.env.OPENAI_API_BASE_URL && process.env.OPENAI_API_BASE_URL.trim().length > 0)
|
||||
options.apiBaseUrl = process.env.OPENAI_API_BASE_URL
|
||||
|
||||
if (process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_PORT) {
|
||||
const agent = new SocksProxyAgent({
|
||||
hostname: process.env.SOCKS_PROXY_HOST,
|
||||
port: process.env.SOCKS_PROXY_PORT,
|
||||
})
|
||||
options.fetch = (url, options) => {
|
||||
return fetch(url, { agent, ...options })
|
||||
}
|
||||
}
|
||||
|
||||
api = new ChatGPTAPI({ ...options })
|
||||
apiModel = 'ChatGPTAPI'
|
||||
}
|
||||
else {
|
||||
const options: ChatGPTUnofficialProxyAPIOptions = {
|
||||
accessToken: process.env.OPENAI_ACCESS_TOKEN,
|
||||
debug: false,
|
||||
}
|
||||
|
||||
if (process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_PORT) {
|
||||
const agent = new SocksProxyAgent({
|
||||
hostname: process.env.SOCKS_PROXY_HOST,
|
||||
port: process.env.SOCKS_PROXY_PORT,
|
||||
})
|
||||
options.fetch = (url, options) => {
|
||||
return fetch(url, { agent, ...options })
|
||||
}
|
||||
}
|
||||
|
||||
if (process.env.API_REVERSE_PROXY)
|
||||
options.apiReverseProxyUrl = process.env.API_REVERSE_PROXY
|
||||
|
||||
api = new ChatGPTUnofficialProxyAPI({ ...options })
|
||||
apiModel = 'ChatGPTUnofficialProxyAPI'
|
||||
}
|
||||
})()
|
||||
|
||||
async function chatReplyProcess(
|
||||
message: string,
|
||||
lastContext?: { conversationId?: string; parentMessageId?: string },
|
||||
process?: (chat: ChatMessage) => void,
|
||||
) {
|
||||
if (!message)
|
||||
return sendResponse({ type: 'Fail', message: 'Message is empty' })
|
||||
|
||||
try {
|
||||
let options: SendMessageOptions = { timeoutMs }
|
||||
|
||||
if (lastContext) {
|
||||
if (apiModel === 'ChatGPTAPI')
|
||||
options = { parentMessageId: lastContext.parentMessageId }
|
||||
else
|
||||
options = { ...lastContext }
|
||||
}
|
||||
|
||||
const response = await api.sendMessage(message, {
|
||||
...options,
|
||||
onProgress: (partialResponse) => {
|
||||
process?.(partialResponse)
|
||||
},
|
||||
})
|
||||
|
||||
return sendResponse({ type: 'Success', data: response })
|
||||
}
|
||||
catch (error: any) {
|
||||
const code = error.statusCode
|
||||
global.console.log(error)
|
||||
if (Reflect.has(ErrorCodeMessage, code))
|
||||
return sendResponse({ type: 'Fail', message: ErrorCodeMessage[code] })
|
||||
return sendResponse({ type: 'Fail', message: error.message ?? 'Please check the back-end console' })
|
||||
}
|
||||
}
|
||||
|
||||
async function chatConfig() {
|
||||
return sendResponse({
|
||||
type: 'Success',
|
||||
data: {
|
||||
apiModel,
|
||||
reverseProxy: process.env.API_REVERSE_PROXY,
|
||||
timeoutMs,
|
||||
socksProxy: (process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_PORT) ? (`${process.env.SOCKS_PROXY_HOST}:${process.env.SOCKS_PROXY_PORT}`) : '-',
|
||||
} as ModelConfig,
|
||||
})
|
||||
}
|
||||
|
||||
export type { ChatContext, ChatMessage }
|
||||
|
||||
export { chatReplyProcess, chatConfig }
|
||||
78
service/src/index.ts
Normal file
@@ -0,0 +1,78 @@
|
||||
import express from 'express'
|
||||
import type { ChatContext, ChatMessage } from './chatgpt'
|
||||
import { chatConfig, chatReplyProcess } from './chatgpt'
|
||||
import { auth } from './middleware/auth'
|
||||
|
||||
const app = express()
|
||||
const router = express.Router()
|
||||
|
||||
app.use(express.static('public'))
|
||||
app.use(express.json())
|
||||
|
||||
app.all('*', (_, res, next) => {
|
||||
res.header('Access-Control-Allow-Origin', '*')
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type')
|
||||
res.header('Access-Control-Allow-Methods', '*')
|
||||
next()
|
||||
})
|
||||
|
||||
router.post('/chat-process', auth, async (req, res) => {
|
||||
res.setHeader('Content-type', 'application/octet-stream')
|
||||
|
||||
try {
|
||||
const { prompt, options = {} } = req.body as { prompt: string; options?: ChatContext }
|
||||
let firstChunk = true
|
||||
await chatReplyProcess(prompt, options, (chat: ChatMessage) => {
|
||||
res.write(firstChunk ? JSON.stringify(chat) : `\n${JSON.stringify(chat)}`)
|
||||
firstChunk = false
|
||||
})
|
||||
}
|
||||
catch (error) {
|
||||
res.write(JSON.stringify(error))
|
||||
}
|
||||
finally {
|
||||
res.end()
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/config', async (req, res) => {
|
||||
try {
|
||||
const response = await chatConfig()
|
||||
res.send(response)
|
||||
}
|
||||
catch (error) {
|
||||
res.send(error)
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/session', async (req, res) => {
|
||||
try {
|
||||
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
|
||||
const hasAuth = typeof AUTH_SECRET_KEY === 'string' && AUTH_SECRET_KEY.length > 0
|
||||
res.send({ status: 'Success', message: '', data: { auth: hasAuth } })
|
||||
}
|
||||
catch (error) {
|
||||
res.send({ status: 'Fail', message: error.message, data: null })
|
||||
}
|
||||
})
|
||||
|
||||
router.post('/verify', async (req, res) => {
|
||||
try {
|
||||
const { token } = req.body as { token: string }
|
||||
if (!token)
|
||||
throw new Error('Secret key is empty')
|
||||
|
||||
if (process.env.AUTH_SECRET_KEY !== token)
|
||||
throw new Error('密钥无效 | Secret key is invalid')
|
||||
|
||||
res.send({ status: 'Success', message: 'Verify successfully', data: null })
|
||||
}
|
||||
catch (error) {
|
||||
res.send({ status: 'Fail', message: error.message, data: null })
|
||||
}
|
||||
})
|
||||
|
||||
app.use('', router)
|
||||
app.use('/api', router)
|
||||
|
||||
app.listen(3002, () => globalThis.console.log('Server is running on port 3002'))
|
||||
19
service/src/middleware/auth.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
const auth = async (req, res, next) => {
|
||||
const AUTH_SECRET_KEY = process.env.AUTH_SECRET_KEY
|
||||
if (typeof AUTH_SECRET_KEY === 'string' && AUTH_SECRET_KEY.length > 0) {
|
||||
try {
|
||||
const Authorization = req.header('Authorization')
|
||||
if (!Authorization || Authorization.replace('Bearer ', '').trim() !== AUTH_SECRET_KEY.trim())
|
||||
throw new Error('Error: 无访问权限 | No access rights')
|
||||
next()
|
||||
}
|
||||
catch (error) {
|
||||
res.send({ status: 'Unauthorized', message: error.message ?? 'Please authenticate.', data: null })
|
||||
}
|
||||
}
|
||||
else {
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
||||
export { auth }
|
||||
24
service/src/types.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import type { FetchFn } from 'chatgpt'
|
||||
|
||||
export interface ChatContext {
|
||||
conversationId?: string
|
||||
parentMessageId?: string
|
||||
}
|
||||
|
||||
export interface ChatGPTUnofficialProxyAPIOptions {
|
||||
accessToken: string
|
||||
apiReverseProxyUrl?: string
|
||||
model?: string
|
||||
debug?: boolean
|
||||
headers?: Record<string, string>
|
||||
fetch?: FetchFn
|
||||
}
|
||||
|
||||
export interface ModelConfig {
|
||||
apiModel?: ApiModel
|
||||
reverseProxy?: string
|
||||
timeoutMs?: number
|
||||
socksProxy?: string
|
||||
}
|
||||
|
||||
export type ApiModel = 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI' | undefined
|
||||
22
service/src/utils/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
interface SendResponseOptions {
|
||||
type: 'Success' | 'Fail'
|
||||
message?: string
|
||||
data?: any
|
||||
}
|
||||
|
||||
export function sendResponse(options: SendResponseOptions) {
|
||||
if (options.type === 'Success') {
|
||||
return Promise.resolve({
|
||||
message: options.message ?? null,
|
||||
data: options.data ?? null,
|
||||
status: options.type,
|
||||
})
|
||||
}
|
||||
|
||||
// eslint-disable-next-line prefer-promise-reject-errors
|
||||
return Promise.reject({
|
||||
message: options.message ?? 'Failed',
|
||||
data: options.data ?? null,
|
||||
status: options.type,
|
||||
})
|
||||
}
|
||||
27
service/tsconfig.json
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es2020",
|
||||
"lib": [
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"baseUrl": ".",
|
||||
"outDir": "build",
|
||||
"noEmit": true
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"build"
|
||||
],
|
||||
"include": [
|
||||
"**/*.ts"
|
||||
]
|
||||
}
|
||||
13
service/tsup.config.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { defineConfig } from 'tsup'
|
||||
|
||||
export default defineConfig({
|
||||
entry: ['src/index.ts'],
|
||||
outDir: 'build',
|
||||
target: 'es2020',
|
||||
format: ['cjs'],
|
||||
splitting: false,
|
||||
sourcemap: true,
|
||||
minify: false,
|
||||
shims: true,
|
||||
dts: false,
|
||||
})
|
||||
25
src/App.vue
@@ -1,13 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
import { GithubSite, NaiveProvider } from '@/components'
|
||||
import Chat from '@/views/Chat/index.vue'
|
||||
import { NConfigProvider } from 'naive-ui'
|
||||
import { NaiveProvider } from '@/components/common'
|
||||
import { useTheme } from '@/hooks/useTheme'
|
||||
import { useLanguage } from '@/hooks/useLanguage'
|
||||
|
||||
const { theme, themeOverrides } = useTheme()
|
||||
const { language } = useLanguage()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NaiveProvider>
|
||||
<div class="h-full overflow-hidden pb-[50px] p-4">
|
||||
<Chat />
|
||||
<GithubSite />
|
||||
</div>
|
||||
</NaiveProvider>
|
||||
<NConfigProvider
|
||||
class="h-full"
|
||||
:theme="theme"
|
||||
:theme-overrides="themeOverrides"
|
||||
:locale="language"
|
||||
>
|
||||
<NaiveProvider>
|
||||
<RouterView />
|
||||
</NaiveProvider>
|
||||
</NConfigProvider>
|
||||
</template>
|
||||
|
||||
48
src/api/index.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
|
||||
import { post } from '@/utils/request'
|
||||
|
||||
export function fetchChatAPI<T = any>(
|
||||
prompt: string,
|
||||
options?: { conversationId?: string; parentMessageId?: string },
|
||||
signal?: GenericAbortSignal,
|
||||
) {
|
||||
return post<T>({
|
||||
url: '/chat',
|
||||
data: { prompt, options },
|
||||
signal,
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchChatConfig<T = any>() {
|
||||
return post<T>({
|
||||
url: '/config',
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchChatAPIProcess<T = any>(
|
||||
params: {
|
||||
prompt: string
|
||||
options?: { conversationId?: string; parentMessageId?: string }
|
||||
signal?: GenericAbortSignal
|
||||
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void },
|
||||
) {
|
||||
return post<T>({
|
||||
url: '/chat-process',
|
||||
data: { prompt: params.prompt, options: params.options },
|
||||
signal: params.signal,
|
||||
onDownloadProgress: params.onDownloadProgress,
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchSession<T>() {
|
||||
return post<T>({
|
||||
url: '/session',
|
||||
})
|
||||
}
|
||||
|
||||
export function fetchVerify<T>(token: string) {
|
||||
return post<T>({
|
||||
url: '/verify',
|
||||
data: { token },
|
||||
})
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<template>
|
||||
<div class="fixed bottom-0 left-0 right-0 p-4 text-sm text-center text-neutral-500">
|
||||
<span class="text-center">
|
||||
❤️ Made By ChenZhaoYu -
|
||||
<a href="https://github.com/Chanzhaoyu/chatgpt-bot" target="_blank" class="text-blue-500">
|
||||
Github
|
||||
</a>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
@@ -1,27 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { defineComponent, h } from 'vue'
|
||||
import { NConfigProvider, NMessageProvider, useMessage } from 'naive-ui'
|
||||
|
||||
function registerNaiveTools() {
|
||||
window.$message = useMessage()
|
||||
}
|
||||
|
||||
const NaiveProviderContent = defineComponent({
|
||||
name: 'NaiveProviderContent',
|
||||
setup() {
|
||||
registerNaiveTools()
|
||||
},
|
||||
render() {
|
||||
return h('div')
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NConfigProvider class="h-full">
|
||||
<NMessageProvider>
|
||||
<slot />
|
||||
<NaiveProviderContent />
|
||||
</NMessageProvider>
|
||||
</NConfigProvider>
|
||||
</template>
|
||||
20
src/components/common/HoverButton/Button.vue
Normal file
@@ -0,0 +1,20 @@
|
||||
<script setup lang='ts'>
|
||||
interface Emit {
|
||||
(e: 'click'): void
|
||||
}
|
||||
|
||||
const emit = defineEmits<Emit>()
|
||||
|
||||
function handleClick() {
|
||||
emit('click')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<button
|
||||
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100 dark:hover:bg-[#414755]"
|
||||
@click="handleClick"
|
||||
>
|
||||
<slot />
|
||||
</button>
|
||||
</template>
|
||||
46
src/components/common/HoverButton/index.vue
Normal file
@@ -0,0 +1,46 @@
|
||||
<script setup lang='ts'>
|
||||
import { computed } from 'vue'
|
||||
import type { PopoverPlacement } from 'naive-ui'
|
||||
import { NTooltip } from 'naive-ui'
|
||||
import Button from './Button.vue'
|
||||
|
||||
interface Props {
|
||||
tooltip?: string
|
||||
placement?: PopoverPlacement
|
||||
}
|
||||
|
||||
interface Emit {
|
||||
(e: 'click'): void
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
tooltip: '',
|
||||
placement: 'bottom',
|
||||
})
|
||||
|
||||
const emit = defineEmits<Emit>()
|
||||
|
||||
const showTooltip = computed(() => Boolean(props.tooltip))
|
||||
|
||||
function handleClick() {
|
||||
emit('click')
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="showTooltip">
|
||||
<NTooltip :placement="placement" trigger="hover">
|
||||
<template #trigger>
|
||||
<Button @click="handleClick">
|
||||
<slot />
|
||||
</Button>
|
||||
</template>
|
||||
{{ tooltip }}
|
||||
</NTooltip>
|
||||
</div>
|
||||
<div v-else>
|
||||
<Button @click="handleClick">
|
||||
<slot />
|
||||
</Button>
|
||||
</div>
|
||||
</template>
|
||||
43
src/components/common/NaiveProvider/index.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<script setup lang="ts">
|
||||
import { defineComponent, h } from 'vue'
|
||||
import {
|
||||
NDialogProvider,
|
||||
NLoadingBarProvider,
|
||||
NMessageProvider,
|
||||
NNotificationProvider,
|
||||
useDialog,
|
||||
useLoadingBar,
|
||||
useMessage,
|
||||
useNotification,
|
||||
} from 'naive-ui'
|
||||
|
||||
function registerNaiveTools() {
|
||||
window.$loadingBar = useLoadingBar()
|
||||
window.$dialog = useDialog()
|
||||
window.$message = useMessage()
|
||||
window.$notification = useNotification()
|
||||
}
|
||||
|
||||
const NaiveProviderContent = defineComponent({
|
||||
name: 'NaiveProviderContent',
|
||||
setup() {
|
||||
registerNaiveTools()
|
||||
},
|
||||
render() {
|
||||
return h('div')
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NLoadingBarProvider>
|
||||
<NDialogProvider>
|
||||
<NNotificationProvider>
|
||||
<NMessageProvider>
|
||||
<slot />
|
||||
<NaiveProviderContent />
|
||||
</NMessageProvider>
|
||||
</NNotificationProvider>
|
||||
</NDialogProvider>
|
||||
</NLoadingBarProvider>
|
||||
</template>
|
||||
62
src/components/common/Setting/About.vue
Normal file
@@ -0,0 +1,62 @@
|
||||
<script setup lang='ts'>
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { NSpin } from 'naive-ui'
|
||||
import { fetchChatConfig } from '@/api'
|
||||
import pkg from '@/../package.json'
|
||||
|
||||
interface ConfigState {
|
||||
timeoutMs?: number
|
||||
reverseProxy?: string
|
||||
apiModel?: string
|
||||
socksProxy?: string
|
||||
}
|
||||
|
||||
const loading = ref(false)
|
||||
|
||||
const config = ref<ConfigState>()
|
||||
|
||||
async function fetchConfig() {
|
||||
try {
|
||||
loading.value = true
|
||||
const { data } = await fetchChatConfig<ConfigState>()
|
||||
config.value = data
|
||||
}
|
||||
finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchConfig()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSpin :show="loading">
|
||||
<div class="p-4 space-y-4">
|
||||
<h2 class="text-xl font-bold">
|
||||
Version - {{ pkg.version }}
|
||||
</h2>
|
||||
<div class="p-2 space-y-2 rounded-md bg-neutral-100 dark:bg-neutral-700">
|
||||
<p>
|
||||
此项目开源于
|
||||
<a
|
||||
class="text-blue-600 dark:text-blue-500"
|
||||
href="https://github.com/Chanzhaoyu/chatgpt-web"
|
||||
target="_blank"
|
||||
>
|
||||
Github
|
||||
</a>
|
||||
,免费且基于 MIT 协议,没有任何形式的付费行为!
|
||||
</p>
|
||||
<p>
|
||||
如果你觉得此项目对你有帮助,请在 Github 帮我点个 Star 或者给予一点赞助,谢谢!
|
||||
</p>
|
||||
</div>
|
||||
<p>{{ $t("setting.api") }}:{{ config?.apiModel ?? '-' }}</p>
|
||||
<p>{{ $t("setting.reverseProxy") }}:{{ config?.reverseProxy ?? '-' }}</p>
|
||||
<p>{{ $t("setting.timeout") }}:{{ config?.timeoutMs ?? '-' }}</p>
|
||||
<p>{{ $t("setting.socks") }}:{{ config?.socksProxy ?? '-' }}</p>
|
||||
</div>
|
||||
</NSpin>
|
||||
</template>
|
||||
221
src/components/common/Setting/General.vue
Normal file
@@ -0,0 +1,221 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, ref } from 'vue'
|
||||
import { NButton, NInput, NPopconfirm, useMessage } from 'naive-ui'
|
||||
import type { Language, Theme } from '@/store/modules/app/helper'
|
||||
import { SvgIcon } from '@/components/common'
|
||||
import { useAppStore, useUserStore } from '@/store'
|
||||
import type { UserInfo } from '@/store/modules/user/helper'
|
||||
import { getCurrentDate } from '@/utils/functions'
|
||||
import { t } from '@/locales'
|
||||
|
||||
const appStore = useAppStore()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const ms = useMessage()
|
||||
|
||||
const theme = computed(() => appStore.theme)
|
||||
|
||||
const userInfo = computed(() => userStore.userInfo)
|
||||
|
||||
const avatar = ref(userInfo.value.avatar ?? '')
|
||||
|
||||
const name = ref(userInfo.value.name ?? '')
|
||||
|
||||
const description = ref(userInfo.value.description ?? '')
|
||||
|
||||
const language = computed({
|
||||
get() {
|
||||
return appStore.language
|
||||
},
|
||||
set(value: Language) {
|
||||
appStore.setLanguage(value)
|
||||
},
|
||||
})
|
||||
|
||||
const themeOptions: { label: string; key: Theme; icon: string }[] = [
|
||||
{
|
||||
label: 'Auto',
|
||||
key: 'auto',
|
||||
icon: 'ri:contrast-line',
|
||||
},
|
||||
{
|
||||
label: 'Light',
|
||||
key: 'light',
|
||||
icon: 'ri:sun-foggy-line',
|
||||
},
|
||||
{
|
||||
label: 'Dark',
|
||||
key: 'dark',
|
||||
icon: 'ri:moon-foggy-line',
|
||||
},
|
||||
]
|
||||
|
||||
const languageOptions: { label: string; key: Language; value: Language }[] = [
|
||||
{ label: '简体中文', key: 'zh-CN', value: 'zh-CN' },
|
||||
{ label: '繁體中文', key: 'zh-TW', value: 'zh-TW' },
|
||||
{ label: 'English', key: 'en-US', value: 'en-US' },
|
||||
]
|
||||
|
||||
function updateUserInfo(options: Partial<UserInfo>) {
|
||||
userStore.updateUserInfo(options)
|
||||
ms.success(t('common.success'))
|
||||
}
|
||||
|
||||
function handleReset() {
|
||||
userStore.resetUserInfo()
|
||||
ms.success(t('common.success'))
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
function exportData(): void {
|
||||
const date = getCurrentDate()
|
||||
const data: string = localStorage.getItem('chatStorage') || '{}'
|
||||
const jsonString: string = JSON.stringify(JSON.parse(data), null, 2)
|
||||
const blob: Blob = new Blob([jsonString], { type: 'application/json' })
|
||||
const url: string = URL.createObjectURL(blob)
|
||||
const link: HTMLAnchorElement = document.createElement('a')
|
||||
link.href = url
|
||||
link.download = `chat-store_${date}.json`
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
document.body.removeChild(link)
|
||||
}
|
||||
|
||||
function importData(event: Event): void {
|
||||
const target = event.target as HTMLInputElement
|
||||
if (!target || !target.files)
|
||||
return
|
||||
|
||||
const file: File = target.files[0]
|
||||
if (!file)
|
||||
return
|
||||
|
||||
const reader: FileReader = new FileReader()
|
||||
reader.onload = () => {
|
||||
try {
|
||||
const data = JSON.parse(reader.result as string)
|
||||
localStorage.setItem('chatStorage', JSON.stringify(data))
|
||||
ms.success(t('common.success'))
|
||||
location.reload()
|
||||
}
|
||||
catch (error) {
|
||||
ms.error(t('common.invalidFileFormat'))
|
||||
}
|
||||
}
|
||||
reader.readAsText(file)
|
||||
}
|
||||
|
||||
function clearData(): void {
|
||||
localStorage.removeItem('chatStorage')
|
||||
location.reload()
|
||||
}
|
||||
|
||||
function handleImportButtonClick(): void {
|
||||
const fileInput = document.getElementById('fileInput') as HTMLElement
|
||||
if (fileInput)
|
||||
fileInput.click()
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="p-4 space-y-5 min-h-[200px]">
|
||||
<div class="space-y-6">
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.avatarLink') }}</span>
|
||||
<div class="flex-1">
|
||||
<NInput v-model:value="avatar" placeholder="" />
|
||||
</div>
|
||||
<NButton size="tiny" text type="primary" @click="updateUserInfo({ avatar })">
|
||||
{{ $t('common.save') }}
|
||||
</NButton>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.name') }}</span>
|
||||
<div class="w-[200px]">
|
||||
<NInput v-model:value="name" placeholder="" />
|
||||
</div>
|
||||
<NButton size="tiny" text type="primary" @click="updateUserInfo({ name })">
|
||||
{{ $t('common.save') }}
|
||||
</NButton>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.description') }}</span>
|
||||
<div class="flex-1">
|
||||
<NInput v-model:value="description" placeholder="" />
|
||||
</div>
|
||||
<NButton size="tiny" text type="primary" @click="updateUserInfo({ description })">
|
||||
{{ $t('common.save') }}
|
||||
</NButton>
|
||||
</div>
|
||||
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.chatHistory') }}</span>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-4">
|
||||
<NButton size="small" @click="exportData">
|
||||
<template #icon>
|
||||
<SvgIcon icon="ri:download-2-fill" />
|
||||
</template>
|
||||
{{ $t('common.export') }}
|
||||
</NButton>
|
||||
|
||||
<input id="fileInput" type="file" style="display:none" @change="importData">
|
||||
<NButton size="small" @click="handleImportButtonClick">
|
||||
<template #icon>
|
||||
<SvgIcon icon="ri:upload-2-fill" />
|
||||
</template>
|
||||
{{ $t('common.import') }}
|
||||
</NButton>
|
||||
|
||||
<NPopconfirm placement="bottom" @positive-click="clearData">
|
||||
<template #trigger>
|
||||
<NButton size="small">
|
||||
<template #icon>
|
||||
<SvgIcon icon="ri:close-circle-line" />
|
||||
</template>
|
||||
{{ $t('common.clear') }}
|
||||
</NButton>
|
||||
</template>
|
||||
{{ $t('chat.clearHistoryConfirm') }}
|
||||
</NPopconfirm>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.theme') }}</span>
|
||||
<div class="flex flex-wrap items-center gap-4">
|
||||
<template v-for="item of themeOptions" :key="item.key">
|
||||
<NButton
|
||||
size="small"
|
||||
:type="item.key === theme ? 'primary' : undefined"
|
||||
@click="appStore.setTheme(item.key)"
|
||||
>
|
||||
<template #icon>
|
||||
<SvgIcon :icon="item.icon" />
|
||||
</template>
|
||||
</NButton>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.language') }}</span>
|
||||
<div class="flex flex-wrap items-center gap-4">
|
||||
<template v-for="item of languageOptions" :key="item.key">
|
||||
<NButton
|
||||
size="small"
|
||||
:type="item.key === language ? 'primary' : undefined"
|
||||
@click="appStore.setLanguage(item.key)"
|
||||
>
|
||||
{{ item.label }}
|
||||
</NButton>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center space-x-4">
|
||||
<span class="flex-shrink-0 w-[100px]">{{ $t('setting.resetUserInfo') }}</span>
|
||||
<NButton size="small" @click="handleReset">
|
||||
{{ $t('common.reset') }}
|
||||
</NButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
55
src/components/common/Setting/index.vue
Normal file
@@ -0,0 +1,55 @@
|
||||
<script setup lang='ts'>
|
||||
import { computed, ref } from 'vue'
|
||||
import { NCard, NModal, NTabPane, NTabs } from 'naive-ui'
|
||||
import General from './General.vue'
|
||||
import About from './About.vue'
|
||||
import { SvgIcon } from '@/components/common'
|
||||
|
||||
const props = defineProps<Props>()
|
||||
|
||||
const emit = defineEmits<Emit>()
|
||||
|
||||
interface Props {
|
||||
visible: boolean
|
||||
}
|
||||
|
||||
interface Emit {
|
||||
(e: 'update:visible', visible: boolean): void
|
||||
}
|
||||
|
||||
const active = ref('General')
|
||||
|
||||
const show = computed({
|
||||
get() {
|
||||
return props.visible
|
||||
},
|
||||
set(visible: boolean) {
|
||||
emit('update:visible', visible)
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NModal v-model:show="show" :auto-focus="false">
|
||||
<NCard role="dialog" aria-modal="true" :bordered="false" style="width: 95%; max-width: 640px">
|
||||
<NTabs v-model:value="active" type="line" animated>
|
||||
<NTabPane name="General" tab="General">
|
||||
<template #tab>
|
||||
<SvgIcon class="text-lg" icon="ri:file-user-line" />
|
||||
<span class="ml-2">{{ $t('setting.general') }}</span>
|
||||
</template>
|
||||
<div class="min-h-[100px]">
|
||||
<General />
|
||||
</div>
|
||||
</NTabPane>
|
||||
<NTabPane name="Config" tab="Config">
|
||||
<template #tab>
|
||||
<SvgIcon class="text-lg" icon="ri:list-settings-line" />
|
||||
<span class="ml-2">{{ $t('setting.config') }}</span>
|
||||
</template>
|
||||
<About />
|
||||
</NTabPane>
|
||||
</NTabs>
|
||||
</NCard>
|
||||
</NModal>
|
||||
</template>
|
||||
40
src/components/common/UserAvatar/index.vue
Normal file
@@ -0,0 +1,40 @@
|
||||
<script setup lang='ts'>
|
||||
import { computed } from 'vue'
|
||||
import { NAvatar } from 'naive-ui'
|
||||
import { useUserStore } from '@/store'
|
||||
import defaultAvatar from '@/assets/avatar.jpg'
|
||||
import { isString } from '@/utils/is'
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const userInfo = computed(() => userStore.userInfo)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex items-center">
|
||||
<div class="w-10 h-10 overflow-hidden rounded-full">
|
||||
<template v-if="isString(userInfo.avatar) && userInfo.avatar.length > 0">
|
||||
<NAvatar
|
||||
size="large"
|
||||
round
|
||||
:src="userInfo.avatar"
|
||||
:fallback-src="defaultAvatar"
|
||||
/>
|
||||
</template>
|
||||
<template v-else>
|
||||
<NAvatar size="large" round :src="defaultAvatar" />
|
||||
</template>
|
||||
</div>
|
||||
<div class="ml-2">
|
||||
<h2 class="font-bold text-md">
|
||||
{{ userInfo.name ?? 'ChenZhaoYu' }}
|
||||
</h2>
|
||||
<p class="text-xs text-gray-500">
|
||||
<span
|
||||
v-if="isString(userInfo.description) && userInfo.description !== ''"
|
||||
v-html="userInfo.description"
|
||||
/>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
7
src/components/common/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import HoverButton from './HoverButton/index.vue'
|
||||
import NaiveProvider from './NaiveProvider/index.vue'
|
||||
import SvgIcon from './SvgIcon/index.vue'
|
||||
import UserAvatar from './UserAvatar/index.vue'
|
||||
import Setting from './Setting/index.vue'
|
||||
|
||||
export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting }
|
||||
8
src/components/custom/GithubSite.vue
Normal file
@@ -0,0 +1,8 @@
|
||||
<template>
|
||||
<div class="text-neutral-400">
|
||||
<span>Star on</span>
|
||||
<a href="https://github.com/Chanzhaoyu/chatgpt-bot" target="_blank" class="text-blue-500">
|
||||
GitHub
|
||||
</a>
|
||||
</div>
|
||||
</template>
|
||||
3
src/components/custom/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import GithubSite from './GithubSite.vue'
|
||||
|
||||
export { GithubSite }
|
||||
@@ -1,5 +0,0 @@
|
||||
import NaiveProvider from './NaiveProvider.vue'
|
||||
import Icon from './Icon.vue'
|
||||
import GithubSite from './GithubSite.vue'
|
||||
|
||||
export { NaiveProvider, Icon, GithubSite }
|
||||
8
src/hooks/useBasicLayout.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { breakpointsTailwind, useBreakpoints } from '@vueuse/core'
|
||||
|
||||
export function useBasicLayout() {
|
||||
const breakpoints = useBreakpoints(breakpointsTailwind)
|
||||
const isMobile = breakpoints.smaller('sm')
|
||||
|
||||
return { isMobile }
|
||||
}
|
||||
36
src/hooks/useIconRender.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { h } from 'vue'
|
||||
import { SvgIcon } from '@/components/common'
|
||||
|
||||
export const useIconRender = () => {
|
||||
interface IconConfig {
|
||||
icon?: string
|
||||
color?: string
|
||||
fontSize?: number
|
||||
}
|
||||
|
||||
interface IconStyle {
|
||||
color?: string
|
||||
fontSize?: string
|
||||
}
|
||||
|
||||
const iconRender = (config: IconConfig) => {
|
||||
const { color, fontSize, icon } = config
|
||||
|
||||
const style: IconStyle = {}
|
||||
|
||||
if (color)
|
||||
style.color = color
|
||||
|
||||
if (fontSize)
|
||||
style.fontSize = `${fontSize}px`
|
||||
|
||||
if (!icon)
|
||||
window.console.warn('iconRender: icon is required')
|
||||
|
||||
return () => h(SvgIcon, { icon, style })
|
||||
}
|
||||
|
||||
return {
|
||||
iconRender,
|
||||
}
|
||||
}
|
||||
27
src/hooks/useLanguage.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { computed } from 'vue'
|
||||
import { enUS, zhCN, zhTW } from 'naive-ui'
|
||||
import { useAppStore } from '@/store'
|
||||
import { setLocale } from '@/locales'
|
||||
|
||||
export function useLanguage() {
|
||||
const appStore = useAppStore()
|
||||
|
||||
const language = computed(() => {
|
||||
switch (appStore.language) {
|
||||
case 'en-US':
|
||||
setLocale('en-US')
|
||||
return enUS
|
||||
case 'zh-CN':
|
||||
setLocale('zh-CN')
|
||||
return zhCN
|
||||
case 'zh-TW':
|
||||
setLocale('zh-TW')
|
||||
return zhTW
|
||||
default:
|
||||
setLocale('zh-CN')
|
||||
return enUS
|
||||
}
|
||||
})
|
||||
|
||||
return { language }
|
||||
}
|
||||
43
src/hooks/useTheme.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import type { GlobalThemeOverrides } from 'naive-ui'
|
||||
import { computed, watch } from 'vue'
|
||||
import { darkTheme, useOsTheme } from 'naive-ui'
|
||||
import { useAppStore } from '@/store'
|
||||
|
||||
export function useTheme() {
|
||||
const appStore = useAppStore()
|
||||
|
||||
const OsTheme = useOsTheme()
|
||||
|
||||
const isDark = computed(() => {
|
||||
if (appStore.theme === 'auto')
|
||||
return OsTheme.value === 'dark'
|
||||
else
|
||||
return appStore.theme === 'dark'
|
||||
})
|
||||
|
||||
const theme = computed(() => {
|
||||
return isDark.value ? darkTheme : undefined
|
||||
})
|
||||
|
||||
const themeOverrides = computed<GlobalThemeOverrides>(() => {
|
||||
if (isDark.value) {
|
||||
return {
|
||||
common: {},
|
||||
}
|
||||
}
|
||||
return {}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => isDark.value,
|
||||
(dark) => {
|
||||
if (dark)
|
||||
document.documentElement.classList.add('dark')
|
||||
else
|
||||
document.documentElement.classList.remove('dark')
|
||||
},
|
||||
{ immediate: true },
|
||||
)
|
||||
|
||||
return { theme, themeOverrides }
|
||||
}
|
||||
5
src/icons/403.vue
Normal file
1
src/icons/404.svg
Normal file
|
After Width: | Height: | Size: 28 KiB |
5
src/icons/500.vue
Normal file
55
src/locales/en-US.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
export default {
|
||||
common: {
|
||||
delete: 'Delete',
|
||||
save: 'Save',
|
||||
reset: 'Reset',
|
||||
export: 'Export',
|
||||
import: 'Import',
|
||||
clear: 'Clear',
|
||||
yes: 'Yes',
|
||||
no: 'No',
|
||||
noData: 'No Data',
|
||||
wrong: 'Something went wrong, please try again later.',
|
||||
success: 'Success',
|
||||
failed: 'Failed',
|
||||
verify: 'Verify',
|
||||
unauthorizedTips: 'Unauthorized, please verify first.',
|
||||
},
|
||||
chat: {
|
||||
placeholder: 'Ask me anything...(Shift + Enter = line break)',
|
||||
placeholderMobile: 'Ask me anything...',
|
||||
copy: 'Copy',
|
||||
copied: 'Copied',
|
||||
copyCode: 'Copy Code',
|
||||
clearChat: 'Clear Chat',
|
||||
clearChatConfirm: 'Are you sure to clear this chat?',
|
||||
exportImage: 'Export Image',
|
||||
exportImageConfirm: 'Are you sure to export this chat to png?',
|
||||
exportSuccess: 'Export Success',
|
||||
exportFailed: 'Export Failed',
|
||||
usingContext: 'Context Mode',
|
||||
turnOnContext: 'In the current mode, sending messages will carry previous chat records.',
|
||||
turnOffContext: 'In the current mode, sending messages will not carry previous chat records.',
|
||||
deleteMessage: 'Delete Message',
|
||||
deleteMessageConfirm: 'Are you sure to delete this message?',
|
||||
deleteHistoryConfirm: 'Are you sure to clear this history?',
|
||||
clearHistoryConfirm: 'Are you sure to clear chat history?',
|
||||
},
|
||||
setting: {
|
||||
setting: 'Setting',
|
||||
general: 'General',
|
||||
config: 'Config',
|
||||
avatarLink: 'Avatar Link',
|
||||
name: 'Name',
|
||||
description: 'Description',
|
||||
resetUserInfo: 'Reset UserInfo',
|
||||
chatHistory: 'ChatHistory',
|
||||
theme: 'Theme',
|
||||
language: 'Language',
|
||||
api: 'API',
|
||||
reverseProxy: 'Reverse Proxy',
|
||||
timeout: 'Timeout',
|
||||
socks: 'Socks',
|
||||
},
|
||||
|
||||
}
|
||||
36
src/locales/index.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { App } from 'vue'
|
||||
import { createI18n } from 'vue-i18n'
|
||||
import enUS from './en-US'
|
||||
import zhCN from './zh-CN'
|
||||
import zhTW from './zh-TW'
|
||||
import { useAppStoreWithOut } from '@/store/modules/app'
|
||||
import type { Language } from '@/store/modules/app/helper'
|
||||
|
||||
const appStore = useAppStoreWithOut()
|
||||
|
||||
const defaultLocale = appStore.language || 'zh-CN'
|
||||
|
||||
const i18n = createI18n({
|
||||
locale: defaultLocale,
|
||||
fallbackLocale: 'en-US',
|
||||
allowComposition: true,
|
||||
messages: {
|
||||
'en-US': enUS,
|
||||
'zh-CN': zhCN,
|
||||
'zh-TW': zhTW,
|
||||
},
|
||||
})
|
||||
|
||||
export function t(key: string) {
|
||||
return i18n.global.t(key)
|
||||
}
|
||||
|
||||
export function setLocale(locale: Language) {
|
||||
i18n.global.locale = locale
|
||||
}
|
||||
|
||||
export function setupI18n(app: App) {
|
||||
app.use(i18n)
|
||||
}
|
||||
|
||||
export default i18n
|
||||
55
src/locales/zh-CN.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
export default {
|
||||
common: {
|
||||
delete: '删除',
|
||||
save: '保存',
|
||||
reset: '重置',
|
||||
export: '导出',
|
||||
import: '导入',
|
||||
clear: '清空',
|
||||
yes: '是',
|
||||
no: '否',
|
||||
noData: '暂无数据',
|
||||
wrong: '好像出错了,请稍后再试。',
|
||||
success: '操作成功',
|
||||
failed: '操作失败',
|
||||
verify: '验证',
|
||||
unauthorizedTips: '未经授权,请先进行验证。',
|
||||
},
|
||||
chat: {
|
||||
placeholder: '来说点什么吧...(Shift + Enter = 换行)',
|
||||
placeholderMobile: '来说点什么...',
|
||||
copy: '复制',
|
||||
copied: '复制成功',
|
||||
copyCode: '复制代码',
|
||||
clearChat: '清空会话',
|
||||
clearChatConfirm: '是否清空会话?',
|
||||
exportImage: '保存会话到图片',
|
||||
exportImageConfirm: '是否将会话保存为图片?',
|
||||
exportSuccess: '保存成功',
|
||||
exportFailed: '保存失败',
|
||||
usingContext: '上下文模式',
|
||||
turnOnContext: '当前模式下, 发送消息会携带之前的聊天记录',
|
||||
turnOffContext: '当前模式下, 发送消息不会携带之前的聊天记录',
|
||||
deleteMessage: '删除消息',
|
||||
deleteMessageConfirm: '是否删除此消息?',
|
||||
deleteHistoryConfirm: '确定删除此记录?',
|
||||
clearHistoryConfirm: '确定清空聊天记录?',
|
||||
},
|
||||
setting: {
|
||||
setting: '设置',
|
||||
general: '总览',
|
||||
config: '配置',
|
||||
avatarLink: '头像链接',
|
||||
name: '名称',
|
||||
description: '描述',
|
||||
resetUserInfo: '重置用户信息',
|
||||
chatHistory: '聊天记录',
|
||||
theme: '主题',
|
||||
language: '语言',
|
||||
api: 'API',
|
||||
reverseProxy: '反向代理',
|
||||
timeout: '超时',
|
||||
socks: 'Socks',
|
||||
},
|
||||
|
||||
}
|
||||
53
src/locales/zh-TW.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
export default {
|
||||
common: {
|
||||
delete: '刪除',
|
||||
save: '儲存',
|
||||
reset: '重設',
|
||||
export: '匯出',
|
||||
import: '匯入',
|
||||
clear: '清除',
|
||||
yes: '是',
|
||||
no: '否',
|
||||
noData: '暫無資料',
|
||||
wrong: '好像出錯了,請稍後再試。',
|
||||
success: '操作成功',
|
||||
failed: '操作失敗',
|
||||
verify: '驗證',
|
||||
unauthorizedTips: '未經授權,請先進行驗證。',
|
||||
},
|
||||
chat: {
|
||||
placeholder: '來說點什麼...(Shift + Enter = 換行)',
|
||||
placeholderMobile: '來說點什麼...',
|
||||
copy: '複製',
|
||||
copied: '複製成功',
|
||||
copyCode: '複製代碼',
|
||||
clearChat: '清除對話',
|
||||
clearChatConfirm: '是否清空對話?',
|
||||
exportImage: '儲存對話為圖片',
|
||||
exportImageConfirm: '是否將對話儲存為圖片?',
|
||||
exportSuccess: '儲存成功',
|
||||
exportFailed: '儲存失敗',
|
||||
usingContext: '上下文模式',
|
||||
turnOnContext: '在當前模式下, 發送訊息會攜帶之前的聊天記錄。',
|
||||
turnOffContext: '在當前模式下, 發送訊息不會攜帶之前的聊天記錄。',
|
||||
deleteMessage: '刪除訊息',
|
||||
deleteMessageConfirm: '是否刪除此訊息?',
|
||||
deleteHistoryConfirm: '確定刪除此紀錄?',
|
||||
},
|
||||
setting: {
|
||||
setting: '設定',
|
||||
general: '總覽',
|
||||
config: '設定',
|
||||
avatarLink: '頭貼連結',
|
||||
name: '名稱',
|
||||
description: '描述',
|
||||
resetUserInfo: '重設使用者資訊',
|
||||
chatHistory: '紀錄',
|
||||
theme: '主題',
|
||||
language: '語言',
|
||||
api: 'API',
|
||||
reverseProxy: '反向代理',
|
||||
timeout: '逾時',
|
||||
socks: 'Socks',
|
||||
},
|
||||
}
|
||||
24
src/main.ts
@@ -1,18 +1,20 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
import './styles/global.css'
|
||||
import { setupI18n } from './locales'
|
||||
import { setupAssets } from './plugins'
|
||||
import { setupStore } from './store'
|
||||
import { setupRouter } from './router'
|
||||
|
||||
/** Tailwind's Preflight Style Override */
|
||||
function naiveStyleOverride() {
|
||||
const meta = document.createElement('meta')
|
||||
meta.name = 'naive-ui-style'
|
||||
document.head.appendChild(meta)
|
||||
}
|
||||
|
||||
/** Setup */
|
||||
function bootstrap() {
|
||||
async function bootstrap() {
|
||||
const app = createApp(App)
|
||||
naiveStyleOverride()
|
||||
setupAssets()
|
||||
|
||||
setupStore(app)
|
||||
|
||||
setupI18n(app)
|
||||
|
||||
await setupRouter(app)
|
||||
|
||||
app.mount('#app')
|
||||
}
|
||||
|
||||
|
||||
18
src/plugins/assets.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'katex/dist/katex.min.css'
|
||||
import '@/styles/lib/tailwind.css'
|
||||
import '@/styles/lib/highlight.less'
|
||||
import '@/styles/lib/github-markdown.less'
|
||||
import '@/styles/global.less'
|
||||
|
||||
/** Tailwind's Preflight Style Override */
|
||||
function naiveStyleOverride() {
|
||||
const meta = document.createElement('meta')
|
||||
meta.name = 'naive-ui-style'
|
||||
document.head.appendChild(meta)
|
||||
}
|
||||
|
||||
function setupAssets() {
|
||||
naiveStyleOverride()
|
||||
}
|
||||
|
||||
export default setupAssets
|
||||
3
src/plugins/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import setupAssets from './assets'
|
||||
|
||||
export { setupAssets }
|
||||
52
src/router/index.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import type { App } from 'vue'
|
||||
import type { RouteRecordRaw } from 'vue-router'
|
||||
import { createRouter, createWebHashHistory } from 'vue-router'
|
||||
import { setupPageGuard } from './permission'
|
||||
import { ChatLayout } from '@/views/chat/layout'
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Root',
|
||||
component: ChatLayout,
|
||||
redirect: '/chat',
|
||||
children: [
|
||||
{
|
||||
path: '/chat/:uuid?',
|
||||
name: 'Chat',
|
||||
component: () => import('@/views/chat/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
path: '/404',
|
||||
name: '404',
|
||||
component: () => import('@/views/exception/404/index.vue'),
|
||||
},
|
||||
|
||||
{
|
||||
path: '/500',
|
||||
name: '500',
|
||||
component: () => import('@/views/exception/500/index.vue'),
|
||||
},
|
||||
|
||||
{
|
||||
path: '/:pathMatch(.*)*',
|
||||
name: 'notFound',
|
||||
redirect: '/404',
|
||||
},
|
||||
]
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes,
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
})
|
||||
|
||||
setupPageGuard(router)
|
||||
|
||||
export async function setupRouter(app: App) {
|
||||
app.use(router)
|
||||
await router.isReady()
|
||||
}
|
||||
25
src/router/permission.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import type { Router } from 'vue-router'
|
||||
import { useAuthStoreWithout } from '@/store/modules/auth'
|
||||
|
||||
export function setupPageGuard(router: Router) {
|
||||
router.beforeEach(async (from, to, next) => {
|
||||
const authStore = useAuthStoreWithout()
|
||||
if (!authStore.session) {
|
||||
try {
|
||||
const data = await authStore.getSession()
|
||||
if (String(data.auth) === 'false' && authStore.token)
|
||||
authStore.removeToken()
|
||||
next()
|
||||
}
|
||||
catch (error) {
|
||||
if (from.path !== '/500')
|
||||
next({ name: '500' })
|
||||
else
|
||||
next()
|
||||
}
|
||||
}
|
||||
else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
}
|
||||
10
src/store/index.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { App } from 'vue'
|
||||
import { createPinia } from 'pinia'
|
||||
|
||||
export const store = createPinia()
|
||||
|
||||
export function setupStore(app: App) {
|
||||
app.use(store)
|
||||
}
|
||||
|
||||
export * from './modules'
|
||||
26
src/store/modules/app/helper.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'appSetting'
|
||||
|
||||
export type Theme = 'light' | 'dark' | 'auto'
|
||||
|
||||
export type Language = 'zh-CN' | 'zh-TW' | 'en-US'
|
||||
|
||||
export interface AppState {
|
||||
siderCollapsed: boolean
|
||||
theme: Theme
|
||||
language: Language
|
||||
}
|
||||
|
||||
export function defaultSetting(): AppState {
|
||||
return { siderCollapsed: false, theme: 'light', language: 'zh-CN' }
|
||||
}
|
||||
|
||||
export function getLocalSetting(): AppState {
|
||||
const localSetting: AppState | undefined = ss.get(LOCAL_NAME)
|
||||
return { ...defaultSetting(), ...localSetting }
|
||||
}
|
||||
|
||||
export function setLocalSetting(setting: AppState): void {
|
||||
ss.set(LOCAL_NAME, setting)
|
||||
}
|
||||
34
src/store/modules/app/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { AppState, Language, Theme } from './helper'
|
||||
import { getLocalSetting, setLocalSetting } from './helper'
|
||||
import { store } from '@/store'
|
||||
|
||||
export const useAppStore = defineStore('app-store', {
|
||||
state: (): AppState => getLocalSetting(),
|
||||
actions: {
|
||||
setSiderCollapsed(collapsed: boolean) {
|
||||
this.siderCollapsed = collapsed
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
setTheme(theme: Theme) {
|
||||
this.theme = theme
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
setLanguage(language: Language) {
|
||||
if (this.language !== language) {
|
||||
this.language = language
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalSetting(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export function useAppStoreWithOut() {
|
||||
return useAppStore(store)
|
||||
}
|
||||
15
src/store/modules/auth/helper.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'SECRET_TOKEN'
|
||||
|
||||
export function getToken() {
|
||||
return ss.get(LOCAL_NAME)
|
||||
}
|
||||
|
||||
export function setToken(token: string) {
|
||||
return ss.set(LOCAL_NAME, token)
|
||||
}
|
||||
|
||||
export function removeToken() {
|
||||
return ss.remove(LOCAL_NAME)
|
||||
}
|
||||
43
src/store/modules/auth/index.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { getToken, removeToken, setToken } from './helper'
|
||||
import { store } from '@/store'
|
||||
import { fetchSession } from '@/api'
|
||||
|
||||
export interface AuthState {
|
||||
token: string | undefined
|
||||
session: { auth: boolean } | null
|
||||
}
|
||||
|
||||
export const useAuthStore = defineStore('auth-store', {
|
||||
state: (): AuthState => ({
|
||||
token: getToken(),
|
||||
session: null,
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async getSession() {
|
||||
try {
|
||||
const { data } = await fetchSession<{ auth: boolean }>()
|
||||
this.session = { ...data }
|
||||
return Promise.resolve(data)
|
||||
}
|
||||
catch (error) {
|
||||
return Promise.reject(error)
|
||||
}
|
||||
},
|
||||
|
||||
setToken(token: string) {
|
||||
this.token = token
|
||||
setToken(token)
|
||||
},
|
||||
|
||||
removeToken() {
|
||||
this.token = undefined
|
||||
removeToken()
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
export function useAuthStoreWithout() {
|
||||
return useAuthStore(store)
|
||||
}
|
||||
17
src/store/modules/chat/helper.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'chatStorage'
|
||||
|
||||
export function defaultState(): Chat.ChatState {
|
||||
const uuid = 1002
|
||||
return { active: uuid, history: [{ uuid, title: 'New Chat', isEdit: false }], chat: [{ uuid, data: [] }] }
|
||||
}
|
||||
|
||||
export function getLocalState(): Chat.ChatState {
|
||||
const localState = ss.get(LOCAL_NAME)
|
||||
return localState ?? defaultState()
|
||||
}
|
||||
|
||||
export function setLocalState(state: Chat.ChatState) {
|
||||
ss.set(LOCAL_NAME, state)
|
||||
}
|
||||
189
src/store/modules/chat/index.ts
Normal file
@@ -0,0 +1,189 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { getLocalState, setLocalState } from './helper'
|
||||
import { router } from '@/router'
|
||||
|
||||
export const useChatStore = defineStore('chat-store', {
|
||||
state: (): Chat.ChatState => getLocalState(),
|
||||
|
||||
getters: {
|
||||
getChatHistoryByCurrentActive(state: Chat.ChatState) {
|
||||
const index = state.history.findIndex(item => item.uuid === state.active)
|
||||
if (index !== -1)
|
||||
return state.history[index]
|
||||
return null
|
||||
},
|
||||
|
||||
getChatByUuid(state: Chat.ChatState) {
|
||||
return (uuid?: number) => {
|
||||
if (uuid)
|
||||
return state.chat.find(item => item.uuid === uuid)?.data ?? []
|
||||
return state.chat.find(item => item.uuid === state.active)?.data ?? []
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
actions: {
|
||||
addHistory(history: Chat.History, chatData: Chat.Chat[] = []) {
|
||||
this.history.unshift(history)
|
||||
this.chat.unshift({ uuid: history.uuid, data: chatData })
|
||||
this.active = history.uuid
|
||||
this.reloadRoute(history.uuid)
|
||||
},
|
||||
|
||||
updateHistory(uuid: number, edit: Partial<Chat.History>) {
|
||||
const index = this.history.findIndex(item => item.uuid === uuid)
|
||||
if (index !== -1) {
|
||||
this.history[index] = { ...this.history[index], ...edit }
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
async deleteHistory(index: number) {
|
||||
this.history.splice(index, 1)
|
||||
this.chat.splice(index, 1)
|
||||
|
||||
if (this.history.length === 0) {
|
||||
this.active = null
|
||||
this.reloadRoute()
|
||||
return
|
||||
}
|
||||
|
||||
if (index > 0 && index <= this.history.length) {
|
||||
const uuid = this.history[index - 1].uuid
|
||||
this.active = uuid
|
||||
this.reloadRoute(uuid)
|
||||
return
|
||||
}
|
||||
|
||||
if (index === 0) {
|
||||
if (this.history.length > 0) {
|
||||
const uuid = this.history[0].uuid
|
||||
this.active = uuid
|
||||
this.reloadRoute(uuid)
|
||||
}
|
||||
}
|
||||
|
||||
if (index > this.history.length) {
|
||||
const uuid = this.history[this.history.length - 1].uuid
|
||||
this.active = uuid
|
||||
this.reloadRoute(uuid)
|
||||
}
|
||||
},
|
||||
|
||||
async setActive(uuid: number) {
|
||||
this.active = uuid
|
||||
return await this.reloadRoute(uuid)
|
||||
},
|
||||
|
||||
getChatByUuidAndIndex(uuid: number, index: number) {
|
||||
if (!uuid || uuid === 0) {
|
||||
if (this.chat.length)
|
||||
return this.chat[0].data[index]
|
||||
return null
|
||||
}
|
||||
const chatIndex = this.chat.findIndex(item => item.uuid === uuid)
|
||||
if (chatIndex !== -1)
|
||||
return this.chat[chatIndex].data[index]
|
||||
return null
|
||||
},
|
||||
|
||||
addChatByUuid(uuid: number, chat: Chat.Chat) {
|
||||
if (!uuid || uuid === 0) {
|
||||
if (this.history.length === 0) {
|
||||
const uuid = Date.now()
|
||||
this.history.push({ uuid, title: chat.text, isEdit: false })
|
||||
this.chat.push({ uuid, data: [chat] })
|
||||
this.active = uuid
|
||||
this.recordState()
|
||||
}
|
||||
else {
|
||||
this.chat[0].data.push(chat)
|
||||
if (this.history[0].title === 'New Chat')
|
||||
this.history[0].title = chat.text
|
||||
this.recordState()
|
||||
}
|
||||
}
|
||||
|
||||
const index = this.chat.findIndex(item => item.uuid === uuid)
|
||||
if (index !== -1) {
|
||||
this.chat[index].data.push(chat)
|
||||
if (this.history[index].title === 'New Chat')
|
||||
this.history[index].title = chat.text
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
updateChatByUuid(uuid: number, index: number, chat: Chat.Chat) {
|
||||
if (!uuid || uuid === 0) {
|
||||
if (this.chat.length) {
|
||||
this.chat[0].data[index] = chat
|
||||
this.recordState()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const chatIndex = this.chat.findIndex(item => item.uuid === uuid)
|
||||
if (chatIndex !== -1) {
|
||||
this.chat[chatIndex].data[index] = chat
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
updateChatSomeByUuid(uuid: number, index: number, chat: Partial<Chat.Chat>) {
|
||||
if (!uuid || uuid === 0) {
|
||||
if (this.chat.length) {
|
||||
this.chat[0].data[index] = { ...this.chat[0].data[index], ...chat }
|
||||
this.recordState()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const chatIndex = this.chat.findIndex(item => item.uuid === uuid)
|
||||
if (chatIndex !== -1) {
|
||||
this.chat[chatIndex].data[index] = { ...this.chat[chatIndex].data[index], ...chat }
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
deleteChatByUuid(uuid: number, index: number) {
|
||||
if (!uuid || uuid === 0) {
|
||||
if (this.chat.length) {
|
||||
this.chat[0].data.splice(index, 1)
|
||||
this.recordState()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const chatIndex = this.chat.findIndex(item => item.uuid === uuid)
|
||||
if (chatIndex !== -1) {
|
||||
this.chat[chatIndex].data.splice(index, 1)
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
clearChatByUuid(uuid: number) {
|
||||
if (!uuid || uuid === 0) {
|
||||
if (this.chat.length) {
|
||||
this.chat[0].data = []
|
||||
this.recordState()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const index = this.chat.findIndex(item => item.uuid === uuid)
|
||||
if (index !== -1) {
|
||||
this.chat[index].data = []
|
||||
this.recordState()
|
||||
}
|
||||
},
|
||||
|
||||
async reloadRoute(uuid?: number) {
|
||||
this.recordState()
|
||||
await router.push({ name: 'Chat', params: { uuid } })
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalState(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
4
src/store/modules/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './app'
|
||||
export * from './chat'
|
||||
export * from './user'
|
||||
export * from './auth'
|
||||
32
src/store/modules/user/helper.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { ss } from '@/utils/storage'
|
||||
|
||||
const LOCAL_NAME = 'userStorage'
|
||||
|
||||
export interface UserInfo {
|
||||
avatar: string
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
|
||||
export interface UserState {
|
||||
userInfo: UserInfo
|
||||
}
|
||||
|
||||
export function defaultSetting(): UserState {
|
||||
return {
|
||||
userInfo: {
|
||||
avatar: 'https://raw.githubusercontent.com/Chanzhaoyu/chatgpt-web/main/src/assets/avatar.jpg',
|
||||
name: 'ChenZhaoYu',
|
||||
description: 'Star on <a href="https://github.com/Chanzhaoyu/chatgpt-bot" class="text-blue-500" target="_blank" >Github</a>',
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function getLocalState(): UserState {
|
||||
const localSetting: UserState | undefined = ss.get(LOCAL_NAME)
|
||||
return { ...defaultSetting(), ...localSetting }
|
||||
}
|
||||
|
||||
export function setLocalState(setting: UserState): void {
|
||||
ss.set(LOCAL_NAME, setting)
|
||||
}
|
||||
22
src/store/modules/user/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import type { UserInfo, UserState } from './helper'
|
||||
import { defaultSetting, getLocalState, setLocalState } from './helper'
|
||||
|
||||
export const useUserStore = defineStore('user-store', {
|
||||
state: (): UserState => getLocalState(),
|
||||
actions: {
|
||||
updateUserInfo(userInfo: Partial<UserInfo>) {
|
||||
this.userInfo = { ...this.userInfo, ...userInfo }
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
resetUserInfo() {
|
||||
this.userInfo = { ...defaultSetting().userInfo }
|
||||
this.recordState()
|
||||
},
|
||||
|
||||
recordState() {
|
||||
setLocalState(this.$state)
|
||||
},
|
||||
},
|
||||
})
|
||||
9
src/styles/global.less
Normal file
@@ -0,0 +1,9 @@
|
||||
html,
|
||||
body,
|
||||
#app {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
padding-bottom: constant(safe-area-inset-bottom);
|
||||
}
|
||||
1102
src/styles/lib/github-markdown.less
Normal file
203
src/styles/lib/highlight.less
Normal file
@@ -0,0 +1,203 @@
|
||||
html.dark {
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
padding: 3px 5px
|
||||
}
|
||||
|
||||
.hljs {
|
||||
color: #abb2bf;
|
||||
background: #282c34
|
||||
}
|
||||
|
||||
.hljs-keyword,
|
||||
.hljs-operator,
|
||||
.hljs-pattern-match {
|
||||
color: #f92672
|
||||
}
|
||||
|
||||
.hljs-function,
|
||||
.hljs-pattern-match .hljs-constructor {
|
||||
color: #61aeee
|
||||
}
|
||||
|
||||
.hljs-function .hljs-params {
|
||||
color: #a6e22e
|
||||
}
|
||||
|
||||
.hljs-function .hljs-params .hljs-typing {
|
||||
color: #fd971f
|
||||
}
|
||||
|
||||
.hljs-module-access .hljs-module {
|
||||
color: #7e57c2
|
||||
}
|
||||
|
||||
.hljs-constructor {
|
||||
color: #e2b93d
|
||||
}
|
||||
|
||||
.hljs-constructor .hljs-string {
|
||||
color: #9ccc65
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: #b18eb1;
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
.hljs-doctag,
|
||||
.hljs-formula {
|
||||
color: #c678dd
|
||||
}
|
||||
|
||||
.hljs-deletion,
|
||||
.hljs-name,
|
||||
.hljs-section,
|
||||
.hljs-selector-tag,
|
||||
.hljs-subst {
|
||||
color: #e06c75
|
||||
}
|
||||
|
||||
.hljs-literal {
|
||||
color: #56b6c2
|
||||
}
|
||||
|
||||
.hljs-addition,
|
||||
.hljs-attribute,
|
||||
.hljs-meta .hljs-string,
|
||||
.hljs-regexp,
|
||||
.hljs-string {
|
||||
color: #98c379
|
||||
}
|
||||
|
||||
.hljs-built_in,
|
||||
.hljs-class .hljs-title,
|
||||
.hljs-title.class_ {
|
||||
color: #e6c07b
|
||||
}
|
||||
|
||||
.hljs-attr,
|
||||
.hljs-number,
|
||||
.hljs-selector-attr,
|
||||
.hljs-selector-class,
|
||||
.hljs-selector-pseudo,
|
||||
.hljs-template-variable,
|
||||
.hljs-type,
|
||||
.hljs-variable {
|
||||
color: #d19a66
|
||||
}
|
||||
|
||||
.hljs-bullet,
|
||||
.hljs-link,
|
||||
.hljs-meta,
|
||||
.hljs-selector-id,
|
||||
.hljs-symbol,
|
||||
.hljs-title {
|
||||
color: #61aeee
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: 700
|
||||
}
|
||||
|
||||
.hljs-link {
|
||||
text-decoration: underline
|
||||
}
|
||||
}
|
||||
|
||||
html {
|
||||
pre code.hljs {
|
||||
display: block;
|
||||
overflow-x: auto;
|
||||
padding: 1em
|
||||
}
|
||||
|
||||
code.hljs {
|
||||
padding: 3px 5px
|
||||
}
|
||||
|
||||
.hljs {
|
||||
color: #383a42;
|
||||
background: #fafafa
|
||||
}
|
||||
|
||||
.hljs-comment,
|
||||
.hljs-quote {
|
||||
color: #a0a1a7;
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
.hljs-doctag,
|
||||
.hljs-formula,
|
||||
.hljs-keyword {
|
||||
color: #a626a4
|
||||
}
|
||||
|
||||
.hljs-deletion,
|
||||
.hljs-name,
|
||||
.hljs-section,
|
||||
.hljs-selector-tag,
|
||||
.hljs-subst {
|
||||
color: #e45649
|
||||
}
|
||||
|
||||
.hljs-literal {
|
||||
color: #0184bb
|
||||
}
|
||||
|
||||
.hljs-addition,
|
||||
.hljs-attribute,
|
||||
.hljs-meta .hljs-string,
|
||||
.hljs-regexp,
|
||||
.hljs-string {
|
||||
color: #50a14f
|
||||
}
|
||||
|
||||
.hljs-attr,
|
||||
.hljs-number,
|
||||
.hljs-selector-attr,
|
||||
.hljs-selector-class,
|
||||
.hljs-selector-pseudo,
|
||||
.hljs-template-variable,
|
||||
.hljs-type,
|
||||
.hljs-variable {
|
||||
color: #986801
|
||||
}
|
||||
|
||||
.hljs-bullet,
|
||||
.hljs-link,
|
||||
.hljs-meta,
|
||||
.hljs-selector-id,
|
||||
.hljs-symbol,
|
||||
.hljs-title {
|
||||
color: #4078f2
|
||||
}
|
||||
|
||||
.hljs-built_in,
|
||||
.hljs-class .hljs-title,
|
||||
.hljs-title.class_ {
|
||||
color: #c18401
|
||||
}
|
||||
|
||||
.hljs-emphasis {
|
||||
font-style: italic
|
||||
}
|
||||
|
||||
.hljs-strong {
|
||||
font-weight: 700
|
||||
}
|
||||
|
||||
.hljs-link {
|
||||
text-decoration: underline
|
||||
}
|
||||
}
|
||||