mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-29 09:53:44 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
42e320fe35 | ||
![]() |
94e23bb916 | ||
![]() |
21fb4f817c | ||
![]() |
2c509c329f | ||
![]() |
4769c31d09 | ||
![]() |
89712aada7 | ||
![]() |
3e9db49aad | ||
![]() |
2dcd292dd4 | ||
![]() |
90f6989445 | ||
![]() |
1406292405 | ||
![]() |
628187f5c3 | ||
![]() |
cc91e95eed | ||
![]() |
abbdcf9c51 | ||
![]() |
b6fd9ae766 | ||
![]() |
1e2f893ef6 |
16
.github/workflows/build_docker.yml
vendored
16
.github/workflows/build_docker.yml
vendored
@@ -3,6 +3,8 @@ name: build_docker
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [main]
|
branches: [main]
|
||||||
|
release:
|
||||||
|
types: [created] # 表示在创建新的 Release 时触发
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_docker:
|
build_docker:
|
||||||
@@ -11,11 +13,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
- name: Docker meta
|
|
||||||
id: meta
|
- run: |
|
||||||
uses: docker/metadata-action@v4
|
echo "本次构建的版本为:${GITHUB_REF_NAME} (但是这个变量目前上下文中无法获取到)"
|
||||||
with:
|
echo 本次构建的版本为:${{ github.ref_name }}
|
||||||
images: chenzhaoyu94/chatgpt-web
|
env
|
||||||
|
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v2
|
uses: docker/setup-qemu-action@v2
|
||||||
@@ -32,6 +34,8 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
push: true
|
push: true
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
platforms: linux/amd64,linux/arm64
|
platforms: linux/amd64,linux/arm64
|
||||||
|
tags: |
|
||||||
|
${{ secrets.DOCKERHUB_USERNAME }}/chatgpt-web:${{ github.ref_name }}
|
||||||
|
${{ secrets.DOCKERHUB_USERNAME }}/chatgpt-web:latest
|
||||||
|
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -29,6 +29,7 @@
|
|||||||
"dockerhub",
|
"dockerhub",
|
||||||
"esno",
|
"esno",
|
||||||
"GPTAPI",
|
"GPTAPI",
|
||||||
|
"hljs",
|
||||||
"iconify",
|
"iconify",
|
||||||
"logprobs",
|
"logprobs",
|
||||||
"nodata",
|
"nodata",
|
||||||
|
78
CHANGELOG.md
78
CHANGELOG.md
@@ -1,3 +1,81 @@
|
|||||||
|
## 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
|
## v2.7.0
|
||||||
|
|
||||||
`2023-02-23`
|
`2023-02-23`
|
||||||
|
30
README.md
30
README.md
@@ -1,9 +1,9 @@
|
|||||||
# ChatGPT Web
|
# ChatGPT Web
|
||||||
|
|
||||||
> 使用 `express` 和 `vue3` 搭建的支持 `ChatGPT` 双模型演示网页
|
> 声明:此项目只发布于 Github,基于 MIT 协议,免费且作为开源学习使用。并且不会有任何形式的卖号、付费服务、讨论群、讨论组等行为。谨防受骗。
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||
|
|
||||||
- [ChatGPT Web](#chatgpt-web)
|
- [ChatGPT Web](#chatgpt-web)
|
||||||
- [介绍](#介绍)
|
- [介绍](#介绍)
|
||||||
@@ -30,6 +30,7 @@
|
|||||||
- [前端网页](#前端网页-1)
|
- [前端网页](#前端网页-1)
|
||||||
- [常见问题](#常见问题)
|
- [常见问题](#常见问题)
|
||||||
- [参与贡献](#参与贡献)
|
- [参与贡献](#参与贡献)
|
||||||
|
- [赞助](#赞助)
|
||||||
- [License](#license)
|
- [License](#license)
|
||||||
## 介绍
|
## 介绍
|
||||||
|
|
||||||
@@ -38,14 +39,14 @@
|
|||||||
| 方式 | 免费? | 可靠性 | 质量 |
|
| 方式 | 免费? | 可靠性 | 质量 |
|
||||||
| ---- | ---- | ---- | ---- |
|
| ---- | ---- | ---- | ---- |
|
||||||
| `ChatGPTAPI(GPT-3)` | 否 | 可靠 | 较笨 |
|
| `ChatGPTAPI(GPT-3)` | 否 | 可靠 | 较笨 |
|
||||||
| `ChatGPTUnofficialProxyAPI(网页 accessToken)` | 是 | 不可靠 | 聪明 |
|
| `ChatGPTUnofficialProxyAPI(网页 accessToken)` | 是 | 相对不可靠 | 聪明 |
|
||||||
|
|
||||||
***Note:*** 网页 `accessToken` 存在大约 8 小时,而且国内地区网络问题更推荐使用 `GPT-3` 的方式
|
|
||||||
|
|
||||||
对比:
|
对比:
|
||||||
1. `ChatGPTAPI` 使用 `text-davinci-003` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型)
|
1. `ChatGPTAPI` 使用 `text-davinci-003` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型)
|
||||||
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(使用真实的的`ChatGPT`,非常轻量级,但依赖于第三方服务器,并且有速率限制)
|
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(使用真实的的`ChatGPT`,非常轻量级,但依赖于第三方服务器,并且有速率限制)
|
||||||
|
|
||||||
|
[查看详情](https://github.com/Chanzhaoyu/chatgpt-web/issues/138)
|
||||||
|
|
||||||
切换方式:
|
切换方式:
|
||||||
1. 进入 `service/.env` 文件
|
1. 进入 `service/.env` 文件
|
||||||
2. 使用 `OpenAI API Key` 请填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)
|
2. 使用 `OpenAI API Key` 请填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)
|
||||||
@@ -173,7 +174,7 @@ version: '3'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
app:
|
app:
|
||||||
image: chenzhaoyu94/chatgpt-web:main
|
image: chenzhaoyu94/chatgpt-web # 总是使用latest,更新时重新pull该tag镜像即可
|
||||||
ports:
|
ports:
|
||||||
- 3002:3002
|
- 3002:3002
|
||||||
environment:
|
environment:
|
||||||
@@ -257,5 +258,20 @@ A: `vscode` 请安装项目推荐插件,或手动安装 `Eslint` 插件。
|
|||||||
<img src="https://contrib.rocks/image?repo=Chanzhaoyu/chatgpt-web" />
|
<img src="https://contrib.rocks/image?repo=Chanzhaoyu/chatgpt-web" />
|
||||||
</a>
|
</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
|
## License
|
||||||
MIT © [ChenZhaoYu](./license)
|
MIT © [ChenZhaoYu](./license)
|
||||||
|
@@ -6,9 +6,9 @@ export function createViteProxy(isOpenProxy: boolean, viteEnv: ImportMetaEnv) {
|
|||||||
|
|
||||||
const proxy: Record<string, string | ProxyOptions> = {
|
const proxy: Record<string, string | ProxyOptions> = {
|
||||||
'/api': {
|
'/api': {
|
||||||
target: viteEnv.VITE_GLOB_API_URL,
|
target: viteEnv.VITE_APP_API_BASE_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: path => path.replace(/^\/api/, ''),
|
rewrite: path => path.replace('/api/', '/'),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
docs/alipay.png
Normal file
BIN
docs/alipay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
BIN
docs/c1-2.8.0.png
Normal file
BIN
docs/c1-2.8.0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 123 KiB |
BIN
docs/c1.png
Normal file
BIN
docs/c1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 410 KiB |
BIN
docs/c2-2.8.0.png
Normal file
BIN
docs/c2-2.8.0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 396 KiB |
BIN
docs/c2.png
Normal file
BIN
docs/c2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
BIN
docs/wechat.png
Normal file
BIN
docs/wechat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 KiB |
@@ -1,6 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="zh-cmn-Hans">
|
<html lang="zh-cmn-Hans">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||||
@@ -9,7 +8,7 @@
|
|||||||
<title>ChatGPT Web</title>
|
<title>ChatGPT Web</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body class="dark:bg-black">
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<style>
|
<style>
|
||||||
.loading-wrap {
|
.loading-wrap {
|
||||||
@@ -61,6 +60,12 @@
|
|||||||
transform: translateX(100%);
|
transform: translateX(100%);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
body {
|
||||||
|
background: #121212;
|
||||||
|
}
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
<div class="loading-wrap">
|
<div class="loading-wrap">
|
||||||
<div class="balls">
|
<div class="balls">
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chatgpt-web",
|
"name": "chatgpt-web",
|
||||||
"version": "2.7.0",
|
"version": "2.8.3",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "ChatGPT Web",
|
"description": "ChatGPT Web",
|
||||||
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
||||||
|
@@ -8,4 +8,4 @@ OPENAI_ACCESS_TOKEN=
|
|||||||
API_REVERSE_PROXY=
|
API_REVERSE_PROXY=
|
||||||
|
|
||||||
# timeout
|
# timeout
|
||||||
TIMEOUT_MS=60000
|
TIMEOUT_MS=100000
|
||||||
|
@@ -28,7 +28,9 @@
|
|||||||
"dotenv": "^16.0.3",
|
"dotenv": "^16.0.3",
|
||||||
"esno": "^0.16.3",
|
"esno": "^0.16.3",
|
||||||
"express": "^4.18.2",
|
"express": "^4.18.2",
|
||||||
"isomorphic-fetch": "^3.0.0"
|
"isomorphic-fetch": "^3.0.0",
|
||||||
|
"node-fetch": "^3.3.0",
|
||||||
|
"socks-proxy-agent": "^7.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@antfu/eslint-config": "^0.35.2",
|
"@antfu/eslint-config": "^0.35.2",
|
||||||
|
82
service/pnpm-lock.yaml
generated
82
service/pnpm-lock.yaml
generated
@@ -10,7 +10,9 @@ specifiers:
|
|||||||
esno: ^0.16.3
|
esno: ^0.16.3
|
||||||
express: ^4.18.2
|
express: ^4.18.2
|
||||||
isomorphic-fetch: ^3.0.0
|
isomorphic-fetch: ^3.0.0
|
||||||
|
node-fetch: ^3.3.0
|
||||||
rimraf: ^4.1.2
|
rimraf: ^4.1.2
|
||||||
|
socks-proxy-agent: ^7.0.0
|
||||||
tsup: ^6.6.3
|
tsup: ^6.6.3
|
||||||
typescript: ^4.9.5
|
typescript: ^4.9.5
|
||||||
|
|
||||||
@@ -20,6 +22,8 @@ dependencies:
|
|||||||
esno: 0.16.3
|
esno: 0.16.3
|
||||||
express: 4.18.2
|
express: 4.18.2
|
||||||
isomorphic-fetch: 3.0.0
|
isomorphic-fetch: 3.0.0
|
||||||
|
node-fetch: 3.3.0
|
||||||
|
socks-proxy-agent: 7.0.0
|
||||||
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@antfu/eslint-config': 0.35.2_7kw3g6rralp5ps6mg3uyzz6azm
|
'@antfu/eslint-config': 0.35.2_7kw3g6rralp5ps6mg3uyzz6azm
|
||||||
@@ -641,6 +645,15 @@ packages:
|
|||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/agent-base/6.0.2:
|
||||||
|
resolution: {integrity: sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==}
|
||||||
|
engines: {node: '>= 6.0.0'}
|
||||||
|
dependencies:
|
||||||
|
debug: 4.3.4
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- supports-color
|
||||||
|
dev: false
|
||||||
|
|
||||||
/ajv-formats/2.1.1:
|
/ajv-formats/2.1.1:
|
||||||
resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==}
|
resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==}
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
@@ -999,6 +1012,11 @@ packages:
|
|||||||
hasBin: true
|
hasBin: true
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/data-uri-to-buffer/4.0.1:
|
||||||
|
resolution: {integrity: sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==}
|
||||||
|
engines: {node: '>= 12'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/debounce-fn/5.1.2:
|
/debounce-fn/5.1.2:
|
||||||
resolution: {integrity: sha512-Sr4SdOZ4vw6eQDvPYNxHogvrxmCIld/VenC5JbNrFwMiwd7lY/Z18ZFfo+EWNG4DD9nFlAujWAo/wGuOPHmy5A==}
|
resolution: {integrity: sha512-Sr4SdOZ4vw6eQDvPYNxHogvrxmCIld/VenC5JbNrFwMiwd7lY/Z18ZFfo+EWNG4DD9nFlAujWAo/wGuOPHmy5A==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
@@ -1038,7 +1056,6 @@ packages:
|
|||||||
optional: true
|
optional: true
|
||||||
dependencies:
|
dependencies:
|
||||||
ms: 2.1.2
|
ms: 2.1.2
|
||||||
dev: true
|
|
||||||
|
|
||||||
/deep-is/0.1.4:
|
/deep-is/0.1.4:
|
||||||
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
|
resolution: {integrity: sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==}
|
||||||
@@ -1748,6 +1765,14 @@ packages:
|
|||||||
reusify: 1.0.4
|
reusify: 1.0.4
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/fetch-blob/3.2.0:
|
||||||
|
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
|
||||||
|
engines: {node: ^12.20 || >= 14.13}
|
||||||
|
dependencies:
|
||||||
|
node-domexception: 1.0.0
|
||||||
|
web-streams-polyfill: 3.2.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
/file-entry-cache/6.0.1:
|
/file-entry-cache/6.0.1:
|
||||||
resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}
|
resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==}
|
||||||
engines: {node: ^10.12.0 || >=12.0.0}
|
engines: {node: ^10.12.0 || >=12.0.0}
|
||||||
@@ -1819,6 +1844,13 @@ packages:
|
|||||||
is-callable: 1.2.7
|
is-callable: 1.2.7
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/formdata-polyfill/4.0.10:
|
||||||
|
resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}
|
||||||
|
engines: {node: '>=12.20.0'}
|
||||||
|
dependencies:
|
||||||
|
fetch-blob: 3.2.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
/forwarded/0.2.0:
|
/forwarded/0.2.0:
|
||||||
resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==}
|
resolution: {integrity: sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==}
|
||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
@@ -2086,6 +2118,10 @@ packages:
|
|||||||
side-channel: 1.0.4
|
side-channel: 1.0.4
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/ip/2.0.0:
|
||||||
|
resolution: {integrity: sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/ipaddr.js/1.9.1:
|
/ipaddr.js/1.9.1:
|
||||||
resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==}
|
resolution: {integrity: sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==}
|
||||||
engines: {node: '>= 0.10'}
|
engines: {node: '>= 0.10'}
|
||||||
@@ -2509,7 +2545,6 @@ packages:
|
|||||||
|
|
||||||
/ms/2.1.2:
|
/ms/2.1.2:
|
||||||
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
|
||||||
dev: true
|
|
||||||
|
|
||||||
/ms/2.1.3:
|
/ms/2.1.3:
|
||||||
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
|
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
|
||||||
@@ -2535,6 +2570,11 @@ packages:
|
|||||||
engines: {node: '>= 0.6'}
|
engines: {node: '>= 0.6'}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/node-domexception/1.0.0:
|
||||||
|
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
|
||||||
|
engines: {node: '>=10.5.0'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/node-fetch/2.6.9:
|
/node-fetch/2.6.9:
|
||||||
resolution: {integrity: sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==}
|
resolution: {integrity: sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==}
|
||||||
engines: {node: 4.x || >=6.0.0}
|
engines: {node: 4.x || >=6.0.0}
|
||||||
@@ -2547,6 +2587,15 @@ packages:
|
|||||||
whatwg-url: 5.0.0
|
whatwg-url: 5.0.0
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/node-fetch/3.3.0:
|
||||||
|
resolution: {integrity: sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA==}
|
||||||
|
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
|
||||||
|
dependencies:
|
||||||
|
data-uri-to-buffer: 4.0.1
|
||||||
|
fetch-blob: 3.2.0
|
||||||
|
formdata-polyfill: 4.0.10
|
||||||
|
dev: false
|
||||||
|
|
||||||
/normalize-package-data/2.5.0:
|
/normalize-package-data/2.5.0:
|
||||||
resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==}
|
resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -3083,6 +3132,30 @@ packages:
|
|||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/smart-buffer/4.2.0:
|
||||||
|
resolution: {integrity: sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==}
|
||||||
|
engines: {node: '>= 6.0.0', npm: '>= 3.0.0'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/socks-proxy-agent/7.0.0:
|
||||||
|
resolution: {integrity: sha512-Fgl0YPZ902wEsAyiQ+idGd1A7rSFx/ayC1CQVMw5P+EQx2V0SgpGtf6OKFhVjPflPUl9YMmEOnmfjCdMUsygww==}
|
||||||
|
engines: {node: '>= 10'}
|
||||||
|
dependencies:
|
||||||
|
agent-base: 6.0.2
|
||||||
|
debug: 4.3.4
|
||||||
|
socks: 2.7.1
|
||||||
|
transitivePeerDependencies:
|
||||||
|
- supports-color
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/socks/2.7.1:
|
||||||
|
resolution: {integrity: sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==}
|
||||||
|
engines: {node: '>= 10.13.0', npm: '>= 3.0.0'}
|
||||||
|
dependencies:
|
||||||
|
ip: 2.0.0
|
||||||
|
smart-buffer: 4.2.0
|
||||||
|
dev: false
|
||||||
|
|
||||||
/source-map-support/0.5.21:
|
/source-map-support/0.5.21:
|
||||||
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
|
resolution: {integrity: sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -3440,6 +3513,11 @@ packages:
|
|||||||
- supports-color
|
- supports-color
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/web-streams-polyfill/3.2.1:
|
||||||
|
resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==}
|
||||||
|
engines: {node: '>= 8'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/webidl-conversions/3.0.1:
|
/webidl-conversions/3.0.1:
|
||||||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
@@ -1,20 +1,18 @@
|
|||||||
import * as dotenv from 'dotenv'
|
import * as dotenv from 'dotenv'
|
||||||
import 'isomorphic-fetch'
|
import 'isomorphic-fetch'
|
||||||
import type { ChatGPTAPI, ChatMessage, SendMessageOptions } from 'chatgpt'
|
import type { ChatMessage, SendMessageOptions } from 'chatgpt'
|
||||||
import { ChatGPTUnofficialProxyAPI } from 'chatgpt'
|
import { ChatGPTAPI, ChatGPTUnofficialProxyAPI } from 'chatgpt'
|
||||||
|
import { SocksProxyAgent } from 'socks-proxy-agent'
|
||||||
|
import fetch from 'node-fetch'
|
||||||
import { sendResponse } from './utils'
|
import { sendResponse } from './utils'
|
||||||
|
import type { ApiModel, ChatContext, ChatGPTAPIOptions, ChatGPTUnofficialProxyAPIOptions, ModelConfig } from './types'
|
||||||
|
|
||||||
dotenv.config()
|
dotenv.config()
|
||||||
|
|
||||||
let apiModel: 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI' | undefined
|
|
||||||
|
|
||||||
interface ChatContext {
|
|
||||||
conversationId?: string
|
|
||||||
parentMessageId?: string
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
if (!process.env.OPENAI_API_KEY && !process.env.OPENAI_ACCESS_TOKEN)
|
if (!process.env.OPENAI_API_KEY && !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')
|
||||||
|
|
||||||
@@ -23,17 +21,34 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
|||||||
// To use ESM in CommonJS, you can use a dynamic import
|
// To use ESM in CommonJS, you can use a dynamic import
|
||||||
(async () => {
|
(async () => {
|
||||||
// More Info: https://github.com/transitive-bullshit/chatgpt-api
|
// More Info: https://github.com/transitive-bullshit/chatgpt-api
|
||||||
const { ChatGPTAPI } = await import('chatgpt')
|
|
||||||
|
|
||||||
if (process.env.OPENAI_API_KEY) {
|
if (process.env.OPENAI_API_KEY) {
|
||||||
api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })
|
const options: ChatGPTAPIOptions = {
|
||||||
|
apiKey: process.env.OPENAI_API_KEY,
|
||||||
|
debug: false,
|
||||||
|
}
|
||||||
|
|
||||||
|
api = new ChatGPTAPI({ ...options })
|
||||||
apiModel = 'ChatGPTAPI'
|
apiModel = 'ChatGPTAPI'
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let options = {}
|
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)
|
if (process.env.API_REVERSE_PROXY)
|
||||||
options = { apiReverseProxyUrl: process.env.API_REVERSE_PROXY }
|
options.apiReverseProxyUrl = process.env.API_REVERSE_PROXY
|
||||||
|
|
||||||
api = new ChatGPTUnofficialProxyAPI({
|
api = new ChatGPTUnofficialProxyAPI({
|
||||||
accessToken: process.env.OPENAI_ACCESS_TOKEN,
|
accessToken: process.env.OPENAI_ACCESS_TOKEN,
|
||||||
@@ -100,7 +115,8 @@ async function chatConfig() {
|
|||||||
apiModel,
|
apiModel,
|
||||||
reverseProxy: process.env.API_REVERSE_PROXY,
|
reverseProxy: process.env.API_REVERSE_PROXY,
|
||||||
timeoutMs,
|
timeoutMs,
|
||||||
},
|
socksProxy: (process.env.SOCKS_PROXY_HOST && process.env.SOCKS_PROXY_PORT) ? (`${process.env.SOCKS_PROXY_HOST}:${process.env.SOCKS_PROXY_PORT}`) : '-',
|
||||||
|
} as ModelConfig,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,8 +31,10 @@ router.post('/chat-process', async (req, res) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { prompt, options = {} } = req.body as { prompt: string; options?: ChatContext }
|
const { prompt, options = {} } = req.body as { prompt: string; options?: ChatContext }
|
||||||
|
let firstChunk = true
|
||||||
await chatReplyProcess(prompt, options, (chat: ChatMessage) => {
|
await chatReplyProcess(prompt, options, (chat: ChatMessage) => {
|
||||||
res.write(JSON.stringify(chat))
|
res.write(firstChunk ? JSON.stringify(chat) : `\n${JSON.stringify(chat)}`)
|
||||||
|
firstChunk = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
30
service/src/types.ts
Normal file
30
service/src/types.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import type { FetchFn, openai } from 'chatgpt'
|
||||||
|
|
||||||
|
export interface ChatContext {
|
||||||
|
conversationId?: string
|
||||||
|
parentMessageId?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ChatGPTAPIOptions {
|
||||||
|
apiKey: string
|
||||||
|
debug?: boolean
|
||||||
|
completionParams?: Partial<openai.CompletionParams>
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
@@ -1,10 +1,17 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { NConfigProvider } from 'naive-ui'
|
import { NConfigProvider } from 'naive-ui'
|
||||||
import { NaiveProvider } from '@/components/common'
|
import { NaiveProvider } from '@/components/common'
|
||||||
|
import { useTheme } from '@/hooks/useTheme'
|
||||||
|
|
||||||
|
const { theme, themeOverrides } = useTheme()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<NConfigProvider class="h-full">
|
<NConfigProvider
|
||||||
|
class="h-full"
|
||||||
|
:theme="theme"
|
||||||
|
:theme-overrides="themeOverrides"
|
||||||
|
>
|
||||||
<NaiveProvider>
|
<NaiveProvider>
|
||||||
<RouterView />
|
<RouterView />
|
||||||
</NaiveProvider>
|
</NaiveProvider>
|
||||||
|
@@ -13,6 +13,12 @@ export function fetchChatAPI<T = any>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchChatConfig<T = any>() {
|
||||||
|
return post<T>({
|
||||||
|
url: '/config',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
export function fetchChatAPIProcess<T = any>(
|
export function fetchChatAPIProcess<T = any>(
|
||||||
params: {
|
params: {
|
||||||
prompt: string
|
prompt: string
|
||||||
@@ -27,9 +33,3 @@ export function fetchChatAPIProcess<T = any>(
|
|||||||
onDownloadProgress: params.onDownloadProgress,
|
onDownloadProgress: params.onDownloadProgress,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchChatConfig<T = any>() {
|
|
||||||
return post<T>({
|
|
||||||
url: '/config',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
@@ -12,7 +12,7 @@ function handleClick() {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<button
|
<button
|
||||||
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100"
|
class="flex items-center justify-center w-10 h-10 transition rounded-full hover:bg-neutral-100 dark:hover:bg-[#414755]"
|
||||||
@click="handleClick"
|
@click="handleClick"
|
||||||
>
|
>
|
||||||
<slot />
|
<slot />
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import { computed, ref, watch } from 'vue'
|
import { computed, ref, watch } from 'vue'
|
||||||
import { NCard, NModal } from 'naive-ui'
|
import { NCard, NModal } from 'naive-ui'
|
||||||
|
import pkg from '../../../../package.json'
|
||||||
import { fetchChatConfig } from '@/api'
|
import { fetchChatConfig } from '@/api'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -15,6 +16,7 @@ interface ConfigState {
|
|||||||
timeoutMs?: number
|
timeoutMs?: number
|
||||||
reverseProxy?: string
|
reverseProxy?: string
|
||||||
apiModel?: string
|
apiModel?: string
|
||||||
|
socksProxy?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
@@ -55,12 +57,20 @@ watch(
|
|||||||
<NModal v-model:show="show" style="width: 80%; max-width: 460px;">
|
<NModal v-model:show="show" style="width: 80%; max-width: 460px;">
|
||||||
<NCard>
|
<NCard>
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<h1 class="text-xl font-bold">
|
<h2 class="text-xl font-bold text-center">
|
||||||
当前后台设置
|
Version - {{ pkg.version }}
|
||||||
</h1>
|
</h2>
|
||||||
|
<hr>
|
||||||
|
<p>
|
||||||
|
此项目开源于
|
||||||
|
<a class="text-blue-600" href="https://github.com/Chanzhaoyu/chatgpt-web" target="_blank">Github</a>
|
||||||
|
如果你觉得此项目对你有帮助,请帮我点个 Star,谢谢!
|
||||||
|
</p>
|
||||||
|
<hr>
|
||||||
<p>API方式:{{ config?.apiModel ?? '-' }}</p>
|
<p>API方式:{{ config?.apiModel ?? '-' }}</p>
|
||||||
<p>反向代理:{{ config?.reverseProxy ?? '-' }}</p>
|
<p>反向代理:{{ config?.reverseProxy ?? '-' }}</p>
|
||||||
<p>超时时间:{{ config?.timeoutMs ?? '-' }}</p>
|
<p>超时时间:{{ config?.timeoutMs ?? '-' }}</p>
|
||||||
|
<p>Socks代理:{{ config?.socksProxy ?? '-' }}</p>
|
||||||
</div>
|
</div>
|
||||||
</NCard>
|
</NCard>
|
||||||
</NModal>
|
</NModal>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="text-center text-neutral-500">
|
<div class="text-neutral-400">
|
||||||
<span>❤️ Star on</span>
|
<span>Star on</span>
|
||||||
<a href="https://github.com/Chanzhaoyu/chatgpt-bot" target="_blank" class="text-blue-500">
|
<a href="https://github.com/Chanzhaoyu/chatgpt-bot" target="_blank" class="text-blue-500">
|
||||||
GitHub
|
GitHub
|
||||||
</a>
|
</a>
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
import type { App, Directive } from 'vue'
|
import type { App, Directive } from 'vue'
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
import includeCode from '@/utils/functions/includeCode'
|
import { includeCode } from '@/utils/format'
|
||||||
|
|
||||||
|
hljs.configure({ ignoreUnescapedHTML: true })
|
||||||
|
|
||||||
function highlightCode(el: HTMLElement) {
|
function highlightCode(el: HTMLElement) {
|
||||||
if (includeCode(el.textContent))
|
if (includeCode(el.textContent))
|
||||||
|
36
src/hooks/useIconRender.ts
Normal file
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,
|
||||||
|
}
|
||||||
|
}
|
43
src/hooks/useTheme.ts
Normal file
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 }
|
||||||
|
}
|
@@ -1,5 +1,7 @@
|
|||||||
import 'highlight.js/styles/xcode.css'
|
import '@/styles/lib/tailwind.css'
|
||||||
import '@/styles/global.css'
|
import '@/styles/lib/highlight.less'
|
||||||
|
import '@/styles/lib/github-markdown.less'
|
||||||
|
import '@/styles/global.less'
|
||||||
|
|
||||||
/** Tailwind's Preflight Style Override */
|
/** Tailwind's Preflight Style Override */
|
||||||
function naiveStyleOverride() {
|
function naiveStyleOverride() {
|
||||||
|
@@ -2,19 +2,22 @@ import { ss } from '@/utils/storage'
|
|||||||
|
|
||||||
const LOCAL_NAME = 'appSetting'
|
const LOCAL_NAME = 'appSetting'
|
||||||
|
|
||||||
|
export type Theme = 'light' | 'dark' | 'auto'
|
||||||
|
|
||||||
export interface AppState {
|
export interface AppState {
|
||||||
siderCollapsed: boolean
|
siderCollapsed: boolean
|
||||||
|
theme: Theme
|
||||||
}
|
}
|
||||||
|
|
||||||
export function defaultSetting() {
|
export function defaultSetting(): AppState {
|
||||||
return { siderCollapsed: false }
|
return { siderCollapsed: false, theme: 'light' }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLocalSetting() {
|
export function getLocalSetting(): AppState {
|
||||||
const localSetting: AppState | undefined = ss.get(LOCAL_NAME)
|
const localSetting: AppState | undefined = ss.get(LOCAL_NAME)
|
||||||
return localSetting ?? defaultSetting()
|
return { ...defaultSetting(), ...localSetting }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setLocalSetting(setting: AppState) {
|
export function setLocalSetting(setting: AppState): void {
|
||||||
ss.set(LOCAL_NAME, setting)
|
ss.set(LOCAL_NAME, setting)
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import type { AppState } from './helper'
|
import type { AppState, Theme } from './helper'
|
||||||
import { getLocalSetting, setLocalSetting } from './helper'
|
import { getLocalSetting, setLocalSetting } from './helper'
|
||||||
|
|
||||||
export const useAppStore = defineStore('app-store', {
|
export const useAppStore = defineStore('app-store', {
|
||||||
@@ -7,6 +7,15 @@ export const useAppStore = defineStore('app-store', {
|
|||||||
actions: {
|
actions: {
|
||||||
setSiderCollapsed(collapsed: boolean) {
|
setSiderCollapsed(collapsed: boolean) {
|
||||||
this.siderCollapsed = collapsed
|
this.siderCollapsed = collapsed
|
||||||
|
this.recordState()
|
||||||
|
},
|
||||||
|
|
||||||
|
setTheme(theme: Theme) {
|
||||||
|
this.theme = theme
|
||||||
|
this.recordState()
|
||||||
|
},
|
||||||
|
|
||||||
|
recordState() {
|
||||||
setLocalSetting(this.$state)
|
setLocalSetting(this.$state)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -6,6 +6,13 @@ export const useChatStore = defineStore('chat-store', {
|
|||||||
state: (): Chat.ChatState => getLocalState(),
|
state: (): Chat.ChatState => getLocalState(),
|
||||||
|
|
||||||
getters: {
|
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) {
|
getChatByUuid(state: Chat.ChatState) {
|
||||||
return (uuid?: number) => {
|
return (uuid?: number) => {
|
||||||
if (uuid)
|
if (uuid)
|
||||||
@@ -68,6 +75,18 @@ export const useChatStore = defineStore('chat-store', {
|
|||||||
return await this.reloadRoute(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) {
|
addChatByUuid(uuid: number, chat: Chat.Chat) {
|
||||||
if (!uuid || uuid === 0) {
|
if (!uuid || uuid === 0) {
|
||||||
if (this.history.length === 0) {
|
if (this.history.length === 0) {
|
||||||
@@ -110,6 +129,38 @@ export const useChatStore = defineStore('chat-store', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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) {
|
clearChatByUuid(uuid: number) {
|
||||||
if (!uuid || uuid === 0) {
|
if (!uuid || uuid === 0) {
|
||||||
if (this.chat.length) {
|
if (this.chat.length) {
|
||||||
|
5
src/styles/global.less
Normal file
5
src/styles/global.less
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
html,
|
||||||
|
body,
|
||||||
|
#app {
|
||||||
|
height: 100%;
|
||||||
|
}
|
1102
src/styles/lib/github-markdown.less
Normal file
1102
src/styles/lib/github-markdown.less
Normal file
File diff suppressed because it is too large
Load Diff
203
src/styles/lib/highlight.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
|
||||||
|
}
|
||||||
|
}
|
@@ -1,9 +1,3 @@
|
|||||||
@tailwind base;
|
@tailwind base;
|
||||||
@tailwind components;
|
@tailwind components;
|
||||||
@tailwind utilities;
|
@tailwind utilities;
|
||||||
|
|
||||||
html,
|
|
||||||
body,
|
|
||||||
#app {
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
27
src/utils/format/index.ts
Normal file
27
src/utils/format/index.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
// 转义 HTML 字符
|
||||||
|
export function encodeHTML(source: string) {
|
||||||
|
return source
|
||||||
|
.replace(/&/g, '&')
|
||||||
|
.replace(/</g, '<')
|
||||||
|
.replace(/>/g, '>')
|
||||||
|
.replace(/"/g, '"')
|
||||||
|
.replace(/'/g, ''')
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否为代码块
|
||||||
|
export function includeCode(text: string | null | undefined) {
|
||||||
|
const regexp = /^(?:\s{4}|\t).+/gm
|
||||||
|
return !!(text?.includes(' = ') || text?.match(regexp))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 复制文本
|
||||||
|
export function copyText(text: string) {
|
||||||
|
const input = document.createElement('input')
|
||||||
|
input.setAttribute('readonly', 'readonly')
|
||||||
|
input.setAttribute('value', text)
|
||||||
|
document.body.appendChild(input)
|
||||||
|
input.select()
|
||||||
|
if (document.execCommand('copy'))
|
||||||
|
document.execCommand('copy')
|
||||||
|
document.body.removeChild(input)
|
||||||
|
}
|
@@ -1,6 +0,0 @@
|
|||||||
function includeCode(text: string | null | undefined) {
|
|
||||||
const regexp = /^(?:\s{4}|\t).+/gm
|
|
||||||
return !!(text?.includes(' = ') || text?.match(regexp))
|
|
||||||
}
|
|
||||||
|
|
||||||
export default includeCode
|
|
@@ -8,9 +8,9 @@ defineProps<Props>()
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<img v-if="image" src="@/assets/avatar.jpg" class="object-cover w-full h-full " alt="avatar">
|
<img v-if="image" src="@/assets/avatar.jpg" class="object-cover w-full h-full " alt="avatar">
|
||||||
<span v-else class="text-[27px]">
|
<span v-else class="text-[27px] dark:text-white">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" aria-hidden="true" width="1em" height="1em">
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" aria-hidden="true" width="1em" height="1em">
|
||||||
<path d="M29.71,13.09A8.09,8.09,0,0,0,20.34,2.68a8.08,8.08,0,0,0-13.7,2.9A8.08,8.08,0,0,0,2.3,18.9,8,8,0,0,0,3,25.45a8.08,8.08,0,0,0,8.69,3.87,8,8,0,0,0,6,2.68,8.09,8.09,0,0,0,7.7-5.61,8,8,0,0,0,5.33-3.86A8.09,8.09,0,0,0,29.71,13.09Zm-12,16.82a6,6,0,0,1-3.84-1.39l.19-.11,6.37-3.68a1,1,0,0,0,.53-.91v-9l2.69,1.56a.08.08,0,0,1,.05.07v7.44A6,6,0,0,1,17.68,29.91ZM4.8,24.41a6,6,0,0,1-.71-4l.19.11,6.37,3.68a1,1,0,0,0,1,0l7.79-4.49V22.8a.09.09,0,0,1,0,.08L13,26.6A6,6,0,0,1,4.8,24.41ZM3.12,10.53A6,6,0,0,1,6.28,7.9v7.57a1,1,0,0,0,.51.9l7.75,4.47L11.85,22.4a.14.14,0,0,1-.09,0L5.32,18.68a6,6,0,0,1-2.2-8.18Zm22.13,5.14-7.78-4.52L20.16,9.6a.08.08,0,0,1,.09,0l6.44,3.72a6,6,0,0,1-.9,10.81V16.56A1.06,1.06,0,0,0,25.25,15.67Zm2.68-4-.19-.12-6.36-3.7a1,1,0,0,0-1.05,0l-7.78,4.49V9.2a.09.09,0,0,1,0-.09L19,5.4a6,6,0,0,1,8.91,6.21ZM11.08,17.15,8.38,15.6a.14.14,0,0,1-.05-.08V8.1a6,6,0,0,1,9.84-4.61L18,3.6,11.61,7.28a1,1,0,0,0-.53.91ZM12.54,14,16,12l3.47,2v4L16,20l-3.47-2Z" />
|
<path d="M29.71,13.09A8.09,8.09,0,0,0,20.34,2.68a8.08,8.08,0,0,0-13.7,2.9A8.08,8.08,0,0,0,2.3,18.9,8,8,0,0,0,3,25.45a8.08,8.08,0,0,0,8.69,3.87,8,8,0,0,0,6,2.68,8.09,8.09,0,0,0,7.7-5.61,8,8,0,0,0,5.33-3.86A8.09,8.09,0,0,0,29.71,13.09Zm-12,16.82a6,6,0,0,1-3.84-1.39l.19-.11,6.37-3.68a1,1,0,0,0,.53-.91v-9l2.69,1.56a.08.08,0,0,1,.05.07v7.44A6,6,0,0,1,17.68,29.91ZM4.8,24.41a6,6,0,0,1-.71-4l.19.11,6.37,3.68a1,1,0,0,0,1,0l7.79-4.49V22.8a.09.09,0,0,1,0,.08L13,26.6A6,6,0,0,1,4.8,24.41ZM3.12,10.53A6,6,0,0,1,6.28,7.9v7.57a1,1,0,0,0,.51.9l7.75,4.47L11.85,22.4a.14.14,0,0,1-.09,0L5.32,18.68a6,6,0,0,1-2.2-8.18Zm22.13,5.14-7.78-4.52L20.16,9.6a.08.08,0,0,1,.09,0l6.44,3.72a6,6,0,0,1-.9,10.81V16.56A1.06,1.06,0,0,0,25.25,15.67Zm2.68-4-.19-.12-6.36-3.7a1,1,0,0,0-1.05,0l-7.78,4.49V9.2a.09.09,0,0,1,0-.09L19,5.4a6,6,0,0,1,8.91,6.21ZM11.08,17.15,8.38,15.6a.14.14,0,0,1-.05-.08V8.1a6,6,0,0,1,9.84-4.61L18,3.6,11.61,7.28a1,1,0,0,0-.53.91ZM12.54,14,16,12l3.47,2v4L16,20l-3.47-2Z" fill="currentColor" />
|
||||||
</svg>
|
</svg>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
@@ -1,7 +1,9 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
import { marked } from 'marked'
|
import { marked } from 'marked'
|
||||||
import includeCode from '@/utils/functions/includeCode'
|
import hljs from 'highlight.js'
|
||||||
|
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
||||||
|
import { encodeHTML } from '@/utils/format'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
inversion?: boolean
|
inversion?: boolean
|
||||||
@@ -12,52 +14,62 @@ interface Props {
|
|||||||
|
|
||||||
const props = defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
|
const { isMobile } = useBasicLayout()
|
||||||
|
|
||||||
|
const renderer = new marked.Renderer()
|
||||||
|
|
||||||
|
renderer.html = (html) => {
|
||||||
|
return `<p>${encodeHTML(html)}</p>`
|
||||||
|
}
|
||||||
|
|
||||||
|
renderer.code = (code, language) => {
|
||||||
|
const validLang = !!(language && hljs.getLanguage(language))
|
||||||
|
if (validLang)
|
||||||
|
return `<pre><code class="hljs ${language}">${hljs.highlight(language, code).value}</code></pre>`
|
||||||
|
return `<pre style="background: none">${hljs.highlightAuto(code).value}</pre>`
|
||||||
|
}
|
||||||
|
|
||||||
|
marked.setOptions({
|
||||||
|
renderer,
|
||||||
|
highlight(code) {
|
||||||
|
return hljs.highlightAuto(code).value
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
const wrapClass = computed(() => {
|
const wrapClass = computed(() => {
|
||||||
return [
|
return [
|
||||||
'text-wrap',
|
'text-wrap',
|
||||||
'p-3',
|
|
||||||
'min-w-[20px]',
|
'min-w-[20px]',
|
||||||
'rounded-md',
|
'rounded-md',
|
||||||
|
isMobile.value ? 'p-2' : 'p-3',
|
||||||
props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]',
|
props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]',
|
||||||
|
props.inversion ? 'dark:bg-[#a1dc95]' : 'dark:bg-[#1e1e20]',
|
||||||
{ 'text-red-500': props.error },
|
{ 'text-red-500': props.error },
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const text = computed(() => {
|
const text = computed(() => {
|
||||||
if (props.text) {
|
const value = props.text ?? ''
|
||||||
if (!includeCode(props.text))
|
if (!props.inversion)
|
||||||
return marked.parse(props.text)
|
return marked(value)
|
||||||
return props.text
|
return value
|
||||||
}
|
|
||||||
return ''
|
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="wrapClass">
|
<div class="text-black" :class="wrapClass">
|
||||||
<template v-if="loading">
|
<template v-if="loading">
|
||||||
<span class="w-[3px] h-[20px] block animate-blink" />
|
<span class="dark:text-white w-[4px] h-[20px] block animate-blink" />
|
||||||
</template>
|
</template>
|
||||||
<template v-else>
|
<template v-else>
|
||||||
<code v-if="includeCode(text)" v-highlight class="leading-relaxed" v-text="text" />
|
<div class="leading-relaxed break-all">
|
||||||
<div v-else class="leading-relaxed break-all" v-html="text" />
|
<div v-if="!inversion" class="markdown-body" v-html="text" />
|
||||||
|
<div v-else class="whitespace-pre-wrap" v-text="text" />
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
.text-wrap{
|
@import url(./style.less);
|
||||||
img{
|
|
||||||
max-width: 100%;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
color: #2d5cf6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.hljs {
|
|
||||||
background-color: #fff0 !important;
|
|
||||||
white-space: break-spaces;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
@@ -1,7 +1,10 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import Avatar from './Avatar.vue'
|
import { NDropdown, useMessage } from 'naive-ui'
|
||||||
import Text from './Text.vue'
|
import AvatarComponent from './Avatar.vue'
|
||||||
|
import TextComponent from './Text.vue'
|
||||||
import { SvgIcon } from '@/components/common'
|
import { SvgIcon } from '@/components/common'
|
||||||
|
import { copyText } from '@/utils/format'
|
||||||
|
import { useIconRender } from '@/hooks/useIconRender'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
dateTime?: string
|
dateTime?: string
|
||||||
@@ -13,38 +16,86 @@ interface Props {
|
|||||||
|
|
||||||
interface Emit {
|
interface Emit {
|
||||||
(ev: 'regenerate'): void
|
(ev: 'regenerate'): void
|
||||||
|
(ev: 'delete'): void
|
||||||
}
|
}
|
||||||
|
|
||||||
defineProps<Props>()
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
const emit = defineEmits<Emit>()
|
const emit = defineEmits<Emit>()
|
||||||
|
|
||||||
|
const ms = useMessage()
|
||||||
|
|
||||||
|
const { iconRender } = useIconRender()
|
||||||
|
|
||||||
|
const options = [
|
||||||
|
{
|
||||||
|
label: 'Copy',
|
||||||
|
key: 'copy',
|
||||||
|
icon: iconRender({ icon: 'ri:file-copy-2-line' }),
|
||||||
|
}, {
|
||||||
|
label: 'Delete',
|
||||||
|
key: 'delete',
|
||||||
|
icon: iconRender({ icon: 'ri:delete-bin-line' }),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
function handleSelect(key: 'copy' | 'delete') {
|
||||||
|
if (key === 'copy')
|
||||||
|
handleCopy()
|
||||||
|
else
|
||||||
|
handleDelete()
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDelete() {
|
||||||
|
emit('delete')
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleCopy() {
|
||||||
|
copyText(props.text ?? '')
|
||||||
|
ms.success('Copied')
|
||||||
|
}
|
||||||
|
|
||||||
function handleRegenerate() {
|
function handleRegenerate() {
|
||||||
emit('regenerate')
|
emit('regenerate')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex w-full mb-6" :class="[{ 'flex-row-reverse': inversion }]">
|
<div class="flex w-full mb-6 overflow-hidden" :class="[{ 'flex-row-reverse': inversion }]">
|
||||||
<div
|
<div
|
||||||
class="flex items-center justify-center rounded-full overflow-hidden w-[32px] h-[32px]"
|
class="flex items-center justify-center flex-shrink-0 h-8 overflow-hidden rounded-full basis-8"
|
||||||
:class="[inversion ? 'ml-3' : 'mr-3']"
|
:class="[inversion ? 'ml-2' : 'mr-2']"
|
||||||
>
|
>
|
||||||
<Avatar :image="inversion" />
|
<AvatarComponent :image="inversion" />
|
||||||
</div>
|
</div>
|
||||||
<div class="flex flex-col flex-1 text-sm" :class="[inversion ? 'items-end' : 'items-start']">
|
<div class="overflow-hidden text-sm " :class="[inversion ? 'items-end' : 'items-start']">
|
||||||
<span class="text-xs text-[#b4bbc4]">
|
<p class="text-xs text-[#b4bbc4]" :class="[inversion ? 'text-right' : 'text-left']">
|
||||||
{{ dateTime }}
|
{{ dateTime }}
|
||||||
</span>
|
</p>
|
||||||
<div class="flex items-end mt-2">
|
<div
|
||||||
<Text :inversion="inversion" :error="error" :text="text" :loading="loading" />
|
class="flex items-end gap-2 mt-2"
|
||||||
<button
|
:class="[inversion ? 'flex-row-reverse' : 'flex-row']"
|
||||||
v-if="!inversion && !loading"
|
>
|
||||||
class="mb-2 ml-2 transition text-neutral-400 hover:text-neutral-800"
|
<TextComponent
|
||||||
@click="handleRegenerate"
|
:inversion="inversion"
|
||||||
>
|
:error="error"
|
||||||
<SvgIcon icon="ri:restart-line" />
|
:text="text"
|
||||||
</button>
|
:loading="loading"
|
||||||
|
/>
|
||||||
|
<div class="flex flex-col">
|
||||||
|
<button
|
||||||
|
v-if="!inversion"
|
||||||
|
class="mb-2 transition text-neutral-400 hover:text-neutral-800 dark:hover:text-neutral-200"
|
||||||
|
@click="handleRegenerate"
|
||||||
|
>
|
||||||
|
<SvgIcon icon="ri:restart-line" />
|
||||||
|
</button>
|
||||||
|
<NDropdown :options="options" @select="handleSelect">
|
||||||
|
<button class="transition text-neutral-300 hover:text-neutral-800 dark:hover:text-neutral-200">
|
||||||
|
<SvgIcon icon="ri:function-line" />
|
||||||
|
</button>
|
||||||
|
</NDropdown>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
38
src/views/chat/components/Message/style.less
Normal file
38
src/views/chat/components/Message/style.less
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
.markdown-body {
|
||||||
|
background-color: transparent;
|
||||||
|
font-size: 14px;
|
||||||
|
|
||||||
|
p {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol {
|
||||||
|
list-style-type: decimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style-type: disc;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code,
|
||||||
|
pre tt {
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight pre,
|
||||||
|
pre {
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
code.hljs{
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html.dark {
|
||||||
|
|
||||||
|
.highlight pre,
|
||||||
|
pre {
|
||||||
|
background-color: #282c34;
|
||||||
|
}
|
||||||
|
}
|
@@ -3,6 +3,10 @@ import { useChatStore } from '@/store'
|
|||||||
export function useChat() {
|
export function useChat() {
|
||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
|
|
||||||
|
const getChatByUuidAndIndex = (uuid: number, index: number) => {
|
||||||
|
return chatStore.getChatByUuidAndIndex(uuid, index)
|
||||||
|
}
|
||||||
|
|
||||||
const addChat = (uuid: number, chat: Chat.Chat) => {
|
const addChat = (uuid: number, chat: Chat.Chat) => {
|
||||||
chatStore.addChatByUuid(uuid, chat)
|
chatStore.addChatByUuid(uuid, chat)
|
||||||
}
|
}
|
||||||
@@ -11,8 +15,14 @@ export function useChat() {
|
|||||||
chatStore.updateChatByUuid(uuid, index, chat)
|
chatStore.updateChatByUuid(uuid, index, chat)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const updateChatSome = (uuid: number, index: number, chat: Partial<Chat.Chat>) => {
|
||||||
|
chatStore.updateChatSomeByUuid(uuid, index, chat)
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addChat,
|
addChat,
|
||||||
updateChat,
|
updateChat,
|
||||||
|
updateChatSome,
|
||||||
|
getChatByUuidAndIndex,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
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 { NButton, NInput, useDialog } from 'naive-ui'
|
import { NButton, NInput, useDialog, useMessage } from 'naive-ui'
|
||||||
import { Message } from './components'
|
import { Message } from './components'
|
||||||
import { useScroll } from './hooks/useScroll'
|
import { useScroll } from './hooks/useScroll'
|
||||||
import { useChat } from './hooks/useChat'
|
import { useChat } from './hooks/useChat'
|
||||||
@@ -14,11 +14,12 @@ let controller = new AbortController()
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const dialog = useDialog()
|
const dialog = useDialog()
|
||||||
|
const ms = useMessage()
|
||||||
|
|
||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
|
|
||||||
const { isMobile } = useBasicLayout()
|
const { isMobile } = useBasicLayout()
|
||||||
const { addChat, updateChat } = useChat()
|
const { addChat, updateChat, updateChatSome, getChatByUuidAndIndex } = useChat()
|
||||||
const { scrollRef, scrollToBottom } = useScroll()
|
const { scrollRef, scrollToBottom } = useScroll()
|
||||||
|
|
||||||
const { uuid } = route.params as { uuid: string }
|
const { uuid } = route.params as { uuid: string }
|
||||||
@@ -70,7 +71,7 @@ async function onConversation() {
|
|||||||
+uuid,
|
+uuid,
|
||||||
{
|
{
|
||||||
dateTime: new Date().toLocaleString(),
|
dateTime: new Date().toLocaleString(),
|
||||||
text: 'Aha, Thinking...',
|
text: '',
|
||||||
loading: true,
|
loading: true,
|
||||||
inversion: false,
|
inversion: false,
|
||||||
error: false,
|
error: false,
|
||||||
@@ -80,7 +81,6 @@ async function onConversation() {
|
|||||||
)
|
)
|
||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
|
|
||||||
let offset = 0
|
|
||||||
try {
|
try {
|
||||||
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
||||||
prompt: message,
|
prompt: message,
|
||||||
@@ -89,8 +89,11 @@ async function onConversation() {
|
|||||||
onDownloadProgress: ({ event }) => {
|
onDownloadProgress: ({ event }) => {
|
||||||
const xhr = event.target
|
const xhr = event.target
|
||||||
const { responseText } = xhr
|
const { responseText } = xhr
|
||||||
const chunk = responseText.substring(offset)
|
// Always process the final line
|
||||||
offset = responseText.length
|
const lastIndex = responseText.lastIndexOf('\n')
|
||||||
|
let chunk = responseText
|
||||||
|
if (lastIndex !== -1)
|
||||||
|
chunk = responseText.substring(lastIndex)
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(chunk)
|
const data = JSON.parse(chunk)
|
||||||
updateChat(
|
updateChat(
|
||||||
@@ -115,10 +118,34 @@ async function onConversation() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
let errorMessage = error?.message ?? 'Something went wrong, please try again later.'
|
const errorMessage = error?.message ?? 'Something went wrong, please try again later.'
|
||||||
|
|
||||||
if (error.message === 'canceled')
|
if (error.message === 'canceled') {
|
||||||
errorMessage = 'Request canceled. Please try again.'
|
updateChatSome(
|
||||||
|
+uuid,
|
||||||
|
dataSources.value.length - 1,
|
||||||
|
{
|
||||||
|
loading: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
scrollToBottom()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentChat = getChatByUuidAndIndex(+uuid, dataSources.value.length - 1)
|
||||||
|
|
||||||
|
if (currentChat?.text && currentChat.text !== '') {
|
||||||
|
updateChatSome(
|
||||||
|
+uuid,
|
||||||
|
dataSources.value.length - 1,
|
||||||
|
{
|
||||||
|
text: `${currentChat.text}\n[${errorMessage}]`,
|
||||||
|
error: false,
|
||||||
|
loading: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
updateChat(
|
updateChat(
|
||||||
+uuid,
|
+uuid,
|
||||||
@@ -136,7 +163,6 @@ async function onConversation() {
|
|||||||
scrollToBottom()
|
scrollToBottom()
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
offset = 0
|
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -163,7 +189,7 @@ async function onRegenerate(index: number) {
|
|||||||
index,
|
index,
|
||||||
{
|
{
|
||||||
dateTime: new Date().toLocaleString(),
|
dateTime: new Date().toLocaleString(),
|
||||||
text: 'Aha, Let me think again...',
|
text: '',
|
||||||
inversion: false,
|
inversion: false,
|
||||||
error: false,
|
error: false,
|
||||||
loading: true,
|
loading: true,
|
||||||
@@ -172,7 +198,6 @@ async function onRegenerate(index: number) {
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
let offset = 0
|
|
||||||
try {
|
try {
|
||||||
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
await fetchChatAPIProcess<Chat.ConversationResponse>({
|
||||||
prompt: message,
|
prompt: message,
|
||||||
@@ -181,8 +206,11 @@ async function onRegenerate(index: number) {
|
|||||||
onDownloadProgress: ({ event }) => {
|
onDownloadProgress: ({ event }) => {
|
||||||
const xhr = event.target
|
const xhr = event.target
|
||||||
const { responseText } = xhr
|
const { responseText } = xhr
|
||||||
const chunk = responseText.substring(offset)
|
// Always process the final line
|
||||||
offset = responseText.length
|
const lastIndex = responseText.lastIndexOf('\n')
|
||||||
|
let chunk = responseText
|
||||||
|
if (lastIndex !== -1)
|
||||||
|
chunk = responseText.substring(lastIndex)
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(chunk)
|
const data = JSON.parse(chunk)
|
||||||
updateChat(
|
updateChat(
|
||||||
@@ -206,10 +234,18 @@ async function onRegenerate(index: number) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
let errorMessage = error?.message ?? 'Something went wrong, please try again later.'
|
if (error.message === 'canceled') {
|
||||||
|
updateChatSome(
|
||||||
|
+uuid,
|
||||||
|
index,
|
||||||
|
{
|
||||||
|
loading: false,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (error.message === 'canceled')
|
const errorMessage = error?.message ?? 'Something went wrong, please try again later.'
|
||||||
errorMessage = 'Request canceled. Please try again.'
|
|
||||||
|
|
||||||
updateChat(
|
updateChat(
|
||||||
+uuid,
|
+uuid,
|
||||||
@@ -227,10 +263,25 @@ async function onRegenerate(index: number) {
|
|||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
offset = 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleDelete(index: number) {
|
||||||
|
if (loading.value)
|
||||||
|
return
|
||||||
|
|
||||||
|
dialog.warning({
|
||||||
|
title: 'Delete Message',
|
||||||
|
content: 'Are you sure to delete this message?',
|
||||||
|
positiveText: 'Yes',
|
||||||
|
negativeText: 'No',
|
||||||
|
onPositiveClick: () => {
|
||||||
|
chatStore.deleteChatByUuid(+uuid, index)
|
||||||
|
ms.success('Message deleted successfully.')
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function handleClear() {
|
function handleClear() {
|
||||||
if (loading.value)
|
if (loading.value)
|
||||||
return
|
return
|
||||||
@@ -247,19 +298,34 @@ function handleClear() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleEnter(event: KeyboardEvent) {
|
function handleEnter(event: KeyboardEvent) {
|
||||||
if (event.key === 'Enter' && !event.shiftKey) {
|
if (!isMobile.value) {
|
||||||
event.preventDefault()
|
if (event.key === 'Enter' && !event.shiftKey) {
|
||||||
handleSubmit()
|
event.preventDefault()
|
||||||
|
handleSubmit()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleStop() {
|
||||||
|
if (loading.value) {
|
||||||
|
controller.abort()
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const placeholder = computed(() => {
|
||||||
|
if (isMobile.value)
|
||||||
|
return 'Ask me anything...'
|
||||||
|
return 'Ask me anything... (Shift + Enter = line break)'
|
||||||
|
})
|
||||||
|
|
||||||
const buttonDisabled = computed(() => {
|
const buttonDisabled = computed(() => {
|
||||||
return loading.value || !prompt.value || prompt.value.trim() === ''
|
return loading.value || !prompt.value || prompt.value.trim() === ''
|
||||||
})
|
})
|
||||||
|
|
||||||
const wrapClass = computed(() => {
|
const wrapClass = computed(() => {
|
||||||
if (isMobile.value)
|
if (isMobile.value)
|
||||||
return ['pt-14', 'pb-14']
|
return ['pt-14', 'pb-16']
|
||||||
|
|
||||||
return []
|
return []
|
||||||
})
|
})
|
||||||
@@ -284,7 +350,12 @@ onUnmounted(() => {
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col h-full" :class="wrapClass">
|
<div class="flex flex-col h-full" :class="wrapClass">
|
||||||
<main class="flex-1 overflow-hidden">
|
<main class="flex-1 overflow-hidden">
|
||||||
<div ref="scrollRef" class="h-full p-4 overflow-hidden overflow-y-auto" :class="[{ 'p-2': isMobile }]">
|
<div
|
||||||
|
id="scrollRef"
|
||||||
|
ref="scrollRef"
|
||||||
|
class="h-full overflow-hidden overflow-y-auto"
|
||||||
|
:class="[isMobile ? 'p-2' : 'p-4']"
|
||||||
|
>
|
||||||
<template v-if="!dataSources.length">
|
<template v-if="!dataSources.length">
|
||||||
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
<div class="flex items-center justify-center mt-4 text-center text-neutral-300">
|
||||||
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
<SvgIcon icon="ri:bubble-chart-fill" class="mr-2 text-3xl" />
|
||||||
@@ -302,7 +373,16 @@ onUnmounted(() => {
|
|||||||
:error="item.error"
|
:error="item.error"
|
||||||
:loading="item.loading"
|
:loading="item.loading"
|
||||||
@regenerate="onRegenerate(index)"
|
@regenerate="onRegenerate(index)"
|
||||||
|
@delete="handleDelete(index)"
|
||||||
/>
|
/>
|
||||||
|
<div class="sticky bottom-0 left-0 flex justify-center">
|
||||||
|
<NButton v-if="loading" type="warning" @click="handleStop">
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon icon="ri:stop-circle-line" />
|
||||||
|
</template>
|
||||||
|
Stop Responding
|
||||||
|
</NButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
@@ -310,7 +390,7 @@ onUnmounted(() => {
|
|||||||
<footer :class="footerClass">
|
<footer :class="footerClass">
|
||||||
<div class="flex items-center justify-between space-x-2">
|
<div class="flex items-center justify-between space-x-2">
|
||||||
<HoverButton @click="handleClear">
|
<HoverButton @click="handleClear">
|
||||||
<span class="text-xl text-[#4f555e]">
|
<span class="text-xl text-[#4f555e] dark:text-white">
|
||||||
<SvgIcon icon="ri:delete-bin-line" />
|
<SvgIcon icon="ri:delete-bin-line" />
|
||||||
</span>
|
</span>
|
||||||
</HoverButton>
|
</HoverButton>
|
||||||
@@ -318,12 +398,14 @@ onUnmounted(() => {
|
|||||||
v-model:value="prompt"
|
v-model:value="prompt"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:autosize="{ minRows: 1, maxRows: 2 }"
|
:autosize="{ minRows: 1, maxRows: 2 }"
|
||||||
placeholder="Ask me anything..."
|
:placeholder="placeholder"
|
||||||
@keypress="handleEnter"
|
@keypress="handleEnter"
|
||||||
/>
|
/>
|
||||||
<NButton type="primary" :disabled="buttonDisabled" @click="handleSubmit">
|
<NButton type="primary" :disabled="buttonDisabled" @click="handleSubmit">
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<SvgIcon icon="ri:send-plane-fill" />
|
<span class="dark:text-black">
|
||||||
|
<SvgIcon icon="ri:send-plane-fill" />
|
||||||
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</NButton>
|
</NButton>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -20,7 +20,7 @@ const collapsed = computed(() => appStore.siderCollapsed)
|
|||||||
const getMobileClass = computed(() => {
|
const getMobileClass = computed(() => {
|
||||||
if (isMobile.value)
|
if (isMobile.value)
|
||||||
return ['rounded-none', 'shadow-none']
|
return ['rounded-none', 'shadow-none']
|
||||||
return ['border', 'rounded-md', 'shadow-md']
|
return ['border', 'rounded-md', 'shadow-md', 'dark:border-neutral-800']
|
||||||
})
|
})
|
||||||
|
|
||||||
const getContainerClass = computed(() => {
|
const getContainerClass = computed(() => {
|
||||||
@@ -32,7 +32,7 @@ const getContainerClass = computed(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="h-full" :class="[isMobile ? 'p-0' : 'p-4']">
|
<div class="h-full dark:bg-[#24272e] transition-all" :class="[isMobile ? 'p-0' : 'p-4']">
|
||||||
<div class="h-full overflow-hidden" :class="getMobileClass">
|
<div class="h-full overflow-hidden" :class="getMobileClass">
|
||||||
<NLayout class="z-40 transition" :class="getContainerClass" has-sider>
|
<NLayout class="z-40 transition" :class="getContainerClass" has-sider>
|
||||||
<Sider />
|
<Sider />
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { computed } from 'vue'
|
import { computed, nextTick } from 'vue'
|
||||||
import { SvgIcon } from '@/components/common'
|
import { SvgIcon } from '@/components/common'
|
||||||
import { useAppStore, useChatStore } from '@/store'
|
import { useAppStore, useChatStore } from '@/store'
|
||||||
|
|
||||||
@@ -7,25 +7,48 @@ const appStore = useAppStore()
|
|||||||
const chatStore = useChatStore()
|
const chatStore = useChatStore()
|
||||||
|
|
||||||
const collapsed = computed(() => appStore.siderCollapsed)
|
const collapsed = computed(() => appStore.siderCollapsed)
|
||||||
|
const currentChatHistory = computed(() => chatStore.getChatHistoryByCurrentActive)
|
||||||
function handleAdd() {
|
|
||||||
chatStore.addHistory({ title: 'New Chat', uuid: Date.now(), isEdit: false })
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleUpdateCollapsed() {
|
function handleUpdateCollapsed() {
|
||||||
appStore.setSiderCollapsed(!collapsed.value)
|
appStore.setSiderCollapsed(!collapsed.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onScrollToTop() {
|
||||||
|
const scrollRef = document.querySelector('#scrollRef')
|
||||||
|
if (scrollRef)
|
||||||
|
nextTick(() => scrollRef.scrollTop = 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
function onScrollToBottom() {
|
||||||
|
const scrollRef = document.querySelector('#scrollRef')
|
||||||
|
if (scrollRef)
|
||||||
|
nextTick(() => scrollRef.scrollTop = scrollRef.scrollHeight)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<header class="fixed top-0 left-0 right-0 z-30 border-b bg-white/80 backdrop-blur">
|
<header
|
||||||
|
class="fixed top-0 left-0 right-0 z-30 border-b dark:border-neutral-800 bg-white/80 dark:bg-black/20 backdrop-blur"
|
||||||
|
>
|
||||||
<div class="relative flex items-center justify-between h-14">
|
<div class="relative flex items-center justify-between h-14">
|
||||||
<button class="flex items-center justify-center w-11 h-11" @click="handleUpdateCollapsed">
|
<button
|
||||||
|
class="flex items-center justify-center w-11 h-11"
|
||||||
|
@click="handleUpdateCollapsed"
|
||||||
|
>
|
||||||
<SvgIcon v-if="collapsed" class="text-2xl" icon="ri:align-justify" />
|
<SvgIcon v-if="collapsed" class="text-2xl" icon="ri:align-justify" />
|
||||||
<SvgIcon v-else class="text-2xl" icon="ri:align-right" />
|
<SvgIcon v-else class="text-2xl" icon="ri:align-right" />
|
||||||
</button>
|
</button>
|
||||||
<button class="flex items-center justify-center w-11 h-11" @click="handleAdd">
|
<h1
|
||||||
<SvgIcon class="text-2xl" icon="ri:add-fill" />
|
class="flex-1 px-4 overflow-hidden text-center cursor-pointer select-none text-ellipsis whitespace-nowrap"
|
||||||
|
@dblclick="onScrollToTop"
|
||||||
|
>
|
||||||
|
{{ currentChatHistory?.title ?? '' }}
|
||||||
|
</h1>
|
||||||
|
<button
|
||||||
|
class="flex items-center justify-center w-11 h-11"
|
||||||
|
@click="onScrollToBottom"
|
||||||
|
>
|
||||||
|
<SvgIcon class="text-2xl" icon="ri:arrow-down-s-line" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
@@ -1,15 +1,57 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import { ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
|
import { NDropdown } from 'naive-ui'
|
||||||
import { HoverButton, Setting, SvgIcon, UserAvatar } from '@/components/common'
|
import { HoverButton, Setting, SvgIcon, UserAvatar } from '@/components/common'
|
||||||
|
import { useAppStore } from '@/store'
|
||||||
|
import { useIconRender } from '@/hooks/useIconRender'
|
||||||
|
|
||||||
|
const appStore = useAppStore()
|
||||||
|
|
||||||
|
const { iconRender } = useIconRender()
|
||||||
|
|
||||||
const show = ref(false)
|
const show = ref(false)
|
||||||
|
|
||||||
|
const theme = computed(() => appStore.theme)
|
||||||
|
|
||||||
|
const options = [
|
||||||
|
{
|
||||||
|
label: 'Dark',
|
||||||
|
key: 'dark',
|
||||||
|
icon: iconRender({ icon: 'ri:moon-foggy-line' }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Light',
|
||||||
|
key: 'light',
|
||||||
|
icon: iconRender({ icon: 'ri:sun-foggy-line' }),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Auto',
|
||||||
|
key: 'auto',
|
||||||
|
icon: iconRender({ icon: 'ri:contrast-line' }),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
|
||||||
|
function handleThemeChange(key: 'light' | 'dark' | 'auto') {
|
||||||
|
appStore.setTheme(key)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<footer class="flex items-center justify-between min-w-0 p-4 overflow-hidden border-t">
|
<footer class="flex items-center justify-between min-w-0 p-4 overflow-hidden border-t dark:border-neutral-800">
|
||||||
<UserAvatar />
|
<UserAvatar />
|
||||||
|
|
||||||
|
<NDropdown :options="options" placement="top" trigger="click" @select="handleThemeChange">
|
||||||
|
<HoverButton>
|
||||||
|
<span class="text-xl text-[#4f555e] dark:text-white">
|
||||||
|
<SvgIcon v-if="theme === 'dark'" icon="ri:moon-foggy-line" />
|
||||||
|
<SvgIcon v-if="theme === 'light'" icon="ri:sun-foggy-line" />
|
||||||
|
<SvgIcon v-if="theme === 'auto'" icon="ri:contrast-line" />
|
||||||
|
</span>
|
||||||
|
</HoverButton>
|
||||||
|
</NDropdown>
|
||||||
|
|
||||||
<HoverButton tooltip="Setting" @click="show = true">
|
<HoverButton tooltip="Setting" @click="show = true">
|
||||||
<span class="text-xl text-[#4f555e]">
|
<span class="text-xl text-[#4f555e] dark:text-white">
|
||||||
<SvgIcon icon="ri:settings-4-line" />
|
<SvgIcon icon="ri:settings-4-line" />
|
||||||
</span>
|
</span>
|
||||||
</HoverButton>
|
</HoverButton>
|
||||||
|
@@ -55,8 +55,8 @@ function isActive(uuid: number) {
|
|||||||
<template v-else>
|
<template v-else>
|
||||||
<div v-for="(item, index) of dataSources" :key="index">
|
<div v-for="(item, index) of dataSources" :key="index">
|
||||||
<a
|
<a
|
||||||
class="relative flex items-center gap-3 px-3 py-3 break-all border rounded-md cursor-pointer hover:bg-neutral-100 group"
|
class="relative flex items-center gap-3 px-3 py-3 break-all border rounded-md cursor-pointer hover:bg-neutral-100 group dark:border-neutral-800 dark:hover:bg-[#24272e]"
|
||||||
:class="isActive(item.uuid) && ['border-[#4b9e5f]', 'bg-neutral-100', 'text-[#4b9e5f]', 'pr-14']"
|
:class="isActive(item.uuid) && ['border-[#4b9e5f]', 'bg-neutral-100', 'text-[#4b9e5f]', 'dark:bg-[#24272e]', 'dark:border-[#4b9e5f]', 'pr-14']"
|
||||||
@click="handleSelect(item)"
|
@click="handleSelect(item)"
|
||||||
>
|
>
|
||||||
<span>
|
<span>
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
/** @type {import('tailwindcss').Config} */
|
/** @type {import('tailwindcss').Config} */
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
darkMode: 'class',
|
||||||
content: [
|
content: [
|
||||||
'./index.html',
|
'./index.html',
|
||||||
'./src/**/*.{vue,js,ts,jsx,tsx}',
|
'./src/**/*.{vue,js,ts,jsx,tsx}',
|
||||||
@@ -11,7 +12,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
keyframes: {
|
keyframes: {
|
||||||
blink: {
|
blink: {
|
||||||
'0%, 100%': { 'background-color': '#000' },
|
'0%, 100%': { 'background-color': 'currentColor' },
|
||||||
'50%': { 'background-color': 'transparent' },
|
'50%': { 'background-color': 'transparent' },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@@ -16,7 +16,6 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
},
|
},
|
||||||
// @vueuse/core 不能通过 vue-tsc 检查,所以这里需要忽略,以后将移除
|
|
||||||
"types": ["vite/client", "node", "naive-ui/volar", "web-bluetooth"]
|
"types": ["vite/client", "node", "naive-ui/volar", "web-bluetooth"]
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "dist", "service"]
|
"exclude": ["node_modules", "dist", "service"]
|
||||||
|
Reference in New Issue
Block a user