Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a8dc393b5 | ||
|
|
5fca2e9fa3 | ||
|
|
917feec5d8 | ||
|
|
c52195cef8 | ||
|
|
630e88b8c4 | ||
|
|
734eb7a3fb | ||
|
|
e55fc06686 | ||
|
|
5fee11323b | ||
|
|
814c3a2565 | ||
|
|
d2a22a3ee5 | ||
|
|
92278932ef | ||
|
|
9c6a3d6110 | ||
|
|
e30217542d | ||
|
|
1edf591721 | ||
|
|
60fd2ae0e0 | ||
|
|
3e509f6663 | ||
|
|
bf48eae9fe | ||
|
|
31a84325d4 | ||
|
|
b1d0056429 | ||
|
|
6ecc61ac5d | ||
|
|
e02ab1fbad | ||
|
|
47dc009505 | ||
|
|
f1584b60e8 | ||
|
|
d1c15f58c4 | ||
|
|
d422a805f6 | ||
|
|
08b5772420 |
3
.env
3
.env
@@ -5,3 +5,6 @@ VITE_APP_API_BASE_URL=http://localhost:3002/
|
|||||||
|
|
||||||
# Whether long replies are supported, which may result in higher API fees
|
# Whether long replies are supported, which may result in higher API fees
|
||||||
VITE_GLOB_OPEN_LONG_REPLY=false
|
VITE_GLOB_OPEN_LONG_REPLY=false
|
||||||
|
|
||||||
|
# When you want to use PWA
|
||||||
|
VITE_GLOB_APP_PWA=false
|
||||||
|
|||||||
25
.vscode/launch.json
vendored
Normal file
25
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "chrome",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Web App",
|
||||||
|
"url": "http://localhost:1002",
|
||||||
|
"webRoot": "${workspaceFolder}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Launch Service Server",
|
||||||
|
"runtimeExecutable": "${workspaceFolder}/service/node_modules/.bin/esno",
|
||||||
|
"skipFiles": ["<node_internals>/**"],
|
||||||
|
"program": "${workspaceFolder}/service/src/index.ts",
|
||||||
|
"outFiles": ["${workspaceFolder}/service/**/*.js"],
|
||||||
|
"envFile": "${workspaceFolder}/service/.env"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -37,6 +37,7 @@
|
|||||||
"linkify",
|
"linkify",
|
||||||
"logprobs",
|
"logprobs",
|
||||||
"mdhljs",
|
"mdhljs",
|
||||||
|
"mila",
|
||||||
"nodata",
|
"nodata",
|
||||||
"OPENAI",
|
"OPENAI",
|
||||||
"pinia",
|
"pinia",
|
||||||
|
|||||||
36
CHANGELOG.md
36
CHANGELOG.md
@@ -1,3 +1,39 @@
|
|||||||
|
## v2.10.8
|
||||||
|
|
||||||
|
`2023-03-23`
|
||||||
|
|
||||||
|
如遇问题,请删除 `node_modules` 重新安装依赖。
|
||||||
|
|
||||||
|
## Feature
|
||||||
|
- 显示回复消息原文的选项 [[yilozt](https://github.com/Chanzhaoyu/chatgpt-web/pull/672)]
|
||||||
|
- 添加单 `IP` 每小时请求限制。环境变量: `MAX_REQUEST_PER_HOUR` [[zhuxindong ](https://github.com/Chanzhaoyu/chatgpt-web/pull/718)]
|
||||||
|
- 前端添加角色设定,仅 `API` 方式可见 [[quzard](https://github.com/Chanzhaoyu/chatgpt-web/pull/768)]
|
||||||
|
- `OPENAI_API_MODEL` 变量现在对 `ChatGPTUnofficialProxyAPI` 也生效,注意:`Token` 和 `API` 的模型命名不一致,不能直接填入 `gpt-3.5` 或者 `gpt-4` [[hncboy](https://github.com/Chanzhaoyu/chatgpt-web/pull/632)]
|
||||||
|
- 添加繁体中文 `Prompts` [[PeterDaveHello](https://github.com/Chanzhaoyu/chatgpt-web/pull/796)]
|
||||||
|
|
||||||
|
## Enhancement
|
||||||
|
- 重置回答时滚动定位至该回答 [[shunyue1320](https://github.com/Chanzhaoyu/chatgpt-web/pull/781)]
|
||||||
|
- 当 `API` 是 `gpt-4` 时增加可用的 `Max Tokens` [[simonwu53](https://github.com/Chanzhaoyu/chatgpt-web/pull/729)]
|
||||||
|
- 判断和忽略回复字符 [[liut](https://github.com/Chanzhaoyu/chatgpt-web/pull/474)]
|
||||||
|
- 切换会话时,自动聚焦输入框 [[JS-an](https://github.com/Chanzhaoyu/chatgpt-web/pull/735)]
|
||||||
|
- 渲染的链接新窗口打开
|
||||||
|
- 查询余额可选 `API_BASE_URL` 代理地址
|
||||||
|
- `config` 接口添加验证防止被无限制调用
|
||||||
|
- `PWA` 默认不开启,现在需手动修改 `.env` 文件 `VITE_GLOB_APP_PWA` 变量
|
||||||
|
- 当网络连接时,刷新页面,`500` 错误页自动跳转到主页
|
||||||
|
|
||||||
|
## BugFix
|
||||||
|
- `scrollToBottom` 调回 `scrollToBottomIfAtBottom` [[shunyue1320](https://github.com/Chanzhaoyu/chatgpt-web/pull/771)]
|
||||||
|
- 重置异常的 `loading` 会话
|
||||||
|
|
||||||
|
## Common
|
||||||
|
- 创建 `start.cmd` 在 `windows` 下也可以运行 [vulgatecnn](https://github.com/Chanzhaoyu/chatgpt-web/pull/656)]
|
||||||
|
- 添加 `visual-studio-code` 中调试配置 [[ChandlerVer5](https://github.com/Chanzhaoyu/chatgpt-web/pull/296)]
|
||||||
|
- 修复文档中 `docker` 端口为本地 [[kilvn](https://github.com/Chanzhaoyu/chatgpt-web/pull/802)]
|
||||||
|
## Other
|
||||||
|
- 依赖更新
|
||||||
|
|
||||||
|
|
||||||
## v2.10.7
|
## v2.10.7
|
||||||
|
|
||||||
`2023-03-17`
|
`2023-03-17`
|
||||||
|
|||||||
@@ -185,10 +185,10 @@ pnpm dev
|
|||||||
docker build -t chatgpt-web .
|
docker build -t chatgpt-web .
|
||||||
|
|
||||||
# foreground operation
|
# foreground operation
|
||||||
docker run --name chatgpt-web --rm -it -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
docker run --name chatgpt-web --rm -it -p 127.0.0.1:3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||||
|
|
||||||
# background operation
|
# background operation
|
||||||
docker run --name chatgpt-web -d -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
docker run --name chatgpt-web -d -p 127.0.0.1:3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||||
|
|
||||||
# running address
|
# running address
|
||||||
http://localhost:3002/
|
http://localhost:3002/
|
||||||
@@ -205,7 +205,7 @@ services:
|
|||||||
app:
|
app:
|
||||||
image: chenzhaoyu94/chatgpt-web # always use latest, pull the tag image again when updating
|
image: chenzhaoyu94/chatgpt-web # always use latest, pull the tag image again when updating
|
||||||
ports:
|
ports:
|
||||||
- 3002:3002
|
- 127.0.0.1:3002:3002
|
||||||
environment:
|
environment:
|
||||||
# one of two
|
# one of two
|
||||||
OPENAI_API_KEY: xxxxxx
|
OPENAI_API_KEY: xxxxxx
|
||||||
|
|||||||
10
README.md
10
README.md
@@ -170,6 +170,7 @@ pnpm dev
|
|||||||
通用:
|
通用:
|
||||||
|
|
||||||
- `AUTH_SECRET_KEY` 访问权限密钥,可选
|
- `AUTH_SECRET_KEY` 访问权限密钥,可选
|
||||||
|
- `MAX_REQUEST_PER_HOUR` 每小时最大请求次数,可选,默认无限
|
||||||
- `TIMEOUT_MS` 超时,单位毫秒,可选
|
- `TIMEOUT_MS` 超时,单位毫秒,可选
|
||||||
- `SOCKS_PROXY_HOST` 和 `SOCKS_PROXY_PORT` 一起时生效,可选
|
- `SOCKS_PROXY_HOST` 和 `SOCKS_PROXY_PORT` 一起时生效,可选
|
||||||
- `SOCKS_PROXY_PORT` 和 `SOCKS_PROXY_HOST` 一起时生效,可选
|
- `SOCKS_PROXY_PORT` 和 `SOCKS_PROXY_HOST` 一起时生效,可选
|
||||||
@@ -190,10 +191,10 @@ pnpm dev
|
|||||||
docker build -t chatgpt-web .
|
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 --rm -it -p 127.0.0.1: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
|
docker run --name chatgpt-web -d -p 127.0.0.1:3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||||
|
|
||||||
# 运行地址
|
# 运行地址
|
||||||
http://localhost:3002/
|
http://localhost:3002/
|
||||||
@@ -210,7 +211,7 @@ services:
|
|||||||
app:
|
app:
|
||||||
image: chenzhaoyu94/chatgpt-web # 总是使用 latest ,更新时重新 pull 该 tag 镜像即可
|
image: chenzhaoyu94/chatgpt-web # 总是使用 latest ,更新时重新 pull 该 tag 镜像即可
|
||||||
ports:
|
ports:
|
||||||
- 3002:3002
|
- 127.0.0.1:3002:3002
|
||||||
environment:
|
environment:
|
||||||
# 二选一
|
# 二选一
|
||||||
OPENAI_API_KEY: sk-xxx
|
OPENAI_API_KEY: sk-xxx
|
||||||
@@ -224,6 +225,8 @@ services:
|
|||||||
API_REVERSE_PROXY: xxx
|
API_REVERSE_PROXY: xxx
|
||||||
# 访问权限密钥,可选
|
# 访问权限密钥,可选
|
||||||
AUTH_SECRET_KEY: xxx
|
AUTH_SECRET_KEY: xxx
|
||||||
|
# 每小时最大请求次数,可选,默认无限
|
||||||
|
MAX_REQUEST_PER_HOUR: 0
|
||||||
# 超时,单位毫秒,可选
|
# 超时,单位毫秒,可选
|
||||||
TIMEOUT_MS: 60000
|
TIMEOUT_MS: 60000
|
||||||
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||||
@@ -245,6 +248,7 @@ services:
|
|||||||
| --------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- |
|
| --------------------- | ---------------------- | -------------------------------------------------------------------------------------------------- |
|
||||||
| `PORT` | 必填 | 默认 `3002`
|
| `PORT` | 必填 | 默认 `3002`
|
||||||
| `AUTH_SECRET_KEY` | 可选 | 访问权限密钥 |
|
| `AUTH_SECRET_KEY` | 可选 | 访问权限密钥 |
|
||||||
|
| `MAX_REQUEST_PER_HOUR` | 可选 | 每小时最大请求次数,可选,默认无限 |
|
||||||
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒 |
|
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒 |
|
||||||
| `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) |
|
| `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_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) |
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ services:
|
|||||||
API_REVERSE_PROXY: xxx
|
API_REVERSE_PROXY: xxx
|
||||||
# 访问权限密钥,可选
|
# 访问权限密钥,可选
|
||||||
AUTH_SECRET_KEY: xxx
|
AUTH_SECRET_KEY: xxx
|
||||||
|
# 每小时最大请求次数,可选,默认无限
|
||||||
|
MAX_REQUEST_PER_HOUR: 0
|
||||||
# 超时,单位毫秒,可选
|
# 超时,单位毫秒,可选
|
||||||
TIMEOUT_MS: 60000
|
TIMEOUT_MS: 60000
|
||||||
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
# Socks代理,可选,和 SOCKS_PROXY_PORT 一起时生效
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chatgpt-web",
|
"name": "chatgpt-web",
|
||||||
"version": "2.10.7",
|
"version": "2.10.8",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "ChatGPT Web",
|
"description": "ChatGPT Web",
|
||||||
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
||||||
@@ -43,6 +43,7 @@
|
|||||||
"@types/crypto-js": "^4.1.1",
|
"@types/crypto-js": "^4.1.1",
|
||||||
"@types/katex": "^0.16.0",
|
"@types/katex": "^0.16.0",
|
||||||
"@types/markdown-it": "^12.2.3",
|
"@types/markdown-it": "^12.2.3",
|
||||||
|
"@types/markdown-it-link-attributes": "^3.0.1",
|
||||||
"@types/node": "^18.14.6",
|
"@types/node": "^18.14.6",
|
||||||
"@vitejs/plugin-vue": "^4.0.0",
|
"@vitejs/plugin-vue": "^4.0.0",
|
||||||
"autoprefixer": "^10.4.13",
|
"autoprefixer": "^10.4.13",
|
||||||
@@ -52,6 +53,7 @@
|
|||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"less": "^4.1.3",
|
"less": "^4.1.3",
|
||||||
"lint-staged": "^13.1.2",
|
"lint-staged": "^13.1.2",
|
||||||
|
"markdown-it-link-attributes": "^4.0.1",
|
||||||
"npm-run-all": "^4.1.5",
|
"npm-run-all": "^4.1.5",
|
||||||
"postcss": "^8.4.21",
|
"postcss": "^8.4.21",
|
||||||
"rimraf": "^4.2.0",
|
"rimraf": "^4.2.0",
|
||||||
|
|||||||
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@@ -9,6 +9,7 @@ specifiers:
|
|||||||
'@types/crypto-js': ^4.1.1
|
'@types/crypto-js': ^4.1.1
|
||||||
'@types/katex': ^0.16.0
|
'@types/katex': ^0.16.0
|
||||||
'@types/markdown-it': ^12.2.3
|
'@types/markdown-it': ^12.2.3
|
||||||
|
'@types/markdown-it-link-attributes': ^3.0.1
|
||||||
'@types/node': ^18.14.6
|
'@types/node': ^18.14.6
|
||||||
'@vitejs/plugin-vue': ^4.0.0
|
'@vitejs/plugin-vue': ^4.0.0
|
||||||
'@vueuse/core': ^9.13.0
|
'@vueuse/core': ^9.13.0
|
||||||
@@ -23,6 +24,7 @@ specifiers:
|
|||||||
less: ^4.1.3
|
less: ^4.1.3
|
||||||
lint-staged: ^13.1.2
|
lint-staged: ^13.1.2
|
||||||
markdown-it: ^13.0.1
|
markdown-it: ^13.0.1
|
||||||
|
markdown-it-link-attributes: ^4.0.1
|
||||||
naive-ui: ^2.34.3
|
naive-ui: ^2.34.3
|
||||||
npm-run-all: ^4.1.5
|
npm-run-all: ^4.1.5
|
||||||
pinia: ^2.0.33
|
pinia: ^2.0.33
|
||||||
@@ -58,6 +60,7 @@ devDependencies:
|
|||||||
'@types/crypto-js': 4.1.1
|
'@types/crypto-js': 4.1.1
|
||||||
'@types/katex': 0.16.0
|
'@types/katex': 0.16.0
|
||||||
'@types/markdown-it': 12.2.3
|
'@types/markdown-it': 12.2.3
|
||||||
|
'@types/markdown-it-link-attributes': 3.0.1
|
||||||
'@types/node': 18.14.6
|
'@types/node': 18.14.6
|
||||||
'@vitejs/plugin-vue': 4.0.0_vite@4.2.0+vue@3.2.47
|
'@vitejs/plugin-vue': 4.0.0_vite@4.2.0+vue@3.2.47
|
||||||
autoprefixer: 10.4.13_postcss@8.4.21
|
autoprefixer: 10.4.13_postcss@8.4.21
|
||||||
@@ -67,6 +70,7 @@ devDependencies:
|
|||||||
husky: 8.0.3
|
husky: 8.0.3
|
||||||
less: 4.1.3
|
less: 4.1.3
|
||||||
lint-staged: 13.1.2
|
lint-staged: 13.1.2
|
||||||
|
markdown-it-link-attributes: 4.0.1
|
||||||
npm-run-all: 4.1.5
|
npm-run-all: 4.1.5
|
||||||
postcss: 8.4.21
|
postcss: 8.4.21
|
||||||
rimraf: 4.3.0
|
rimraf: 4.3.0
|
||||||
@@ -2065,6 +2069,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==}
|
resolution: {integrity: sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/@types/markdown-it-link-attributes/3.0.1:
|
||||||
|
resolution: {integrity: sha512-K8RnNb1q8j7rDOJbMF7AnlhCC/45BjrQ8z3WZWOrvkBIl8u9RXvmBdG/hfpnmK1JhhEZcmFEKWt+ilW1Mly+2Q==}
|
||||||
|
dependencies:
|
||||||
|
'@types/markdown-it': 12.2.3
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/markdown-it/12.2.3:
|
/@types/markdown-it/12.2.3:
|
||||||
resolution: {integrity: sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==}
|
resolution: {integrity: sha512-GKMHFfv3458yYy+v/N8gjufHO6MSZKCOXpZc5GXIWWy8uldwfmPn98vp81gZ5f9SVw8YYBctgfJ22a2d7AOMeQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -4848,6 +4858,10 @@ packages:
|
|||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/markdown-it-link-attributes/4.0.1:
|
||||||
|
resolution: {integrity: sha512-pg5OK0jPLg62H4k7M9mRJLT61gUp9nvG0XveKYHMOOluASo9OEF13WlXrpAp2aj35LbedAy3QOCgQCw0tkLKAQ==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/markdown-it/13.0.1:
|
/markdown-it/13.0.1:
|
||||||
resolution: {integrity: sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==}
|
resolution: {integrity: sha512-lTlxriVoy2criHP0JKRhO2VDG9c2ypWCsT237eDiLqi09rmbKoUetyGHq2uOIRoRS//kfoJckS0eUzzkDR+k2Q==}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ API_REVERSE_PROXY=
|
|||||||
# timeout
|
# timeout
|
||||||
TIMEOUT_MS=100000
|
TIMEOUT_MS=100000
|
||||||
|
|
||||||
|
# Rate Limit
|
||||||
|
MAX_REQUEST_PER_HOUR=
|
||||||
|
|
||||||
# Secret key
|
# Secret key
|
||||||
AUTH_SECRET_KEY=
|
AUTH_SECRET_KEY=
|
||||||
|
|
||||||
@@ -27,3 +30,4 @@ SOCKS_PROXY_PORT=
|
|||||||
|
|
||||||
# HTTPS PROXY
|
# HTTPS PROXY
|
||||||
HTTPS_PROXY=
|
HTTPS_PROXY=
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.3.4",
|
"axios": "^1.3.4",
|
||||||
"chatgpt": "^5.0.10",
|
"chatgpt": "^5.1.2",
|
||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"esno": "^0.16.3",
|
"esno": "^0.16.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
|
"express-rate-limit": "^6.7.0",
|
||||||
"https-proxy-agent": "^5.0.1",
|
"https-proxy-agent": "^5.0.1",
|
||||||
"isomorphic-fetch": "^3.0.0",
|
"isomorphic-fetch": "^3.0.0",
|
||||||
"node-fetch": "^3.3.0",
|
"node-fetch": "^3.3.0",
|
||||||
|
|||||||
25
service/pnpm-lock.yaml
generated
25
service/pnpm-lock.yaml
generated
@@ -5,11 +5,12 @@ specifiers:
|
|||||||
'@types/express': ^4.17.17
|
'@types/express': ^4.17.17
|
||||||
'@types/node': ^18.14.6
|
'@types/node': ^18.14.6
|
||||||
axios: ^1.3.4
|
axios: ^1.3.4
|
||||||
chatgpt: ^5.0.10
|
chatgpt: ^5.1.2
|
||||||
dotenv: ^16.0.3
|
dotenv: ^16.0.3
|
||||||
eslint: ^8.35.0
|
eslint: ^8.35.0
|
||||||
esno: ^0.16.3
|
esno: ^0.16.3
|
||||||
express: ^4.18.2
|
express: ^4.18.2
|
||||||
|
express-rate-limit: ^6.7.0
|
||||||
https-proxy-agent: ^5.0.1
|
https-proxy-agent: ^5.0.1
|
||||||
isomorphic-fetch: ^3.0.0
|
isomorphic-fetch: ^3.0.0
|
||||||
node-fetch: ^3.3.0
|
node-fetch: ^3.3.0
|
||||||
@@ -20,10 +21,11 @@ specifiers:
|
|||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
axios: 1.3.4
|
axios: 1.3.4
|
||||||
chatgpt: 5.0.10
|
chatgpt: 5.1.2
|
||||||
dotenv: 16.0.3
|
dotenv: 16.0.3
|
||||||
esno: 0.16.3
|
esno: 0.16.3
|
||||||
express: 4.18.2
|
express: 4.18.2
|
||||||
|
express-rate-limit: 6.7.0_express@4.18.2
|
||||||
https-proxy-agent: 5.0.1
|
https-proxy-agent: 5.0.1
|
||||||
isomorphic-fetch: 3.0.0
|
isomorphic-fetch: 3.0.0
|
||||||
node-fetch: 3.3.0
|
node-fetch: 3.3.0
|
||||||
@@ -154,8 +156,8 @@ packages:
|
|||||||
chalk: 2.4.2
|
chalk: 2.4.2
|
||||||
js-tokens: 4.0.0
|
js-tokens: 4.0.0
|
||||||
|
|
||||||
/@dqbd/tiktoken/0.4.0:
|
/@dqbd/tiktoken/1.0.2:
|
||||||
resolution: {integrity: sha512-iaHgmwKAOqowBFZKxelyszoeGLoNw62eOULcmyme1aA1Ymr3JgYl0V7jwpuUm7fksalycZajx3loFn9TRUaviw==}
|
resolution: {integrity: sha512-AjGTBRWsMoVmVeN55NLyupyM8TNamOUBl6tj5t/leLDVup3CFGO9tVagNL1jf3GyZLkWZSTmYVbPQ/M2LEcNzw==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/@esbuild-kit/cjs-loader/2.4.2:
|
/@esbuild-kit/cjs-loader/2.4.2:
|
||||||
@@ -920,12 +922,12 @@ packages:
|
|||||||
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/chatgpt/5.0.10:
|
/chatgpt/5.1.2:
|
||||||
resolution: {integrity: sha512-R3vtPlhCapFLkDXED0Cnt1DBcOZAXygr0M5U5kbSI0Fwm4uDQmc7qoIOnr17rd8eaa0JO/UDOevJdEWvd079qA==}
|
resolution: {integrity: sha512-b/NnDQHDOpouK+gmhUCKcKuvnKEh+DotwXlP6Qgw1mqmkcfVl9Wt3/3noT8jbGJpMEpFOfzexXn5Rehpea1N0w==}
|
||||||
engines: {node: '>=14'}
|
engines: {node: '>=14'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dependencies:
|
dependencies:
|
||||||
'@dqbd/tiktoken': 0.4.0
|
'@dqbd/tiktoken': 1.0.2
|
||||||
cac: 6.7.14
|
cac: 6.7.14
|
||||||
conf: 11.0.1
|
conf: 11.0.1
|
||||||
eventsource-parser: 0.0.5
|
eventsource-parser: 0.0.5
|
||||||
@@ -1740,6 +1742,15 @@ packages:
|
|||||||
strip-final-newline: 2.0.0
|
strip-final-newline: 2.0.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/express-rate-limit/6.7.0_express@4.18.2:
|
||||||
|
resolution: {integrity: sha512-vhwIdRoqcYB/72TK3tRZI+0ttS8Ytrk24GfmsxDXK9o9IhHNO5bXRiXQSExPQ4GbaE5tvIS7j1SGrxsuWs+sGA==}
|
||||||
|
engines: {node: '>= 12.9.0'}
|
||||||
|
peerDependencies:
|
||||||
|
express: ^4 || ^5
|
||||||
|
dependencies:
|
||||||
|
express: 4.18.2
|
||||||
|
dev: false
|
||||||
|
|
||||||
/express/4.18.2:
|
/express/4.18.2:
|
||||||
resolution: {integrity: sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==}
|
resolution: {integrity: sha512-5/PsL6iGPdfQ/lKM1UuielYgv3BUoJfz1aUwU9vHZ+J7gyvwdQXFEBIEIaxeGf0GIcreATNyBExtalisDbuMqQ==}
|
||||||
engines: {node: '>= 0.10.0'}
|
engines: {node: '>= 0.10.0'}
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ import axios from 'axios'
|
|||||||
import { sendResponse } from '../utils'
|
import { sendResponse } from '../utils'
|
||||||
import { isNotEmptyString } from '../utils/is'
|
import { isNotEmptyString } from '../utils/is'
|
||||||
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
|
import type { ApiModel, ChatContext, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from '../types'
|
||||||
|
import type { RequestOptions } from './types'
|
||||||
|
|
||||||
|
dotenv.config()
|
||||||
|
|
||||||
const ErrorCodeMessage: Record<string, string> = {
|
const ErrorCodeMessage: Record<string, string> = {
|
||||||
401: '[OpenAI] 提供错误的API密钥 | Incorrect API key provided',
|
401: '[OpenAI] 提供错误的API密钥 | Incorrect API key provided',
|
||||||
@@ -19,13 +22,11 @@ const ErrorCodeMessage: Record<string, string> = {
|
|||||||
500: '[OpenAI] 服务器繁忙,请稍后再试 | Internal Server Error',
|
500: '[OpenAI] 服务器繁忙,请稍后再试 | Internal Server Error',
|
||||||
}
|
}
|
||||||
|
|
||||||
dotenv.config()
|
|
||||||
|
|
||||||
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
||||||
|
|
||||||
let apiModel: ApiModel
|
let apiModel: ApiModel
|
||||||
|
|
||||||
if (!process.env.OPENAI_API_KEY && !process.env.OPENAI_ACCESS_TOKEN)
|
if (!isNotEmptyString(process.env.OPENAI_API_KEY) && !isNotEmptyString(process.env.OPENAI_ACCESS_TOKEN))
|
||||||
throw new Error('Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable')
|
throw new Error('Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable')
|
||||||
|
|
||||||
let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
||||||
@@ -33,7 +34,8 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||||||
(async () => {
|
(async () => {
|
||||||
// More Info: https://github.com/transitive-bullshit/chatgpt-api
|
// More Info: https://github.com/transitive-bullshit/chatgpt-api
|
||||||
|
|
||||||
if (process.env.OPENAI_API_KEY) {
|
if (isNotEmptyString(process.env.OPENAI_API_KEY)) {
|
||||||
|
const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL
|
||||||
const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL
|
const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL
|
||||||
const model = isNotEmptyString(OPENAI_API_MODEL) ? OPENAI_API_MODEL : 'gpt-3.5-turbo'
|
const model = isNotEmptyString(OPENAI_API_MODEL) ? OPENAI_API_MODEL : 'gpt-3.5-turbo'
|
||||||
|
|
||||||
@@ -43,8 +45,21 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||||||
debug: true,
|
debug: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isNotEmptyString(process.env.OPENAI_API_BASE_URL))
|
// increase max token limit if use gpt-4
|
||||||
options.apiBaseUrl = process.env.OPENAI_API_BASE_URL
|
if (model.toLowerCase().includes('gpt-4')) {
|
||||||
|
// if use 32k model
|
||||||
|
if (model.toLowerCase().includes('32k')) {
|
||||||
|
options.maxModelTokens = 32768
|
||||||
|
options.maxResponseTokens = 8192
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
options.maxModelTokens = 8192
|
||||||
|
options.maxResponseTokens = 2048
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isNotEmptyString(OPENAI_API_BASE_URL))
|
||||||
|
options.apiBaseUrl = `${OPENAI_API_BASE_URL}/v1`
|
||||||
|
|
||||||
setupProxy(options)
|
setupProxy(options)
|
||||||
|
|
||||||
@@ -52,10 +67,13 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||||||
apiModel = 'ChatGPTAPI'
|
apiModel = 'ChatGPTAPI'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
const OPENAI_API_MODEL = process.env.OPENAI_API_MODEL
|
||||||
const options: ChatGPTUnofficialProxyAPIOptions = {
|
const options: ChatGPTUnofficialProxyAPIOptions = {
|
||||||
accessToken: process.env.OPENAI_ACCESS_TOKEN,
|
accessToken: process.env.OPENAI_ACCESS_TOKEN,
|
||||||
debug: true,
|
debug: true,
|
||||||
}
|
}
|
||||||
|
if (isNotEmptyString(OPENAI_API_MODEL))
|
||||||
|
options.model = OPENAI_API_MODEL
|
||||||
|
|
||||||
if (isNotEmptyString(process.env.API_REVERSE_PROXY))
|
if (isNotEmptyString(process.env.API_REVERSE_PROXY))
|
||||||
options.apiReverseProxyUrl = process.env.API_REVERSE_PROXY
|
options.apiReverseProxyUrl = process.env.API_REVERSE_PROXY
|
||||||
@@ -67,17 +85,19 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
async function chatReplyProcess(
|
async function chatReplyProcess(options: RequestOptions) {
|
||||||
message: string,
|
const { message, lastContext, process, systemMessage } = options
|
||||||
lastContext?: { conversationId?: string; parentMessageId?: string },
|
|
||||||
process?: (chat: ChatMessage) => void,
|
|
||||||
) {
|
|
||||||
try {
|
try {
|
||||||
let options: SendMessageOptions = { timeoutMs }
|
let options: SendMessageOptions = { timeoutMs }
|
||||||
|
|
||||||
if (lastContext) {
|
if (apiModel === 'ChatGPTAPI') {
|
||||||
|
if (isNotEmptyString(systemMessage))
|
||||||
|
options.systemMessage = systemMessage
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lastContext != null) {
|
||||||
if (apiModel === 'ChatGPTAPI')
|
if (apiModel === 'ChatGPTAPI')
|
||||||
options = { parentMessageId: lastContext.parentMessageId }
|
options.parentMessageId = lastContext.parentMessageId
|
||||||
else
|
else
|
||||||
options = { ...lastContext }
|
options = { ...lastContext }
|
||||||
}
|
}
|
||||||
@@ -102,15 +122,18 @@ async function chatReplyProcess(
|
|||||||
|
|
||||||
async function fetchBalance() {
|
async function fetchBalance() {
|
||||||
const OPENAI_API_KEY = process.env.OPENAI_API_KEY
|
const OPENAI_API_KEY = process.env.OPENAI_API_KEY
|
||||||
|
const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL
|
||||||
|
|
||||||
if (!isNotEmptyString(OPENAI_API_KEY))
|
if (!isNotEmptyString(OPENAI_API_KEY))
|
||||||
return Promise.resolve('-')
|
return Promise.resolve('-')
|
||||||
|
|
||||||
|
const API_BASE_URL = isNotEmptyString(OPENAI_API_BASE_URL)
|
||||||
|
? OPENAI_API_BASE_URL
|
||||||
|
: 'https://api.openai.com'
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const headers = {
|
const headers = { 'Content-Type': 'application/json', 'Authorization': `Bearer ${OPENAI_API_KEY}` }
|
||||||
'Content-Type': 'application/json',
|
const response = await axios.get(`${API_BASE_URL}/dashboard/billing/credit_grants`, { headers })
|
||||||
'Authorization': `Bearer ${OPENAI_API_KEY}`,
|
|
||||||
}
|
|
||||||
const response = await axios.get('https://api.openai.com/dashboard/billing/credit_grants', { headers })
|
|
||||||
const balance = response.data.total_available ?? 0
|
const balance = response.data.total_available ?? 0
|
||||||
return Promise.resolve(balance.toFixed(3))
|
return Promise.resolve(balance.toFixed(3))
|
||||||
}
|
}
|
||||||
|
|||||||
8
service/src/chatgpt/types.ts
Normal file
8
service/src/chatgpt/types.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import type { ChatMessage } from 'chatgpt'
|
||||||
|
|
||||||
|
export interface RequestOptions {
|
||||||
|
message: string
|
||||||
|
lastContext?: { conversationId?: string; parentMessageId?: string }
|
||||||
|
process?: (chat: ChatMessage) => void
|
||||||
|
systemMessage?: string
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import type { ChatContext, ChatMessage } from './chatgpt'
|
import type { RequestProps } from './types'
|
||||||
|
import type { ChatMessage } from './chatgpt'
|
||||||
import { chatConfig, chatReplyProcess, currentModel } from './chatgpt'
|
import { chatConfig, chatReplyProcess, currentModel } from './chatgpt'
|
||||||
import { auth } from './middleware/auth'
|
import { auth } from './middleware/auth'
|
||||||
|
import { limiter } from './middleware/limiter'
|
||||||
import { isNotEmptyString } from './utils/is'
|
import { isNotEmptyString } from './utils/is'
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
@@ -17,15 +19,20 @@ app.all('*', (_, res, next) => {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/chat-process', auth, async (req, res) => {
|
router.post('/chat-process', [auth, limiter], async (req, res) => {
|
||||||
res.setHeader('Content-type', 'application/octet-stream')
|
res.setHeader('Content-type', 'application/octet-stream')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { prompt, options = {} } = req.body as { prompt: string; options?: ChatContext }
|
const { prompt, options = {}, systemMessage } = req.body as RequestProps
|
||||||
let firstChunk = true
|
let firstChunk = true
|
||||||
await chatReplyProcess(prompt, options, (chat: ChatMessage) => {
|
await chatReplyProcess({
|
||||||
res.write(firstChunk ? JSON.stringify(chat) : `\n${JSON.stringify(chat)}`)
|
message: prompt,
|
||||||
firstChunk = false
|
lastContext: options,
|
||||||
|
process: (chat: ChatMessage) => {
|
||||||
|
res.write(firstChunk ? JSON.stringify(chat) : `\n${JSON.stringify(chat)}`)
|
||||||
|
firstChunk = false
|
||||||
|
},
|
||||||
|
systemMessage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
@@ -36,7 +43,7 @@ router.post('/chat-process', auth, async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
router.post('/config', async (req, res) => {
|
router.post('/config', auth, async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const response = await chatConfig()
|
const response = await chatConfig()
|
||||||
res.send(response)
|
res.send(response)
|
||||||
|
|||||||
19
service/src/middleware/limiter.ts
Normal file
19
service/src/middleware/limiter.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { rateLimit } from 'express-rate-limit'
|
||||||
|
import { isNotEmptyString } from '../utils/is'
|
||||||
|
|
||||||
|
const MAX_REQUEST_PER_HOUR = process.env.MAX_REQUEST_PER_HOUR
|
||||||
|
|
||||||
|
const maxCount = (isNotEmptyString(MAX_REQUEST_PER_HOUR) && !isNaN(Number(MAX_REQUEST_PER_HOUR)))
|
||||||
|
? parseInt(MAX_REQUEST_PER_HOUR)
|
||||||
|
: 0 // 0 means unlimited
|
||||||
|
|
||||||
|
const limiter = rateLimit({
|
||||||
|
windowMs: 60 * 60 * 1000, // Maximum number of accesses within an hour
|
||||||
|
max: maxCount,
|
||||||
|
statusCode: 200, // 200 means success,but the message is 'Too many request from this IP in 1 hour'
|
||||||
|
message: async (req, res) => {
|
||||||
|
res.send({ status: 'Fail', message: 'Too many request from this IP in 1 hour', data: null })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export { limiter }
|
||||||
@@ -1,5 +1,11 @@
|
|||||||
import type { FetchFn } from 'chatgpt'
|
import type { FetchFn } from 'chatgpt'
|
||||||
|
|
||||||
|
export interface RequestProps {
|
||||||
|
prompt: string
|
||||||
|
options?: ChatContext
|
||||||
|
systemMessage: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface ChatContext {
|
export interface ChatContext {
|
||||||
conversationId?: string
|
conversationId?: string
|
||||||
parentMessageId?: string
|
parentMessageId?: string
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
|
import type { AxiosProgressEvent, GenericAbortSignal } from 'axios'
|
||||||
import { post } from '@/utils/request'
|
import { post } from '@/utils/request'
|
||||||
|
import { useSettingStore } from '@/store'
|
||||||
|
|
||||||
export function fetchChatAPI<T = any>(
|
export function fetchChatAPI<T = any>(
|
||||||
prompt: string,
|
prompt: string,
|
||||||
@@ -26,9 +27,11 @@ export function fetchChatAPIProcess<T = any>(
|
|||||||
signal?: GenericAbortSignal
|
signal?: GenericAbortSignal
|
||||||
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void },
|
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void },
|
||||||
) {
|
) {
|
||||||
|
const settingStore = useSettingStore()
|
||||||
|
|
||||||
return post<T>({
|
return post<T>({
|
||||||
url: '/chat-process',
|
url: '/chat-process',
|
||||||
data: { prompt: params.prompt, options: params.options },
|
data: { prompt: params.prompt, options: params.options, systemMessage: settingStore.systemMessage },
|
||||||
signal: params.signal,
|
signal: params.signal,
|
||||||
onDownloadProgress: params.onDownloadProgress,
|
onDownloadProgress: params.onDownloadProgress,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
[
|
[
|
||||||
{
|
|
||||||
"key": "chatgpt-prompt-collection",
|
|
||||||
"desc": "Nothing1024收集整理的prompts",
|
|
||||||
"downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json",
|
|
||||||
"url": "https://github.com/Nothing1024/chatgpt-prompt-collection"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"key": "awesome-chatgpt-prompts-zh",
|
"key": "awesome-chatgpt-prompts-zh",
|
||||||
"desc": "ChatGPT 中文调教指南",
|
"desc": "ChatGPT 中文调教指南",
|
||||||
"downloadUrl": "https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json",
|
"downloadUrl": "https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json",
|
||||||
"url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh"
|
"url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "awesome-chatgpt-prompts-zh-TW",
|
||||||
|
"desc": "ChatGPT 中文調教指南 (透過 OpenAI / OpenCC 協助,從簡體中文轉換為繁體中文的版本)",
|
||||||
|
"downloadUrl": "https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh-TW.json",
|
||||||
|
"url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import type { DataTableColumns } from 'naive-ui'
|
import type { DataTableColumns } from 'naive-ui'
|
||||||
import { computed, h, ref, watch } from 'vue'
|
import { computed, h, ref, watch } from 'vue'
|
||||||
import { NButton, NCard, NDataTable, NDivider, NInput, NLayoutContent, NList, NListItem, NModal, NPopconfirm, NSpace, NTabPane, NTabs, NThing, useMessage } from 'naive-ui'
|
import { NButton, NCard, NDataTable, NDivider, NInput, NList, NListItem, NModal, NPopconfirm, NSpace, NTabPane, NTabs, NThing, useMessage } from 'naive-ui'
|
||||||
import PromptRecommend from '../../../assets/recommend.json'
|
import PromptRecommend from '../../../assets/recommend.json'
|
||||||
import { SvgIcon } from '..'
|
import { SvgIcon } from '..'
|
||||||
import { usePromptStore } from '@/store'
|
import { usePromptStore } from '@/store'
|
||||||
@@ -408,17 +408,12 @@ const dataSource = computed(() => {
|
|||||||
</NButton>
|
</NButton>
|
||||||
</div>
|
</div>
|
||||||
<NDivider />
|
<NDivider />
|
||||||
<NLayoutContent
|
<div class="max-h-[360px] overflow-y-auto space-y-4">
|
||||||
style="height: 360px"
|
|
||||||
content-style="background: none;"
|
|
||||||
:native-scrollbar="false"
|
|
||||||
>
|
|
||||||
<NCard
|
<NCard
|
||||||
v-for="info in promptRecommendList"
|
v-for="info in promptRecommendList"
|
||||||
:key="info.key" :title="info.key"
|
:key="info.key" :title="info.key"
|
||||||
style="margin: 5px;"
|
|
||||||
embedded
|
|
||||||
:bordered="true"
|
:bordered="true"
|
||||||
|
embedded
|
||||||
>
|
>
|
||||||
<p
|
<p
|
||||||
class="overflow-hidden text-ellipsis whitespace-nowrap"
|
class="overflow-hidden text-ellipsis whitespace-nowrap"
|
||||||
@@ -442,7 +437,7 @@ const dataSource = computed(() => {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</NCard>
|
</NCard>
|
||||||
</NLayoutContent>
|
</div>
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
</NTabs>
|
</NTabs>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
46
src/components/common/Setting/Advanced.vue
Normal file
46
src/components/common/Setting/Advanced.vue
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { NButton, NInput, useMessage } from 'naive-ui'
|
||||||
|
import { useSettingStore } from '@/store'
|
||||||
|
import type { SettingsState } from '@/store/modules/settings/helper'
|
||||||
|
import { t } from '@/locales'
|
||||||
|
|
||||||
|
const settingStore = useSettingStore()
|
||||||
|
|
||||||
|
const ms = useMessage()
|
||||||
|
|
||||||
|
const systemMessage = ref(settingStore.systemMessage ?? '')
|
||||||
|
|
||||||
|
function updateSettings(options: Partial<SettingsState>) {
|
||||||
|
settingStore.updateSetting(options)
|
||||||
|
ms.success(t('common.success'))
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleReset() {
|
||||||
|
settingStore.resetSetting()
|
||||||
|
ms.success(t('common.success'))
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
|
</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.role') }}</span>
|
||||||
|
<div class="flex-1">
|
||||||
|
<NInput v-model:value="systemMessage" placeholder="" />
|
||||||
|
</div>
|
||||||
|
<NButton size="tiny" text type="primary" @click="updateSettings({ systemMessage })">
|
||||||
|
{{ $t('common.save') }}
|
||||||
|
</NButton>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center space-x-4">
|
||||||
|
<span class="flex-shrink-0 w-[100px]"> </span>
|
||||||
|
<NButton size="small" @click="handleReset">
|
||||||
|
{{ $t('common.reset') }}
|
||||||
|
</NButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
@@ -150,7 +150,6 @@ function handleImportButtonClick(): void {
|
|||||||
{{ $t('common.save') }}
|
{{ $t('common.save') }}
|
||||||
</NButton>
|
</NButton>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="flex items-center space-x-4"
|
class="flex items-center space-x-4"
|
||||||
:class="isMobile && 'items-start'"
|
:class="isMobile && 'items-start'"
|
||||||
|
|||||||
@@ -2,13 +2,11 @@
|
|||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { NModal, NTabPane, NTabs } from 'naive-ui'
|
import { NModal, NTabPane, NTabs } from 'naive-ui'
|
||||||
import General from './General.vue'
|
import General from './General.vue'
|
||||||
|
import Advanced from './Advanced.vue'
|
||||||
import About from './About.vue'
|
import About from './About.vue'
|
||||||
|
import { useAuthStore } from '@/store'
|
||||||
import { SvgIcon } from '@/components/common'
|
import { SvgIcon } from '@/components/common'
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
|
||||||
|
|
||||||
const emit = defineEmits<Emit>()
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
visible: boolean
|
visible: boolean
|
||||||
}
|
}
|
||||||
@@ -17,6 +15,14 @@ interface Emit {
|
|||||||
(e: 'update:visible', visible: boolean): void
|
(e: 'update:visible', visible: boolean): void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
|
const emit = defineEmits<Emit>()
|
||||||
|
|
||||||
|
const authStore = useAuthStore()
|
||||||
|
|
||||||
|
const isChatGPTAPI = computed<boolean>(() => !!authStore.isChatGPTAPI)
|
||||||
|
|
||||||
const active = ref('General')
|
const active = ref('General')
|
||||||
|
|
||||||
const show = computed({
|
const show = computed({
|
||||||
@@ -42,6 +48,15 @@ const show = computed({
|
|||||||
<General />
|
<General />
|
||||||
</div>
|
</div>
|
||||||
</NTabPane>
|
</NTabPane>
|
||||||
|
<NTabPane v-if="isChatGPTAPI" name="Advanced" tab="Advanced">
|
||||||
|
<template #tab>
|
||||||
|
<SvgIcon class="text-lg" icon="ri:equalizer-line" />
|
||||||
|
<span class="ml-2">{{ $t('setting.advanced') }}</span>
|
||||||
|
</template>
|
||||||
|
<div class="min-h-[100px]">
|
||||||
|
<Advanced />
|
||||||
|
</div>
|
||||||
|
</NTabPane>
|
||||||
<NTabPane name="Config" tab="Config">
|
<NTabPane name="Config" tab="Config">
|
||||||
<template #tab>
|
<template #tab>
|
||||||
<SvgIcon class="text-lg" icon="ri:list-settings-line" />
|
<SvgIcon class="text-lg" icon="ri:list-settings-line" />
|
||||||
|
|||||||
@@ -46,14 +46,18 @@ export default {
|
|||||||
deleteMessageConfirm: 'Are you sure to delete this message?',
|
deleteMessageConfirm: 'Are you sure to delete this message?',
|
||||||
deleteHistoryConfirm: 'Are you sure to clear this history?',
|
deleteHistoryConfirm: 'Are you sure to clear this history?',
|
||||||
clearHistoryConfirm: 'Are you sure to clear chat history?',
|
clearHistoryConfirm: 'Are you sure to clear chat history?',
|
||||||
|
preview: 'Preview',
|
||||||
|
showRawText: 'Show as raw text',
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
setting: 'Setting',
|
setting: 'Setting',
|
||||||
general: 'General',
|
general: 'General',
|
||||||
|
advanced: 'Advanced',
|
||||||
config: 'Config',
|
config: 'Config',
|
||||||
avatarLink: 'Avatar Link',
|
avatarLink: 'Avatar Link',
|
||||||
name: 'Name',
|
name: 'Name',
|
||||||
description: 'Description',
|
description: 'Description',
|
||||||
|
role: 'Role',
|
||||||
resetUserInfo: 'Reset UserInfo',
|
resetUserInfo: 'Reset UserInfo',
|
||||||
chatHistory: 'ChatHistory',
|
chatHistory: 'ChatHistory',
|
||||||
theme: 'Theme',
|
theme: 'Theme',
|
||||||
|
|||||||
@@ -46,14 +46,18 @@ export default {
|
|||||||
deleteMessageConfirm: '是否删除此消息?',
|
deleteMessageConfirm: '是否删除此消息?',
|
||||||
deleteHistoryConfirm: '确定删除此记录?',
|
deleteHistoryConfirm: '确定删除此记录?',
|
||||||
clearHistoryConfirm: '确定清空聊天记录?',
|
clearHistoryConfirm: '确定清空聊天记录?',
|
||||||
|
preview: '预览',
|
||||||
|
showRawText: '显示原文',
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
setting: '设置',
|
setting: '设置',
|
||||||
general: '总览',
|
general: '总览',
|
||||||
|
advanced: '高级',
|
||||||
config: '配置',
|
config: '配置',
|
||||||
avatarLink: '头像链接',
|
avatarLink: '头像链接',
|
||||||
name: '名称',
|
name: '名称',
|
||||||
description: '描述',
|
description: '描述',
|
||||||
|
role: '角色设定',
|
||||||
resetUserInfo: '重置用户信息',
|
resetUserInfo: '重置用户信息',
|
||||||
chatHistory: '聊天记录',
|
chatHistory: '聊天记录',
|
||||||
theme: '主题',
|
theme: '主题',
|
||||||
|
|||||||
@@ -46,14 +46,18 @@ export default {
|
|||||||
deleteMessageConfirm: '是否刪除此訊息?',
|
deleteMessageConfirm: '是否刪除此訊息?',
|
||||||
deleteHistoryConfirm: '確定刪除此紀錄?',
|
deleteHistoryConfirm: '確定刪除此紀錄?',
|
||||||
clearHistoryConfirm: '確定清除紀錄?',
|
clearHistoryConfirm: '確定清除紀錄?',
|
||||||
|
preview: '預覽',
|
||||||
|
showRawText: '顯示原文',
|
||||||
},
|
},
|
||||||
setting: {
|
setting: {
|
||||||
setting: '設定',
|
setting: '設定',
|
||||||
general: '總覽',
|
general: '總覽',
|
||||||
|
advanced: '高級',
|
||||||
config: '設定',
|
config: '設定',
|
||||||
avatarLink: '頭貼連結',
|
avatarLink: '頭貼連結',
|
||||||
name: '名稱',
|
name: '名稱',
|
||||||
description: '描述',
|
description: '描述',
|
||||||
|
role: '角色設定',
|
||||||
resetUserInfo: '重設使用者資訊',
|
resetUserInfo: '重設使用者資訊',
|
||||||
chatHistory: '紀錄',
|
chatHistory: '紀錄',
|
||||||
theme: '主題',
|
theme: '主題',
|
||||||
|
|||||||
@@ -9,7 +9,10 @@ export function setupPageGuard(router: Router) {
|
|||||||
const data = await authStore.getSession()
|
const data = await authStore.getSession()
|
||||||
if (String(data.auth) === 'false' && authStore.token)
|
if (String(data.auth) === 'false' && authStore.token)
|
||||||
authStore.removeToken()
|
authStore.removeToken()
|
||||||
next()
|
if (to.path === '/500')
|
||||||
|
next({ name: 'Root' })
|
||||||
|
else
|
||||||
|
next()
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if (to.path !== '/500')
|
if (to.path !== '/500')
|
||||||
|
|||||||
@@ -2,4 +2,5 @@ export * from './app'
|
|||||||
export * from './chat'
|
export * from './chat'
|
||||||
export * from './user'
|
export * from './user'
|
||||||
export * from './prompt'
|
export * from './prompt'
|
||||||
|
export * from './settings'
|
||||||
export * from './auth'
|
export * from './auth'
|
||||||
|
|||||||
27
src/store/modules/settings/helper.ts
Normal file
27
src/store/modules/settings/helper.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import { ss } from '@/utils/storage'
|
||||||
|
|
||||||
|
const LOCAL_NAME = 'settingsStorage'
|
||||||
|
|
||||||
|
export interface SettingsState {
|
||||||
|
systemMessage: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export function defaultSetting(): SettingsState {
|
||||||
|
const currentDate = new Date().toISOString().split('T')[0]
|
||||||
|
return {
|
||||||
|
systemMessage: `You are ChatGPT, a large language model trained by OpenAI. Answer as concisely as possible.\nKnowledge cutoff: 2021-09-01\nCurrent date: ${currentDate}`,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLocalState(): SettingsState {
|
||||||
|
const localSetting: SettingsState | undefined = ss.get(LOCAL_NAME)
|
||||||
|
return { ...defaultSetting(), ...localSetting }
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setLocalState(setting: SettingsState): void {
|
||||||
|
ss.set(LOCAL_NAME, setting)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeLocalState() {
|
||||||
|
ss.remove(LOCAL_NAME)
|
||||||
|
}
|
||||||
22
src/store/modules/settings/index.ts
Normal file
22
src/store/modules/settings/index.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import type { SettingsState } from './helper'
|
||||||
|
import { defaultSetting, getLocalState, removeLocalState, setLocalState } from './helper'
|
||||||
|
|
||||||
|
export const useSettingStore = defineStore('setting-store', {
|
||||||
|
state: (): SettingsState => getLocalState(),
|
||||||
|
actions: {
|
||||||
|
updateSetting(settings: Partial<SettingsState>) {
|
||||||
|
this.$state = { ...this.$state, ...settings }
|
||||||
|
this.recordState()
|
||||||
|
},
|
||||||
|
|
||||||
|
resetSetting() {
|
||||||
|
this.$state = defaultSetting()
|
||||||
|
removeLocalState()
|
||||||
|
},
|
||||||
|
|
||||||
|
recordState() {
|
||||||
|
setLocalState(this.$state)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
3
src/typings/env.d.ts
vendored
3
src/typings/env.d.ts
vendored
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
interface ImportMetaEnv {
|
interface ImportMetaEnv {
|
||||||
readonly VITE_GLOB_API_URL: string;
|
readonly VITE_GLOB_API_URL: string;
|
||||||
readonly VITE_GLOB_API_TIMEOUT: string;
|
|
||||||
readonly VITE_APP_API_BASE_URL: string;
|
readonly VITE_APP_API_BASE_URL: string;
|
||||||
|
readonly VITE_GLOB_OPEN_LONG_REPLY: string;
|
||||||
|
readonly VITE_GLOB_APP_PWA: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import MarkdownIt from 'markdown-it'
|
import MarkdownIt from 'markdown-it'
|
||||||
import mdKatex from '@traptitech/markdown-it-katex'
|
import mdKatex from '@traptitech/markdown-it-katex'
|
||||||
|
import mila from 'markdown-it-link-attributes'
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
||||||
import { t } from '@/locales'
|
import { t } from '@/locales'
|
||||||
@@ -11,6 +12,7 @@ interface Props {
|
|||||||
error?: boolean
|
error?: boolean
|
||||||
text?: string
|
text?: string
|
||||||
loading?: boolean
|
loading?: boolean
|
||||||
|
asRawText?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
@@ -31,6 +33,7 @@ const mdi = new MarkdownIt({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
mdi.use(mila, { attrs: { target: '_blank', rel: 'noopener' } })
|
||||||
mdi.use(mdKatex, { blockClass: 'katexmath-block rounded-md p-[10px]', errorColor: ' #cc0000' })
|
mdi.use(mdKatex, { blockClass: 'katexmath-block rounded-md p-[10px]', errorColor: ' #cc0000' })
|
||||||
|
|
||||||
const wrapClass = computed(() => {
|
const wrapClass = computed(() => {
|
||||||
@@ -41,13 +44,14 @@ const wrapClass = computed(() => {
|
|||||||
isMobile.value ? 'p-2' : 'px-3 py-2',
|
isMobile.value ? 'p-2' : 'px-3 py-2',
|
||||||
props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]',
|
props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]',
|
||||||
props.inversion ? 'dark:bg-[#a1dc95]' : 'dark:bg-[#1e1e20]',
|
props.inversion ? 'dark:bg-[#a1dc95]' : 'dark:bg-[#1e1e20]',
|
||||||
|
props.inversion ? 'message-request' : 'message-reply',
|
||||||
{ 'text-red-500': props.error },
|
{ 'text-red-500': props.error },
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const text = computed(() => {
|
const text = computed(() => {
|
||||||
const value = props.text ?? ''
|
const value = props.text ?? ''
|
||||||
if (!props.inversion)
|
if (!props.asRawText)
|
||||||
return mdi.render(value)
|
return mdi.render(value)
|
||||||
return value
|
return value
|
||||||
})
|
})
|
||||||
@@ -66,7 +70,10 @@ defineExpose({ textRef })
|
|||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<div ref="textRef" class="leading-relaxed break-words">
|
<div ref="textRef" class="leading-relaxed break-words">
|
||||||
<div v-if="!inversion" class="markdown-body" v-html="text" />
|
<div v-if="!inversion">
|
||||||
|
<div v-if="!asRawText" class="markdown-body" v-html="text" />
|
||||||
|
<div v-else class="whitespace-pre-wrap" v-text="text" />
|
||||||
|
</div>
|
||||||
<div v-else class="whitespace-pre-wrap" v-text="text" />
|
<div v-else class="whitespace-pre-wrap" v-text="text" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import { ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import { NDropdown } from 'naive-ui'
|
import { NDropdown } from 'naive-ui'
|
||||||
import AvatarComponent from './Avatar.vue'
|
import AvatarComponent from './Avatar.vue'
|
||||||
import TextComponent from './Text.vue'
|
import TextComponent from './Text.vue'
|
||||||
@@ -29,36 +29,60 @@ const { iconRender } = useIconRender()
|
|||||||
|
|
||||||
const textRef = ref<HTMLElement>()
|
const textRef = ref<HTMLElement>()
|
||||||
|
|
||||||
const options = [
|
const asRawText = ref(props.inversion)
|
||||||
{
|
|
||||||
label: t('chat.copy'),
|
|
||||||
key: 'copyText',
|
|
||||||
icon: iconRender({ icon: 'ri:file-copy-2-line' }),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: t('common.delete'),
|
|
||||||
key: 'delete',
|
|
||||||
icon: iconRender({ icon: 'ri:delete-bin-line' }),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
function handleSelect(key: 'copyRaw' | 'copyText' | 'delete') {
|
const messageRef = ref<HTMLElement>()
|
||||||
|
|
||||||
|
const options = computed(() => {
|
||||||
|
const common = [
|
||||||
|
{
|
||||||
|
label: t('chat.copy'),
|
||||||
|
key: 'copyText',
|
||||||
|
icon: iconRender({ icon: 'ri:file-copy-2-line' }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: t('common.delete'),
|
||||||
|
key: 'delete',
|
||||||
|
icon: iconRender({ icon: 'ri:delete-bin-line' }),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
if (!props.inversion) {
|
||||||
|
common.unshift({
|
||||||
|
label: asRawText.value ? t('chat.preview') : t('chat.showRawText'),
|
||||||
|
key: 'toggleRenderType',
|
||||||
|
icon: iconRender({ icon: asRawText.value ? 'ic:outline-code-off' : 'ic:outline-code' }),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return common
|
||||||
|
})
|
||||||
|
|
||||||
|
function handleSelect(key: 'copyText' | 'delete' | 'toggleRenderType') {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'copyText':
|
case 'copyText':
|
||||||
copyText({ text: props.text ?? '' })
|
copyText({ text: props.text ?? '' })
|
||||||
return
|
return
|
||||||
|
case 'toggleRenderType':
|
||||||
|
asRawText.value = !asRawText.value
|
||||||
|
return
|
||||||
case 'delete':
|
case 'delete':
|
||||||
emit('delete')
|
emit('delete')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRegenerate() {
|
function handleRegenerate() {
|
||||||
|
messageRef.value?.scrollIntoView()
|
||||||
emit('regenerate')
|
emit('regenerate')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex w-full mb-6 overflow-hidden" :class="[{ 'flex-row-reverse': inversion }]">
|
<div
|
||||||
|
ref="messageRef"
|
||||||
|
class="flex w-full mb-6 overflow-hidden"
|
||||||
|
:class="[{ 'flex-row-reverse': inversion }]"
|
||||||
|
>
|
||||||
<div
|
<div
|
||||||
class="flex items-center justify-center flex-shrink-0 h-8 overflow-hidden rounded-full basis-8"
|
class="flex items-center justify-center flex-shrink-0 h-8 overflow-hidden rounded-full basis-8"
|
||||||
:class="[inversion ? 'ml-2' : 'mr-2']"
|
:class="[inversion ? 'ml-2' : 'mr-2']"
|
||||||
@@ -79,6 +103,7 @@ function handleRegenerate() {
|
|||||||
:error="error"
|
:error="error"
|
||||||
:text="text"
|
:text="text"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
:as-raw-text="asRawText"
|
||||||
/>
|
/>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
<button
|
<button
|
||||||
|
|||||||
@@ -45,20 +45,29 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
color: #b3b3b3;
|
color: #b3b3b3;
|
||||||
|
|
||||||
&__copy{
|
&__copy {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-left: 0.5rem;
|
margin-left: 0.5rem;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
color: #65a665;
|
color: #65a665;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html.dark {
|
html.dark {
|
||||||
|
|
||||||
|
.message-reply {
|
||||||
|
.whitespace-pre-wrap {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
color: var(--n-text-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.highlight pre,
|
.highlight pre,
|
||||||
pre {
|
pre {
|
||||||
background-color: #282c34;
|
background-color: #282c34;
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export function useScroll(): ScrollReturn {
|
|||||||
const scrollToBottomIfAtBottom = async () => {
|
const scrollToBottomIfAtBottom = async () => {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
if (scrollRef.value) {
|
if (scrollRef.value) {
|
||||||
const threshold = 50 // 阈值,表示滚动条到底部的距离阈值
|
const threshold = 100 // 阈值,表示滚动条到底部的距离阈值
|
||||||
const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight
|
const distanceToBottom = scrollRef.value.scrollHeight - scrollRef.value.scrollTop - scrollRef.value.clientHeight
|
||||||
if (distanceToBottom <= threshold)
|
if (distanceToBottom <= threshold)
|
||||||
scrollRef.value.scrollTop = scrollRef.value.scrollHeight
|
scrollRef.value.scrollTop = scrollRef.value.scrollHeight
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
|
import type { Ref } from 'vue'
|
||||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import { storeToRefs } from 'pinia'
|
import { storeToRefs } from 'pinia'
|
||||||
@@ -30,7 +31,7 @@ useCopyCode()
|
|||||||
|
|
||||||
const { isMobile } = useBasicLayout()
|
const { isMobile } = useBasicLayout()
|
||||||
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
|
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
|
||||||
const { scrollRef, scrollToBottom } = useScroll()
|
const { scrollRef, scrollToBottom, scrollToBottomIfAtBottom } = useScroll()
|
||||||
const { usingContext, toggleUsingContext } = useUsingContext()
|
const { usingContext, toggleUsingContext } = useUsingContext()
|
||||||
|
|
||||||
const { uuid } = route.params as { uuid: string }
|
const { uuid } = route.params as { uuid: string }
|
||||||
@@ -40,12 +41,20 @@ const conversationList = computed(() => dataSources.value.filter(item => (!item.
|
|||||||
|
|
||||||
const prompt = ref<string>('')
|
const prompt = ref<string>('')
|
||||||
const loading = ref<boolean>(false)
|
const loading = ref<boolean>(false)
|
||||||
|
const inputRef = ref<Ref | null>(null)
|
||||||
|
|
||||||
// 添加PromptStore
|
// 添加PromptStore
|
||||||
const promptStore = usePromptStore()
|
const promptStore = usePromptStore()
|
||||||
|
|
||||||
// 使用storeToRefs,保证store修改后,联想部分能够重新渲染
|
// 使用storeToRefs,保证store修改后,联想部分能够重新渲染
|
||||||
const { promptList: promptTemplate } = storeToRefs<any>(promptStore)
|
const { promptList: promptTemplate } = storeToRefs<any>(promptStore)
|
||||||
|
|
||||||
|
// 未知原因刷新页面,loading 状态不会重置,手动重置
|
||||||
|
dataSources.value.forEach((item, index) => {
|
||||||
|
if (item.loading)
|
||||||
|
updateChatSome(+uuid, index, { loading: false })
|
||||||
|
})
|
||||||
|
|
||||||
function handleSubmit() {
|
function handleSubmit() {
|
||||||
onConversation()
|
onConversation()
|
||||||
}
|
}
|
||||||
@@ -108,7 +117,7 @@ async function onConversation() {
|
|||||||
const xhr = event.target
|
const xhr = event.target
|
||||||
const { responseText } = xhr
|
const { responseText } = xhr
|
||||||
// Always process the final line
|
// Always process the final line
|
||||||
const lastIndex = responseText.lastIndexOf('\n')
|
const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2)
|
||||||
let chunk = responseText
|
let chunk = responseText
|
||||||
if (lastIndex !== -1)
|
if (lastIndex !== -1)
|
||||||
chunk = responseText.substring(lastIndex)
|
chunk = responseText.substring(lastIndex)
|
||||||
@@ -135,7 +144,7 @@ async function onConversation() {
|
|||||||
return fetchChatAPIOnce()
|
return fetchChatAPIOnce()
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToBottom()
|
scrollToBottomIfAtBottom()
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
//
|
//
|
||||||
@@ -157,7 +166,7 @@ async function onConversation() {
|
|||||||
loading: false,
|
loading: false,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
scrollToBottom()
|
scrollToBottomIfAtBottom()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +198,7 @@ async function onConversation() {
|
|||||||
requestOptions: { prompt: message, options: { ...options } },
|
requestOptions: { prompt: message, options: { ...options } },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
scrollToBottom()
|
scrollToBottomIfAtBottom()
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
@@ -238,7 +247,7 @@ async function onRegenerate(index: number) {
|
|||||||
const xhr = event.target
|
const xhr = event.target
|
||||||
const { responseText } = xhr
|
const { responseText } = xhr
|
||||||
// Always process the final line
|
// Always process the final line
|
||||||
const lastIndex = responseText.lastIndexOf('\n')
|
const lastIndex = responseText.lastIndexOf('\n', responseText.length - 2)
|
||||||
let chunk = responseText
|
let chunk = responseText
|
||||||
if (lastIndex !== -1)
|
if (lastIndex !== -1)
|
||||||
chunk = responseText.substring(lastIndex)
|
chunk = responseText.substring(lastIndex)
|
||||||
@@ -445,6 +454,8 @@ const footerClass = computed(() => {
|
|||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
|
if (inputRef.value)
|
||||||
|
inputRef.value?.focus()
|
||||||
})
|
})
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
@@ -525,6 +536,7 @@ onUnmounted(() => {
|
|||||||
<NAutoComplete v-model:value="prompt" :options="searchOptions" :render-label="renderOption">
|
<NAutoComplete v-model:value="prompt" :options="searchOptions" :render-label="renderOption">
|
||||||
<template #default="{ handleInput, handleBlur, handleFocus }">
|
<template #default="{ handleInput, handleBlur, handleFocus }">
|
||||||
<NInput
|
<NInput
|
||||||
|
ref="inputRef"
|
||||||
v-model:value="prompt"
|
v-model:value="prompt"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ const collapsed = computed(() => appStore.siderCollapsed)
|
|||||||
|
|
||||||
function handleAdd() {
|
function handleAdd() {
|
||||||
chatStore.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
|
chatStore.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
|
||||||
|
if (isMobile.value)
|
||||||
|
appStore.setSiderCollapsed(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpdateCollapsed() {
|
function handleUpdateCollapsed() {
|
||||||
|
|||||||
9
start.cmd
Normal file
9
start.cmd
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
cd ./service
|
||||||
|
start pnpm start > service.log &
|
||||||
|
echo "Start service complete!"
|
||||||
|
|
||||||
|
|
||||||
|
cd ..
|
||||||
|
echo "" > front.log
|
||||||
|
start pnpm dev > front.log &
|
||||||
|
echo "Start front complete!"
|
||||||
@@ -1,8 +1,26 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import type { PluginOption } from 'vite'
|
||||||
import { defineConfig, loadEnv } from 'vite'
|
import { defineConfig, loadEnv } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
import { VitePWA } from 'vite-plugin-pwa'
|
import { VitePWA } from 'vite-plugin-pwa'
|
||||||
|
|
||||||
|
function setupPlugins(env: ImportMetaEnv): PluginOption[] {
|
||||||
|
return [
|
||||||
|
vue(),
|
||||||
|
env.VITE_GLOB_APP_PWA === 'true' && VitePWA({
|
||||||
|
injectRegister: 'auto',
|
||||||
|
manifest: {
|
||||||
|
name: 'chatGPT',
|
||||||
|
short_name: 'chatGPT',
|
||||||
|
icons: [
|
||||||
|
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
|
||||||
|
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig((env) => {
|
export default defineConfig((env) => {
|
||||||
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
|
const viteEnv = loadEnv(env.mode, process.cwd()) as unknown as ImportMetaEnv
|
||||||
|
|
||||||
@@ -12,20 +30,7 @@ export default defineConfig((env) => {
|
|||||||
'@': path.resolve(process.cwd(), 'src'),
|
'@': path.resolve(process.cwd(), 'src'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: setupPlugins(viteEnv),
|
||||||
vue(),
|
|
||||||
VitePWA({
|
|
||||||
injectRegister: 'auto',
|
|
||||||
manifest: {
|
|
||||||
name: 'chatGPT',
|
|
||||||
short_name: 'chatGPT',
|
|
||||||
icons: [
|
|
||||||
{ src: 'pwa-192x192.png', sizes: '192x192', type: 'image/png' },
|
|
||||||
{ src: 'pwa-512x512.png', sizes: '512x512', type: 'image/png' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
server: {
|
server: {
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
port: 1002,
|
port: 1002,
|
||||||
|
|||||||
Reference in New Issue
Block a user