mirror of
https://github.com/Chanzhaoyu/chatgpt-web.git
synced 2025-07-29 01:43:44 +00:00
Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
b6fd9ae766 | ||
![]() |
1e2f893ef6 | ||
![]() |
10058f151c | ||
![]() |
09359c3c46 | ||
![]() |
ba83856173 | ||
![]() |
b84f7e4c72 | ||
![]() |
c0f8e4316e | ||
![]() |
bf5c0cdf04 | ||
![]() |
66cecb6049 | ||
![]() |
808ae600c2 | ||
![]() |
f40048fb08 | ||
![]() |
ac9536ab87 | ||
![]() |
938c91f635 |
3
.env
3
.env
@@ -2,3 +2,6 @@
|
|||||||
VITE_GLOB_API_URL=/api
|
VITE_GLOB_API_URL=/api
|
||||||
|
|
||||||
VITE_APP_API_BASE_URL=http://localhost:3002/
|
VITE_APP_API_BASE_URL=http://localhost:3002/
|
||||||
|
|
||||||
|
# Glob API Timeout (ms)
|
||||||
|
VITE_GLOB_API_TIMEOUT=100000
|
||||||
|
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
@@ -25,6 +25,7 @@
|
|||||||
"chatgpt",
|
"chatgpt",
|
||||||
"chenzhaoyu",
|
"chenzhaoyu",
|
||||||
"commitlint",
|
"commitlint",
|
||||||
|
"davinci",
|
||||||
"dockerhub",
|
"dockerhub",
|
||||||
"esno",
|
"esno",
|
||||||
"GPTAPI",
|
"GPTAPI",
|
||||||
|
69
CHANGELOG.md
69
CHANGELOG.md
@@ -1,11 +1,78 @@
|
|||||||
|
## v2.7.2
|
||||||
|
|
||||||
|
`2023-02-24`
|
||||||
|
### Enhancement
|
||||||
|
- 消息使用 [github-markdown-css](https://www.npmjs.com/package/github-markdown-css) 进行美化,现在支持全语法
|
||||||
|
- 移除测试无用函数
|
||||||
|
|
||||||
|
## v2.7.1
|
||||||
|
|
||||||
|
`2023-02-23`
|
||||||
|
|
||||||
|
因为消息流在 `accessToken` 中存在解析失败和消息不完整等一系列的问题,调整回正常消息形式
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
- 现在可以中断请求过长没有答复的消息
|
||||||
|
- 现在可以删除单条消息
|
||||||
|
- 设置中显示当前版本信息
|
||||||
|
|
||||||
|
### BugFix
|
||||||
|
- 回退 `2.7.0` 的消息不稳定的问题
|
||||||
|
|
||||||
|
## v2.7.0
|
||||||
|
|
||||||
|
`2023-02-23`
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
- 使用消息流返回信息,反应更迅速
|
||||||
|
|
||||||
|
### Enhancement
|
||||||
|
- 样式的一点小改动
|
||||||
|
|
||||||
|
## v2.6.2
|
||||||
|
|
||||||
|
`2023-02-22`
|
||||||
|
### BugFix
|
||||||
|
- 还原修改代理导致的异常问题
|
||||||
|
|
||||||
|
## v2.6.1
|
||||||
|
|
||||||
|
`2023-02-22`
|
||||||
|
|
||||||
|
### Feature
|
||||||
|
- 新增 `Railway` 部署模版
|
||||||
|
|
||||||
|
### BugFix
|
||||||
|
- 手动打包 `Proxy` 问题
|
||||||
|
|
||||||
|
## v2.6.0
|
||||||
|
|
||||||
|
`2023-02-21`
|
||||||
|
### Feature
|
||||||
|
- 新增对 `网页 accessToken` 调用 `ChatGPT`,更智能不过不太稳定 [#51](https://github.com/Chanzhaoyu/chatgpt-web/issues/51)
|
||||||
|
- 前端页面设置按钮显示查看当前后端服务配置
|
||||||
|
|
||||||
|
### Enhancement
|
||||||
|
- 新增 `TIMEOUT_MS` 环境变量设定后端超时时常(单位:毫秒)[#62](https://github.com/Chanzhaoyu/chatgpt-web/issues/62)
|
||||||
|
|
||||||
|
## v2.5.2
|
||||||
|
|
||||||
|
`2023-02-21`
|
||||||
|
### Feature
|
||||||
|
- 增加对 `markdown` 格式的支持 [Demo](https://github.com/Chanzhaoyu/chatgpt-web/pull/77)
|
||||||
|
### BugFix
|
||||||
|
- 重载会话时滚动条保持
|
||||||
|
|
||||||
## v2.5.1
|
## v2.5.1
|
||||||
|
|
||||||
`2023-02-21`
|
`2023-02-21`
|
||||||
|
|
||||||
### Enhancement
|
### Enhancement
|
||||||
- 调整路由模式为 `hash`
|
- 调整路由模式为 `hash`
|
||||||
- 调整新增会话添加到列表最前
|
- 调整新增会话添加到
|
||||||
- 调整移动端样式
|
- 调整移动端样式
|
||||||
|
|
||||||
|
|
||||||
## v2.5.0
|
## v2.5.0
|
||||||
|
|
||||||
`2023-02-20`
|
`2023-02-20`
|
||||||
|
148
README.md
148
README.md
@@ -1,18 +1,73 @@
|
|||||||
# ChatGPT Web
|
# ChatGPT Web
|
||||||
|
|
||||||
使用 express 和 vue3 搭建的 ChartGPT 演示网页
|
> 使用 `express` 和 `vue3` 搭建的支持 `ChatGPT` 双模型演示网页
|
||||||
|
|
||||||

|

|
||||||
|

|
||||||
|
|
||||||
> 提示:目前 `OpenAI` 开放的模型最高只有 `GPT-3`,和现在网页所使用的 `GPT-3.5` 或 `GPT-4` 有很大差距,需要等官方开放最新的模型接口。
|
- [ChatGPT Web](#chatgpt-web)
|
||||||
|
- [介绍](#介绍)
|
||||||
|
- [待实现路线](#待实现路线)
|
||||||
|
- [前置要求](#前置要求)
|
||||||
|
- [Node](#node)
|
||||||
|
- [PNPM](#pnpm)
|
||||||
|
- [填写密钥](#填写密钥)
|
||||||
|
- [安装依赖](#安装依赖)
|
||||||
|
- [后端](#后端)
|
||||||
|
- [前端](#前端)
|
||||||
|
- [测试环境运行](#测试环境运行)
|
||||||
|
- [后端服务](#后端服务)
|
||||||
|
- [前端网页](#前端网页)
|
||||||
|
- [打包](#打包)
|
||||||
|
- [使用 Docker](#使用-docker)
|
||||||
|
- [Docker 参数示例](#docker-参数示例)
|
||||||
|
- [Docker build \& Run](#docker-build--run)
|
||||||
|
- [Docker compose](#docker-compose)
|
||||||
|
- [使用 Railway 部署](#使用-railway-部署)
|
||||||
|
- [Railway 环境变量](#railway-环境变量)
|
||||||
|
- [手动打包](#手动打包)
|
||||||
|
- [后端服务](#后端服务-1)
|
||||||
|
- [前端网页](#前端网页-1)
|
||||||
|
- [常见问题](#常见问题)
|
||||||
|
- [参与贡献](#参与贡献)
|
||||||
|
- [License](#license)
|
||||||
|
## 介绍
|
||||||
|
|
||||||
|
支持双模型,提供了两种非官方 `ChatGPT API` 方法
|
||||||
|
|
||||||
|
| 方式 | 免费? | 可靠性 | 质量 |
|
||||||
|
| ---- | ---- | ---- | ---- |
|
||||||
|
| `ChatGPTAPI(GPT-3)` | 否 | 可靠 | 较笨 |
|
||||||
|
| `ChatGPTUnofficialProxyAPI(网页 accessToken)` | 是 | 不可靠 | 聪明 |
|
||||||
|
|
||||||
|
***Note:*** 网页 `accessToken` 存在大约 8 小时,而且国内地区网络问题更推荐使用 `GPT-3` 的方式
|
||||||
|
|
||||||
|
对比:
|
||||||
|
1. `ChatGPTAPI` 使用 `text-davinci-003` 通过官方`OpenAI`补全`API`模拟`ChatGPT`(最稳健的方法,但它不是免费的,并且没有使用针对聊天进行微调的模型)
|
||||||
|
2. `ChatGPTUnofficialProxyAPI` 使用非官方代理服务器访问 `ChatGPT` 的后端`API`,绕过`Cloudflare`(使用真实的的`ChatGPT`,非常轻量级,但依赖于第三方服务器,并且有速率限制)
|
||||||
|
|
||||||
|
切换方式:
|
||||||
|
1. 进入 `service/.env` 文件
|
||||||
|
2. 使用 `OpenAI API Key` 请填写 `OPENAI_API_KEY` 字段 [(获取 apiKey)](https://platform.openai.com/overview)
|
||||||
|
3. 使用 `Web API` 请填写 `OPENAI_ACCESS_TOKEN` 字段 [(获取 accessToken)](https://chat.openai.com/api/auth/session)
|
||||||
|
4. 同时存在时以 `OpenAI API Key` 优先
|
||||||
|
|
||||||
|
反向代理:
|
||||||
|
|
||||||
|
`ChatGPTUnofficialProxyAPI`时可用 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy)
|
||||||
|
|
||||||
|
```shell
|
||||||
|
# service/.env
|
||||||
|
API_REVERSE_PROXY=
|
||||||
|
```
|
||||||
|
|
||||||
## 待实现路线
|
## 待实现路线
|
||||||
|
[✓] 双模型
|
||||||
|
|
||||||
[✓] 多会话储存和上下文逻辑
|
[✓] 多会话储存和上下文逻辑
|
||||||
|
|
||||||
[✓] 对代码等消息类型的格式化美化处理
|
[✓] 对代码等消息类型的格式化美化处理
|
||||||
|
|
||||||
[✗] 用户模块(注册、登录、个人中心)
|
|
||||||
|
|
||||||
[✗] 界面多语言
|
[✗] 界面多语言
|
||||||
|
|
||||||
[✗] 界面主题
|
[✗] 界面主题
|
||||||
@@ -23,7 +78,7 @@
|
|||||||
|
|
||||||
### Node
|
### Node
|
||||||
|
|
||||||
`node` 需要 `^16 || ^18` 版本(或者 `node >= 14` 需要安装 [fetch polyfill](https://github.com/developit/unfetch#usage-as-a-polyfill)),使用 [nvm](https://github.com/nvm-sh/nvm) 可管理本地多个 `node` 版本
|
`node` 需要 `^16 || ^18` 版本(`node >= 14` 需要安装 [fetch polyfill](https://github.com/developit/unfetch#usage-as-a-polyfill)),使用 [nvm](https://github.com/nvm-sh/nvm) 可管理本地多个 `node` 版本
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
node -v
|
node -v
|
||||||
@@ -35,19 +90,24 @@ node -v
|
|||||||
npm install pnpm -g
|
npm install pnpm -g
|
||||||
```
|
```
|
||||||
|
|
||||||
### OpenAI API Key
|
### 填写密钥
|
||||||
注册并获取 [OpenAI API key](https://platform.openai.com/overview) 并填写到本地环境变量
|
获取 `Openai Api Key` 或 `accessToken` 并填写本地环境变量 [跳转](#介绍)
|
||||||
|
|
||||||
```
|
```
|
||||||
# service/.env 文件
|
# service/.env 文件
|
||||||
|
|
||||||
OPENAI_API_KEY='Your key'
|
# OpenAI API Key - https://platform.openai.com/overview
|
||||||
|
OPENAI_API_KEY=
|
||||||
|
|
||||||
|
# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
|
||||||
|
OPENAI_ACCESS_TOKEN=
|
||||||
```
|
```
|
||||||
|
|
||||||
## 安装依赖
|
## 安装依赖
|
||||||
|
|
||||||
> 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。
|
> 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。
|
||||||
|
|
||||||
### 后端服务
|
### 后端
|
||||||
|
|
||||||
进入文件夹 `/service` 运行以下命令
|
进入文件夹 `/service` 运行以下命令
|
||||||
|
|
||||||
@@ -55,14 +115,13 @@ OPENAI_API_KEY='Your key'
|
|||||||
pnpm install
|
pnpm install
|
||||||
```
|
```
|
||||||
|
|
||||||
### 网页
|
### 前端
|
||||||
根目录下运行以下命令
|
根目录下运行以下命令
|
||||||
```shell
|
```shell
|
||||||
pnpm bootstrap
|
pnpm bootstrap
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 测试环境运行
|
||||||
## 运行
|
|
||||||
### 后端服务
|
### 后端服务
|
||||||
|
|
||||||
进入文件夹 `/service` 运行以下命令
|
进入文件夹 `/service` 运行以下命令
|
||||||
@@ -71,22 +130,41 @@ pnpm bootstrap
|
|||||||
pnpm start
|
pnpm start
|
||||||
```
|
```
|
||||||
|
|
||||||
### 网页
|
### 前端网页
|
||||||
根目录下运行以下命令
|
根目录下运行以下命令
|
||||||
```shell
|
```shell
|
||||||
pnpm dev
|
pnpm dev
|
||||||
```
|
```
|
||||||
|
|
||||||
## 打包
|
## 打包
|
||||||
## Docker build
|
|
||||||
|
|
||||||
[参考信息](https://github.com/Chanzhaoyu/chatgpt-web/pull/42)
|
### 使用 Docker
|
||||||
|
|
||||||
|
#### Docker 参数示例
|
||||||
|
|
||||||
|
- `OPENAI_API_KEY` 二选一
|
||||||
|
- `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先
|
||||||
|
- `API_REVERSE_PROXY` 可选,设置 `OPENAI_ACCESS_TOKEN` 时可用 [参考](#介绍)
|
||||||
|
- `TIMEOUT_MS` 超时,单位毫秒,可选
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### Docker build & Run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
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 -d -p 3002:3002 --env OPENAI_API_KEY=your_api_key chatgpt-web
|
||||||
|
|
||||||
|
# 运行地址
|
||||||
|
http://localhost:3002/
|
||||||
```
|
```
|
||||||
|
|
||||||
## Docker compose
|
#### Docker compose
|
||||||
|
|
||||||
[Hub 地址](https://hub.docker.com/repository/docker/chenzhaoyu94/chatgpt-web/general)
|
[Hub 地址](https://hub.docker.com/repository/docker/chenzhaoyu94/chatgpt-web/general)
|
||||||
|
|
||||||
@@ -99,13 +177,37 @@ services:
|
|||||||
ports:
|
ports:
|
||||||
- 3002:3002
|
- 3002:3002
|
||||||
environment:
|
environment:
|
||||||
|
# 二选一
|
||||||
OPENAI_API_KEY: xxxxxx
|
OPENAI_API_KEY: xxxxxx
|
||||||
|
# 二选一
|
||||||
|
OPENAI_ACCESS_TOKEN: xxxxxx
|
||||||
|
# 反向代理,可选
|
||||||
|
API_REVERSE_PROXY: xxx
|
||||||
|
# 超时,单位毫秒,可选
|
||||||
|
TIMEOUT_MS: 60000
|
||||||
```
|
```
|
||||||
|
|
||||||
### 后端服务
|
### 使用 Railway 部署
|
||||||
|
|
||||||
|
[](https://railway.app/new/template/yytmgc)
|
||||||
|
|
||||||
|
#### Railway 环境变量
|
||||||
|
|
||||||
|
| 环境变量名称 | 必填 | 备注 |
|
||||||
|
| --------------------------- | ---- | ----------------------- |
|
||||||
|
| `PORT` | 必填 | 默认 `3002` |
|
||||||
|
| `TIMEOUT_MS` | 可选 | 超时时间,单位毫秒, |
|
||||||
|
| `OPENAI_API_KEY` | `OpenAI API` 二选一 | 使用 `OpenAI API` 所需的 `apiKey` [(获取 apiKey)](https://platform.openai.com/overview) |
|
||||||
|
| `OPENAI_ACCESS_TOKEN` | `Web API` 二选一 | 使用 `Web API` 所需的 `accessToken` [(获取 accessToken)](https://chat.openai.com/api/auth/session) |
|
||||||
|
| `API_REVERSE_PROXY` | 可选,`Web API` 时可用 | `Web API` 反向代理地址 [详情](https://github.com/transitive-bullshit/chatgpt-api#reverse-proxy) |
|
||||||
|
|
||||||
|
> 注意: `Railway` 修改环境变量会重新 `Deploy`
|
||||||
|
|
||||||
|
### 手动打包
|
||||||
|
#### 后端服务
|
||||||
> 如果你不需要本项目的 `node` 接口,可以省略如下操作
|
> 如果你不需要本项目的 `node` 接口,可以省略如下操作
|
||||||
|
|
||||||
复制 `service` 文件夹到你有 `node` 服务环境的服务器上。(搜索关键字:`express部署`)
|
复制 `service` 文件夹到你有 `node` 服务环境的服务器上。
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# 安装
|
# 安装
|
||||||
@@ -120,9 +222,11 @@ pnpm prod
|
|||||||
|
|
||||||
PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
|
PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
|
||||||
|
|
||||||
### 前端打包
|
#### 前端网页
|
||||||
|
|
||||||
根目录下运行以下命令,然后将 `dist` 文件夹复制到你的托管服务器上
|
1、修改根目录下 `.env` 内 `VITE_APP_API_BASE_URL` 为你的实际后端接口地址
|
||||||
|
|
||||||
|
2、根目录下运行以下命令,然后将 `dist` 文件夹内的文件复制到你网站服务的根目录下
|
||||||
|
|
||||||
[参考信息](https://cn.vitejs.dev/guide/static-deploy.html#building-the-app)
|
[参考信息](https://cn.vitejs.dev/guide/static-deploy.html#building-the-app)
|
||||||
|
|
||||||
@@ -130,7 +234,7 @@ PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
|
|||||||
pnpm build
|
pnpm build
|
||||||
```
|
```
|
||||||
|
|
||||||
### 常见问题
|
## 常见问题
|
||||||
Q: 为什么 `Git` 提交总是报错?
|
Q: 为什么 `Git` 提交总是报错?
|
||||||
|
|
||||||
A: 因为有提交信息验证,请遵循 [Commit 指南](./CONTRIBUTING.md)
|
A: 因为有提交信息验证,请遵循 [Commit 指南](./CONTRIBUTING.md)
|
||||||
|
1
config/index.ts
Normal file
1
config/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './proxy'
|
16
config/proxy.ts
Normal file
16
config/proxy.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import type { ProxyOptions } from 'vite'
|
||||||
|
|
||||||
|
export function createViteProxy(isOpenProxy: boolean, viteEnv: ImportMetaEnv) {
|
||||||
|
if (!isOpenProxy)
|
||||||
|
return
|
||||||
|
|
||||||
|
const proxy: Record<string, string | ProxyOptions> = {
|
||||||
|
'/api': {
|
||||||
|
target: viteEnv.VITE_APP_API_BASE_URL,
|
||||||
|
changeOrigin: true,
|
||||||
|
rewrite: path => path.replace('/api/', '/'),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
return proxy
|
||||||
|
}
|
BIN
docs/cover.png
BIN
docs/cover.png
Binary file not shown.
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 96 KiB |
BIN
docs/cover2.png
Normal file
BIN
docs/cover2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 518 KiB |
BIN
docs/docker.png
Normal file
BIN
docs/docker.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 108 KiB |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "chatgpt-web",
|
"name": "chatgpt-web",
|
||||||
"version": "2.5.1",
|
"version": "2.7.2",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "ChatGPT Web",
|
"description": "ChatGPT Web",
|
||||||
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
"author": "ChenZhaoYu <chenzhaoyu1994@gmail.com>",
|
||||||
@@ -24,7 +24,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vueuse/core": "^9.13.0",
|
"@vueuse/core": "^9.13.0",
|
||||||
|
"github-markdown-css": "^5.2.0",
|
||||||
"highlight.js": "^11.7.0",
|
"highlight.js": "^11.7.0",
|
||||||
|
"marked": "^4.2.12",
|
||||||
"naive-ui": "^2.34.3",
|
"naive-ui": "^2.34.3",
|
||||||
"pinia": "^2.0.30",
|
"pinia": "^2.0.30",
|
||||||
"vue": "^3.2.47",
|
"vue": "^3.2.47",
|
||||||
@@ -36,6 +38,7 @@
|
|||||||
"@commitlint/config-conventional": "^17.4.4",
|
"@commitlint/config-conventional": "^17.4.4",
|
||||||
"@iconify/vue": "^4.1.0",
|
"@iconify/vue": "^4.1.0",
|
||||||
"@types/crypto-js": "^4.1.1",
|
"@types/crypto-js": "^4.1.1",
|
||||||
|
"@types/marked": "^4.0.8",
|
||||||
"@types/node": "^18.14.0",
|
"@types/node": "^18.14.0",
|
||||||
"@types/web-bluetooth": "^0.0.16",
|
"@types/web-bluetooth": "^0.0.16",
|
||||||
"@vitejs/plugin-vue": "^4.0.0",
|
"@vitejs/plugin-vue": "^4.0.0",
|
||||||
|
20
pnpm-lock.yaml
generated
20
pnpm-lock.yaml
generated
@@ -6,6 +6,7 @@ specifiers:
|
|||||||
'@commitlint/config-conventional': ^17.4.4
|
'@commitlint/config-conventional': ^17.4.4
|
||||||
'@iconify/vue': ^4.1.0
|
'@iconify/vue': ^4.1.0
|
||||||
'@types/crypto-js': ^4.1.1
|
'@types/crypto-js': ^4.1.1
|
||||||
|
'@types/marked': ^4.0.8
|
||||||
'@types/node': ^18.14.0
|
'@types/node': ^18.14.0
|
||||||
'@types/web-bluetooth': ^0.0.16
|
'@types/web-bluetooth': ^0.0.16
|
||||||
'@vitejs/plugin-vue': ^4.0.0
|
'@vitejs/plugin-vue': ^4.0.0
|
||||||
@@ -14,10 +15,12 @@ specifiers:
|
|||||||
axios: ^1.3.3
|
axios: ^1.3.3
|
||||||
crypto-js: ^4.1.1
|
crypto-js: ^4.1.1
|
||||||
eslint: ^8.34.0
|
eslint: ^8.34.0
|
||||||
|
github-markdown-css: ^5.2.0
|
||||||
highlight.js: ^11.7.0
|
highlight.js: ^11.7.0
|
||||||
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
|
||||||
|
marked: ^4.2.12
|
||||||
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.30
|
pinia: ^2.0.30
|
||||||
@@ -32,7 +35,9 @@ specifiers:
|
|||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
'@vueuse/core': 9.13.0_vue@3.2.47
|
'@vueuse/core': 9.13.0_vue@3.2.47
|
||||||
|
github-markdown-css: 5.2.0
|
||||||
highlight.js: 11.7.0
|
highlight.js: 11.7.0
|
||||||
|
marked: 4.2.12
|
||||||
naive-ui: 2.34.3_vue@3.2.47
|
naive-ui: 2.34.3_vue@3.2.47
|
||||||
pinia: 2.0.30_hmuptsblhheur2tugfgucj7gc4
|
pinia: 2.0.30_hmuptsblhheur2tugfgucj7gc4
|
||||||
vue: 3.2.47
|
vue: 3.2.47
|
||||||
@@ -44,6 +49,7 @@ devDependencies:
|
|||||||
'@commitlint/config-conventional': 17.4.4
|
'@commitlint/config-conventional': 17.4.4
|
||||||
'@iconify/vue': 4.1.0_vue@3.2.47
|
'@iconify/vue': 4.1.0_vue@3.2.47
|
||||||
'@types/crypto-js': 4.1.1
|
'@types/crypto-js': 4.1.1
|
||||||
|
'@types/marked': 4.0.8
|
||||||
'@types/node': 18.14.0
|
'@types/node': 18.14.0
|
||||||
'@types/web-bluetooth': 0.0.16
|
'@types/web-bluetooth': 0.0.16
|
||||||
'@vitejs/plugin-vue': 4.0.0_vite@4.1.2+vue@3.2.47
|
'@vitejs/plugin-vue': 4.0.0_vite@4.1.2+vue@3.2.47
|
||||||
@@ -735,6 +741,10 @@ packages:
|
|||||||
resolution: {integrity: sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==}
|
resolution: {integrity: sha512-BdZ5BCCvho3EIXw6wUCXHe7rS53AIDPLE+JzwgT+OsJk53oBfbSmZZ7CX4VaRoN78N+TJpFi9QPlfIVNmJYWxQ==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/@types/marked/4.0.8:
|
||||||
|
resolution: {integrity: sha512-HVNzMT5QlWCOdeuBsgXP8EZzKUf0+AXzN+sLmjvaB3ZlLqO+e4u0uXrdw9ub69wBKFs+c6/pA4r9sy6cCDvImw==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/mdast/3.0.10:
|
/@types/mdast/3.0.10:
|
||||||
resolution: {integrity: sha512-W864tg/Osz1+9f4lrGTZpCSO5/z4608eUp19tbozkq2HJK6i3z1kT0H9tlADXuYIb1YYOBByU4Jsqkk75q48qA==}
|
resolution: {integrity: sha512-W864tg/Osz1+9f4lrGTZpCSO5/z4608eUp19tbozkq2HJK6i3z1kT0H9tlADXuYIb1YYOBByU4Jsqkk75q48qA==}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -2516,6 +2526,10 @@ packages:
|
|||||||
through2: 4.0.2
|
through2: 4.0.2
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/github-markdown-css/5.2.0:
|
||||||
|
resolution: {integrity: sha512-hq5RaCInSUZ48bImOZpkppW2/MT44StRgsbsZ8YA4vJFwLKB/Vo3k7R2t+pUGqO+ThG0QDMi96TewV/B3vyItg==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/glob-parent/5.1.2:
|
/glob-parent/5.1.2:
|
||||||
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
|
resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==}
|
||||||
engines: {node: '>= 6'}
|
engines: {node: '>= 6'}
|
||||||
@@ -3229,6 +3243,12 @@ packages:
|
|||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/marked/4.2.12:
|
||||||
|
resolution: {integrity: sha512-yr8hSKa3Fv4D3jdZmtMMPghgVt6TWbk86WQaWhDloQjRSQhMMYCAro7jP7VDJrjjdV8pxVxMssXS8B8Y5DZ5aw==}
|
||||||
|
engines: {node: '>= 12'}
|
||||||
|
hasBin: true
|
||||||
|
dev: false
|
||||||
|
|
||||||
/mdast-util-from-markdown/0.8.5:
|
/mdast-util-from-markdown/0.8.5:
|
||||||
resolution: {integrity: sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==}
|
resolution: {integrity: sha512-2hkTXtYYnr+NubD/g6KGBS/0mFmBcifAsI0yIWRiRo0PjVs6SSOSOdtzbp6kSGnShDN6G5aWZpKQ2lWRy27mWQ==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@@ -1,2 +1,11 @@
|
|||||||
# OpenAI API Key - https://platform.openai.com/overview
|
# OpenAI API Key - https://platform.openai.com/overview
|
||||||
OPENAI_API_KEY=
|
OPENAI_API_KEY=
|
||||||
|
|
||||||
|
# change this to an `accessToken` extracted from the ChatGPT site's `https://chat.openai.com/api/auth/session` response
|
||||||
|
OPENAI_ACCESS_TOKEN=
|
||||||
|
|
||||||
|
# Reverse Proxy
|
||||||
|
API_REVERSE_PROXY=
|
||||||
|
|
||||||
|
# timeout
|
||||||
|
TIMEOUT_MS=60000
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "esno ./src/index.ts",
|
"start": "esno ./src/index.ts",
|
||||||
|
"dev": "esno watch ./src/index.ts",
|
||||||
"prod": "esno ./build/index.js",
|
"prod": "esno ./build/index.js",
|
||||||
"build": "pnpm clean && tsup",
|
"build": "pnpm clean && tsup",
|
||||||
"clean": "rimraf build",
|
"clean": "rimraf build",
|
||||||
@@ -23,7 +24,7 @@
|
|||||||
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml"
|
"common:cleanup": "rimraf node_modules && rimraf pnpm-lock.yaml"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"chatgpt": "^4.7.1",
|
"chatgpt": "^4.7.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",
|
||||||
|
8
service/pnpm-lock.yaml
generated
8
service/pnpm-lock.yaml
generated
@@ -4,7 +4,7 @@ specifiers:
|
|||||||
'@antfu/eslint-config': ^0.35.2
|
'@antfu/eslint-config': ^0.35.2
|
||||||
'@types/express': ^4.17.17
|
'@types/express': ^4.17.17
|
||||||
'@types/node': ^18.14.0
|
'@types/node': ^18.14.0
|
||||||
chatgpt: ^4.7.1
|
chatgpt: ^4.7.2
|
||||||
dotenv: ^16.0.3
|
dotenv: ^16.0.3
|
||||||
eslint: ^8.34.0
|
eslint: ^8.34.0
|
||||||
esno: ^0.16.3
|
esno: ^0.16.3
|
||||||
@@ -15,7 +15,7 @@ specifiers:
|
|||||||
typescript: ^4.9.5
|
typescript: ^4.9.5
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
chatgpt: 4.7.1
|
chatgpt: 4.7.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
|
||||||
@@ -878,8 +878,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
resolution: {integrity: sha512-mKKUkUbhPpQlCOfIuZkvSEgktjPFIsZKRRbC6KWVEMvlzblj3i3asQv5ODsrwt0N3pHAEvjP8KTQPHkp0+6jOg==}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/chatgpt/4.7.1:
|
/chatgpt/4.7.2:
|
||||||
resolution: {integrity: sha512-FRXfpjn//Y4gUMcUo60W5byJ0CbFhC1Xp3PCm2qcBthBYFbC+LyRrwxvSVTdNwgQywHV4Pc5SFkaZ72f5rCNdQ==}
|
resolution: {integrity: sha512-c5CNqvB98IMEz/Byopwu5FlXGS3w/3iNiZITdDlcZLue4VSjEfzMRWrOrdGidzcE+ud2My6nO8/sSnY7W04WJA==}
|
||||||
engines: {node: '>=14'}
|
engines: {node: '>=14'}
|
||||||
hasBin: true
|
hasBin: true
|
||||||
dependencies:
|
dependencies:
|
||||||
|
@@ -1,27 +1,46 @@
|
|||||||
import * as dotenv from 'dotenv'
|
import * as dotenv from 'dotenv'
|
||||||
import 'isomorphic-fetch'
|
import 'isomorphic-fetch'
|
||||||
import type { ChatGPTAPI, SendMessageOptions } from 'chatgpt'
|
import type { ChatGPTAPI, ChatMessage, SendMessageOptions } from 'chatgpt'
|
||||||
|
import { ChatGPTUnofficialProxyAPI } from 'chatgpt'
|
||||||
import { sendResponse } from './utils'
|
import { sendResponse } from './utils'
|
||||||
|
|
||||||
export interface ChatContext {
|
dotenv.config()
|
||||||
|
|
||||||
|
let apiModel: 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI' | undefined
|
||||||
|
|
||||||
|
interface ChatContext {
|
||||||
conversationId?: string
|
conversationId?: string
|
||||||
parentMessageId?: string
|
parentMessageId?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
dotenv.config()
|
const timeoutMs: number = !isNaN(+process.env.TIMEOUT_MS) ? +process.env.TIMEOUT_MS : 30 * 1000
|
||||||
|
|
||||||
const apiKey = process.env.OPENAI_API_KEY
|
if (!process.env.OPENAI_API_KEY && !process.env.OPENAI_ACCESS_TOKEN)
|
||||||
|
throw new Error('Missing OPENAI_API_KEY or OPENAI_ACCESS_TOKEN environment variable')
|
||||||
|
|
||||||
if (apiKey === undefined)
|
let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
|
||||||
throw new Error('OPENAI_API_KEY is not defined')
|
|
||||||
|
|
||||||
let api: ChatGPTAPI
|
|
||||||
|
|
||||||
// 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')
|
const { ChatGPTAPI } = await import('chatgpt')
|
||||||
api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })
|
|
||||||
|
if (process.env.OPENAI_API_KEY) {
|
||||||
|
api = new ChatGPTAPI({ apiKey: process.env.OPENAI_API_KEY })
|
||||||
|
apiModel = 'ChatGPTAPI'
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
let options = {}
|
||||||
|
|
||||||
|
if (process.env.API_REVERSE_PROXY)
|
||||||
|
options = { apiReverseProxyUrl: process.env.API_REVERSE_PROXY }
|
||||||
|
|
||||||
|
api = new ChatGPTUnofficialProxyAPI({
|
||||||
|
accessToken: process.env.OPENAI_ACCESS_TOKEN,
|
||||||
|
...options,
|
||||||
|
})
|
||||||
|
apiModel = 'ChatGPTUnofficialProxyAPI'
|
||||||
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
async function chatReply(
|
async function chatReply(
|
||||||
@@ -32,7 +51,7 @@ async function chatReply(
|
|||||||
return sendResponse({ type: 'Fail', message: 'Message is empty' })
|
return sendResponse({ type: 'Fail', message: 'Message is empty' })
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let options: SendMessageOptions = { timeoutMs: 30 * 1000 }
|
let options: SendMessageOptions = { timeoutMs }
|
||||||
|
|
||||||
if (lastContext)
|
if (lastContext)
|
||||||
options = { ...lastContext }
|
options = { ...lastContext }
|
||||||
@@ -46,4 +65,17 @@ async function chatReply(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { chatReply }
|
async function chatConfig() {
|
||||||
|
return sendResponse({
|
||||||
|
type: 'Success',
|
||||||
|
data: {
|
||||||
|
apiModel,
|
||||||
|
reverseProxy: process.env.API_REVERSE_PROXY,
|
||||||
|
timeoutMs,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export type { ChatContext, ChatMessage }
|
||||||
|
|
||||||
|
export { chatReply, chatConfig }
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
import express from 'express'
|
import express from 'express'
|
||||||
import type { ChatContext } from './chatgpt'
|
import type { ChatContext } from './chatgpt'
|
||||||
import { chatReply } from './chatgpt'
|
import { chatConfig, chatReply } from './chatgpt'
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
const router = express.Router()
|
const router = express.Router()
|
||||||
@@ -26,6 +26,16 @@ router.post('/chat', async (req, res) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.post('/config', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const response = await chatConfig()
|
||||||
|
res.send(response)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
res.send(error)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
app.use('', router)
|
app.use('', router)
|
||||||
app.use('/api', router)
|
app.use('/api', router)
|
||||||
|
|
||||||
|
@@ -12,3 +12,9 @@ export function fetchChatAPI<T = any>(
|
|||||||
signal,
|
signal,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function fetchChatConfig<T = any>() {
|
||||||
|
return post<T>({
|
||||||
|
url: '/config',
|
||||||
|
})
|
||||||
|
}
|
||||||
|
75
src/components/common/Setting/index.vue
Normal file
75
src/components/common/Setting/index.vue
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<script setup lang='ts'>
|
||||||
|
import { computed, ref, watch } from 'vue'
|
||||||
|
import { NCard, NModal } from 'naive-ui'
|
||||||
|
import pkg from '../../../../package.json'
|
||||||
|
import { fetchChatConfig } from '@/api'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
visible: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Emit {
|
||||||
|
(e: 'update:visible', visible: boolean): void
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ConfigState {
|
||||||
|
timeoutMs?: number
|
||||||
|
reverseProxy?: string
|
||||||
|
apiModel?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
|
const emit = defineEmits<Emit>()
|
||||||
|
|
||||||
|
const show = computed({
|
||||||
|
get() {
|
||||||
|
return props.visible
|
||||||
|
},
|
||||||
|
set(visible: boolean) {
|
||||||
|
emit('update:visible', visible)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const config = ref<ConfigState>()
|
||||||
|
|
||||||
|
async function fetchConfig() {
|
||||||
|
try {
|
||||||
|
const { data } = await fetchChatConfig<ConfigState>()
|
||||||
|
config.value = data
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.visible,
|
||||||
|
(val) => {
|
||||||
|
if (val)
|
||||||
|
fetchConfig()
|
||||||
|
},
|
||||||
|
)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<NModal v-model:show="show" style="width: 80%; max-width: 460px;">
|
||||||
|
<NCard>
|
||||||
|
<div class="space-y-4">
|
||||||
|
<h2 class="text-xl font-bold text-center">
|
||||||
|
Version - {{ pkg.version }}
|
||||||
|
</h2>
|
||||||
|
<hr>
|
||||||
|
<p>
|
||||||
|
此项目开源于
|
||||||
|
<a class="text-blue-600" href="https://github.com/Chanzhaoyu/chatgpt-web" target="_blank">Github</a>
|
||||||
|
,免费并且协议为 MIT,其他来源均为盗版,使用时请注意。如果你觉得此项目对你有帮助,请帮我点个 Star,谢谢!
|
||||||
|
</p>
|
||||||
|
<hr>
|
||||||
|
<p>API方式:{{ config?.apiModel ?? '-' }}</p>
|
||||||
|
<p>反向代理:{{ config?.reverseProxy ?? '-' }}</p>
|
||||||
|
<p>超时时间:{{ config?.timeoutMs ?? '-' }}</p>
|
||||||
|
</div>
|
||||||
|
</NCard>
|
||||||
|
</NModal>
|
||||||
|
</template>
|
@@ -2,5 +2,6 @@ import HoverButton from './HoverButton/index.vue'
|
|||||||
import NaiveProvider from './NaiveProvider/index.vue'
|
import NaiveProvider from './NaiveProvider/index.vue'
|
||||||
import SvgIcon from './SvgIcon/index.vue'
|
import SvgIcon from './SvgIcon/index.vue'
|
||||||
import UserAvatar from './UserAvatar/index.vue'
|
import UserAvatar from './UserAvatar/index.vue'
|
||||||
|
import Setting from './Setting/index.vue'
|
||||||
|
|
||||||
export { HoverButton, NaiveProvider, SvgIcon, UserAvatar }
|
export { HoverButton, NaiveProvider, SvgIcon, UserAvatar, Setting }
|
||||||
|
@@ -1,21 +0,0 @@
|
|||||||
import type { App, Directive } from 'vue'
|
|
||||||
import hljs from 'highlight.js'
|
|
||||||
|
|
||||||
function highlightCode(el: HTMLElement) {
|
|
||||||
const regexp = /^(?:\s{4}|\t).+/gm
|
|
||||||
if (el.textContent?.indexOf(' = ') !== -1 || el.textContent.match(regexp))
|
|
||||||
hljs.highlightBlock(el)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function setupHighlightDirective(app: App) {
|
|
||||||
const highLightDirective: Directive<HTMLElement> = {
|
|
||||||
mounted(el: HTMLElement) {
|
|
||||||
highlightCode(el)
|
|
||||||
},
|
|
||||||
updated(el: HTMLElement) {
|
|
||||||
highlightCode(el)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
app.directive('highlight', highLightDirective)
|
|
||||||
}
|
|
@@ -1,6 +1 @@
|
|||||||
import type { App } from 'vue'
|
export function setupDirectives() {}
|
||||||
import setupHighlightDirective from './highlight'
|
|
||||||
|
|
||||||
export function setupDirectives(app: App) {
|
|
||||||
setupHighlightDirective(app)
|
|
||||||
}
|
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import { setupDirectives } from './directives'
|
|
||||||
import { setupAssets } from '@/plugins'
|
import { setupAssets } from '@/plugins'
|
||||||
import { setupStore } from '@/store'
|
import { setupStore } from '@/store'
|
||||||
import { setupRouter } from '@/router'
|
import { setupRouter } from '@/router'
|
||||||
@@ -11,8 +10,6 @@ async function bootstrap() {
|
|||||||
|
|
||||||
setupStore(app)
|
setupStore(app)
|
||||||
|
|
||||||
setupDirectives(app)
|
|
||||||
|
|
||||||
await setupRouter(app)
|
await setupRouter(app)
|
||||||
|
|
||||||
app.mount('#app')
|
app.mount('#app')
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import 'highlight.js/styles/xcode.css'
|
import 'highlight.js/styles/xcode.css'
|
||||||
|
import 'github-markdown-css/github-markdown.css'
|
||||||
import '@/styles/global.css'
|
import '@/styles/global.css'
|
||||||
|
|
||||||
/** Tailwind's Preflight Style Override */
|
/** Tailwind's Preflight Style Override */
|
||||||
|
@@ -110,6 +110,22 @@ export const useChatStore = defineStore('chat-store', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
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) {
|
||||||
|
1
src/typings/env.d.ts
vendored
1
src/typings/env.d.ts
vendored
@@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
6
src/utils/functions/includeCode.ts
Normal file
6
src/utils/functions/includeCode.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
function includeCode(text: string | null | undefined) {
|
||||||
|
const regexp = /^(?:\s{4}|\t).+/gm
|
||||||
|
return !!(text?.includes(' = ') || text?.match(regexp))
|
||||||
|
}
|
||||||
|
|
||||||
|
export default includeCode
|
@@ -2,7 +2,7 @@ import axios, { type AxiosResponse } from 'axios'
|
|||||||
|
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: import.meta.env.VITE_GLOB_API_URL,
|
baseURL: import.meta.env.VITE_GLOB_API_URL,
|
||||||
timeout: 30 * 1000,
|
timeout: !isNaN(+import.meta.env.VITE_GLOB_API_TIMEOUT) ? Number(import.meta.env.VITE_GLOB_API_TIMEOUT) : 60 * 1000,
|
||||||
})
|
})
|
||||||
|
|
||||||
service.interceptors.request.use(
|
service.interceptors.request.use(
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import type { AxiosResponse, GenericAbortSignal } from 'axios'
|
import type { AxiosProgressEvent, AxiosResponse, GenericAbortSignal } from 'axios'
|
||||||
import request from './axios'
|
import request from './axios'
|
||||||
|
|
||||||
export interface HttpOption {
|
export interface HttpOption {
|
||||||
@@ -6,6 +6,7 @@ export interface HttpOption {
|
|||||||
data?: any
|
data?: any
|
||||||
method?: string
|
method?: string
|
||||||
headers?: any
|
headers?: any
|
||||||
|
onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void
|
||||||
signal?: GenericAbortSignal
|
signal?: GenericAbortSignal
|
||||||
beforeRequest?: () => void
|
beforeRequest?: () => void
|
||||||
afterRequest?: () => void
|
afterRequest?: () => void
|
||||||
@@ -17,9 +18,11 @@ export interface Response<T = any> {
|
|||||||
status: string
|
status: string
|
||||||
}
|
}
|
||||||
|
|
||||||
function http<T = any>({ url, data, method, headers, signal, beforeRequest, afterRequest }: HttpOption) {
|
function http<T = any>(
|
||||||
|
{ url, data, method, headers, onDownloadProgress, signal, beforeRequest, afterRequest }: HttpOption,
|
||||||
|
) {
|
||||||
const successHandler = (res: AxiosResponse<Response<T>>) => {
|
const successHandler = (res: AxiosResponse<Response<T>>) => {
|
||||||
if (res.data.status === 'Success')
|
if (res.data.status === 'Success' || typeof res.data === 'string')
|
||||||
return res.data
|
return res.data
|
||||||
|
|
||||||
return Promise.reject(res.data)
|
return Promise.reject(res.data)
|
||||||
@@ -37,17 +40,18 @@ function http<T = any>({ url, data, method, headers, signal, beforeRequest, afte
|
|||||||
const params = Object.assign(typeof data === 'function' ? data() : data ?? {}, {})
|
const params = Object.assign(typeof data === 'function' ? data() : data ?? {}, {})
|
||||||
|
|
||||||
return method === 'GET'
|
return method === 'GET'
|
||||||
? request.get(url, { params, signal }).then(successHandler, failHandler)
|
? request.get(url, { params, signal, onDownloadProgress }).then(successHandler, failHandler)
|
||||||
: request.post(url, params, { headers, signal }).then(successHandler, failHandler)
|
: request.post(url, params, { headers, signal, onDownloadProgress }).then(successHandler, failHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function get<T = any>(
|
export function get<T = any>(
|
||||||
{ url, data, method = 'GET', signal, beforeRequest, afterRequest }: HttpOption,
|
{ url, data, method = 'GET', onDownloadProgress, signal, beforeRequest, afterRequest }: HttpOption,
|
||||||
): Promise<Response<T>> {
|
): Promise<Response<T>> {
|
||||||
return http<T>({
|
return http<T>({
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
data,
|
data,
|
||||||
|
onDownloadProgress,
|
||||||
signal,
|
signal,
|
||||||
beforeRequest,
|
beforeRequest,
|
||||||
afterRequest,
|
afterRequest,
|
||||||
@@ -55,13 +59,14 @@ export function get<T = any>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function post<T = any>(
|
export function post<T = any>(
|
||||||
{ url, data, method = 'POST', headers, signal, beforeRequest, afterRequest }: HttpOption,
|
{ url, data, method = 'POST', headers, onDownloadProgress, signal, beforeRequest, afterRequest }: HttpOption,
|
||||||
): Promise<Response<T>> {
|
): Promise<Response<T>> {
|
||||||
return http<T>({
|
return http<T>({
|
||||||
url,
|
url,
|
||||||
method,
|
method,
|
||||||
data,
|
data,
|
||||||
headers,
|
headers,
|
||||||
|
onDownloadProgress,
|
||||||
signal,
|
signal,
|
||||||
beforeRequest,
|
beforeRequest,
|
||||||
afterRequest,
|
afterRequest,
|
||||||
|
@@ -1,28 +1,55 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import { computed } from 'vue'
|
||||||
|
import { marked } from 'marked'
|
||||||
|
import hljs from 'highlight.js'
|
||||||
|
|
||||||
|
const props = defineProps<Props>()
|
||||||
|
|
||||||
|
marked.setOptions({
|
||||||
|
renderer: new marked.Renderer(),
|
||||||
|
highlight(code) {
|
||||||
|
return hljs.highlightAuto(code).value
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
inversion?: boolean
|
inversion?: boolean
|
||||||
error?: boolean
|
error?: boolean
|
||||||
|
text?: string
|
||||||
|
loading?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
defineProps<Props>()
|
const wrapClass = computed(() => {
|
||||||
|
return [
|
||||||
|
'text-wrap',
|
||||||
|
'p-3',
|
||||||
|
'min-w-[20px]',
|
||||||
|
'rounded-md',
|
||||||
|
props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]',
|
||||||
|
{ 'text-red-500': props.error },
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const text = computed(() => {
|
||||||
|
if (props.text)
|
||||||
|
return marked(props.text)
|
||||||
|
return ''
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div :class="wrapClass">
|
||||||
class="min-w-[20px] p-2 rounded-md"
|
<template v-if="loading">
|
||||||
:class="[inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]', { 'text-red-500': error }]"
|
<span class="w-[5px] h-[20px] block animate-blink" />
|
||||||
>
|
</template>
|
||||||
<span
|
<template v-else>
|
||||||
v-highlight
|
<div class="leading-relaxed break-all">
|
||||||
class="leading-relaxed whitespace-pre-wrap"
|
<div :class="[{ 'markdown-body': !inversion }]" v-html="text" />
|
||||||
>
|
</div>
|
||||||
<slot />
|
</template>
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style>
|
<style lang="less">
|
||||||
.hljs {
|
@import url(./style.less);
|
||||||
background-color: #fff0 !important;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
<script setup lang='ts'>
|
<script setup lang='ts'>
|
||||||
import Avatar from './Avatar.vue'
|
import AvatarComponent from './Avatar.vue'
|
||||||
import Text from './Text.vue'
|
import TextComponent from './Text.vue'
|
||||||
import { SvgIcon } from '@/components/common'
|
import { SvgIcon } from '@/components/common'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -13,12 +13,18 @@ interface Props {
|
|||||||
|
|
||||||
interface Emit {
|
interface Emit {
|
||||||
(ev: 'regenerate'): void
|
(ev: 'regenerate'): void
|
||||||
|
(ev: 'copy'): void
|
||||||
|
(ev: 'delete'): void
|
||||||
}
|
}
|
||||||
|
|
||||||
defineProps<Props>()
|
defineProps<Props>()
|
||||||
|
|
||||||
const emit = defineEmits<Emit>()
|
const emit = defineEmits<Emit>()
|
||||||
|
|
||||||
|
function handleDelete() {
|
||||||
|
emit('delete')
|
||||||
|
}
|
||||||
|
|
||||||
function handleRegenerate() {
|
function handleRegenerate() {
|
||||||
emit('regenerate')
|
emit('regenerate')
|
||||||
}
|
}
|
||||||
@@ -30,24 +36,34 @@ function handleRegenerate() {
|
|||||||
class="flex items-center justify-center rounded-full overflow-hidden w-[32px] h-[32px]"
|
class="flex items-center justify-center rounded-full overflow-hidden w-[32px] h-[32px]"
|
||||||
:class="[inversion ? 'ml-3' : 'mr-3']"
|
:class="[inversion ? 'ml-3' : 'mr-3']"
|
||||||
>
|
>
|
||||||
<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="flex flex-col flex-1 text-sm" :class="[inversion ? 'items-end' : 'items-start']">
|
||||||
<span class="text-xs text-[#b4bbc4]">
|
<span class="text-xs text-[#b4bbc4]">
|
||||||
{{ dateTime }}
|
{{ dateTime }}
|
||||||
</span>
|
</span>
|
||||||
<div class="flex items-end mt-2">
|
<div class="flex items-end gap-2 mt-2" :class="[inversion ? 'flex-row-reverse' : 'flex-row']">
|
||||||
<Text :inversion="inversion" :error="error">
|
<TextComponent
|
||||||
<span v-if="loading" class="w-[3px] h-[20px] block animate-blink" />
|
:inversion="inversion"
|
||||||
<span v-else>{{ text }}</span>
|
:error="error"
|
||||||
</Text>
|
:text="text"
|
||||||
<button
|
:loading="loading"
|
||||||
v-if="!inversion && !loading"
|
/>
|
||||||
class="mb-2 ml-2 transition text-neutral-400 hover:text-neutral-800"
|
<div class="flex flex-col">
|
||||||
@click="handleRegenerate"
|
<button
|
||||||
>
|
v-if="!inversion"
|
||||||
<SvgIcon icon="ri:restart-line" />
|
class="mb-2 transition text-neutral-400 hover:text-neutral-800"
|
||||||
</button>
|
@click="handleRegenerate"
|
||||||
|
>
|
||||||
|
<SvgIcon icon="ri:restart-line" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="mb-1 transition text-neutral-400 hover:text-neutral-800"
|
||||||
|
@click="handleDelete"
|
||||||
|
>
|
||||||
|
<SvgIcon icon="ri:delete-bin-6-line" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
22
src/views/chat/components/Message/style.less
Normal file
22
src/views/chat/components/Message/style.less
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
.markdown-body {
|
||||||
|
background-color: transparent;
|
||||||
|
font-size: 14px;
|
||||||
|
|
||||||
|
ol {
|
||||||
|
list-style-type: decimal;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
list-style-type: disc;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre code,
|
||||||
|
pre tt {
|
||||||
|
line-height: 1.65;
|
||||||
|
}
|
||||||
|
|
||||||
|
.highlight pre,
|
||||||
|
pre {
|
||||||
|
background-color: #fff;
|
||||||
|
}
|
||||||
|
}
|
@@ -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,6 +14,7 @@ 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()
|
||||||
|
|
||||||
@@ -153,7 +154,6 @@ async function onRegenerate(index: number) {
|
|||||||
requestOptions: { prompt: message, ...options },
|
requestOptions: { prompt: message, ...options },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
scrollToBottom()
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { data } = await fetchChatAPI<Chat.ConversationResponse>(message, options, controller.signal)
|
const { data } = await fetchChatAPI<Chat.ConversationResponse>(message, options, controller.signal)
|
||||||
@@ -170,7 +170,6 @@ async function onRegenerate(index: number) {
|
|||||||
requestOptions: { prompt: message, ...options },
|
requestOptions: { prompt: message, ...options },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
scrollToBottom()
|
|
||||||
}
|
}
|
||||||
catch (error: any) {
|
catch (error: any) {
|
||||||
let errorMessage = 'Something went wrong, please try again later.'
|
let errorMessage = 'Something went wrong, please try again later.'
|
||||||
@@ -191,13 +190,28 @@ async function onRegenerate(index: number) {
|
|||||||
requestOptions: { prompt: message, ...options },
|
requestOptions: { prompt: message, ...options },
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
scrollToBottom()
|
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
@@ -220,10 +234,24 @@ function handleEnter(event: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleStop() {
|
||||||
|
if (loading.value) {
|
||||||
|
controller.abort()
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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(() => {
|
||||||
|
if (isMobile.value)
|
||||||
|
return ['pt-14', 'pb-14']
|
||||||
|
|
||||||
|
return []
|
||||||
|
})
|
||||||
|
|
||||||
const footerClass = computed(() => {
|
const footerClass = computed(() => {
|
||||||
let classes = ['p-4']
|
let classes = ['p-4']
|
||||||
if (isMobile.value)
|
if (isMobile.value)
|
||||||
@@ -242,7 +270,7 @@ onUnmounted(() => {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col h-full pt-14 pb-14">
|
<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 ref="scrollRef" class="h-full p-4 overflow-hidden overflow-y-auto" :class="[{ 'p-2': isMobile }]">
|
||||||
<template v-if="!dataSources.length">
|
<template v-if="!dataSources.length">
|
||||||
@@ -262,7 +290,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="flex justify-center">
|
||||||
|
<NButton v-if="loading" ghost @click="handleStop">
|
||||||
|
<template #icon>
|
||||||
|
<SvgIcon icon="ri:stop-circle-line" />
|
||||||
|
</template>
|
||||||
|
Stop Responding
|
||||||
|
</NButton>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
19
src/views/chat/layout/sider/Footer.vue
Normal file
19
src/views/chat/layout/sider/Footer.vue
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<script setup lang='ts'>
|
||||||
|
import { ref } from 'vue'
|
||||||
|
import { HoverButton, Setting, SvgIcon, UserAvatar } from '@/components/common'
|
||||||
|
|
||||||
|
const show = ref(false)
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<footer class="flex items-center justify-between min-w-0 p-4 overflow-hidden border-t">
|
||||||
|
<UserAvatar />
|
||||||
|
<HoverButton tooltip="Setting" @click="show = true">
|
||||||
|
<span class="text-xl text-[#4f555e]">
|
||||||
|
<SvgIcon icon="ri:settings-4-line" />
|
||||||
|
</span>
|
||||||
|
</HoverButton>
|
||||||
|
|
||||||
|
<Setting v-model:visible="show" />
|
||||||
|
</footer>
|
||||||
|
</template>
|
@@ -3,7 +3,7 @@ import type { CSSProperties } from 'vue'
|
|||||||
import { computed, watch } from 'vue'
|
import { computed, watch } from 'vue'
|
||||||
import { NButton, NLayoutSider } from 'naive-ui'
|
import { NButton, NLayoutSider } from 'naive-ui'
|
||||||
import List from './List.vue'
|
import List from './List.vue'
|
||||||
import { HoverButton, SvgIcon, UserAvatar } from '@/components/common'
|
import Footer from './Footer.vue'
|
||||||
import { useAppStore, useChatStore } from '@/store'
|
import { useAppStore, useChatStore } from '@/store'
|
||||||
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
import { useBasicLayout } from '@/hooks/useBasicLayout'
|
||||||
|
|
||||||
@@ -67,14 +67,7 @@ watch(
|
|||||||
<List />
|
<List />
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
<footer class="flex items-center justify-between min-w-0 p-4 overflow-hidden border-t">
|
<Footer />
|
||||||
<UserAvatar />
|
|
||||||
<HoverButton tooltip="Setting">
|
|
||||||
<span class="text-xl text-[#4f555e]">
|
|
||||||
<SvgIcon icon="ri:settings-4-line" />
|
|
||||||
</span>
|
|
||||||
</HoverButton>
|
|
||||||
</footer>
|
|
||||||
</div>
|
</div>
|
||||||
</NLayoutSider>
|
</NLayoutSider>
|
||||||
<template v-if="isMobile">
|
<template v-if="isMobile">
|
||||||
|
@@ -13,8 +13,8 @@ export default defineConfig((env) => {
|
|||||||
},
|
},
|
||||||
plugins: [vue()],
|
plugins: [vue()],
|
||||||
server: {
|
server: {
|
||||||
port: 1002,
|
|
||||||
host: '0.0.0.0',
|
host: '0.0.0.0',
|
||||||
|
port: 1002,
|
||||||
open: false,
|
open: false,
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
|
Reference in New Issue
Block a user