Compare commits

10 Commits

Author SHA1 Message Date
Redon
b6fd9ae766 feat: v2.7.2 消息样式美化和优化代码 (#111)
* perf: 优化代码

* feat: 美化消息,支持 markdown 全语法

* chore: version 2.7.2
2023-02-24 15:03:49 +08:00
Redon
1e2f893ef6 chore: version 2.7.1 (#99)
* feat: 调整流输出为实验性质

* feat: 取消回答按钮

* feat: 更新版本查看

* feat: 单消息复制和删除功能

* feat: 消除警告

* feat: 优化删除功能

* chore: version 2.7.1
2023-02-23 12:44:28 +08:00
ChenZhaoYu
10058f151c chore: version 2.7.0 2023-02-22 23:08:00 +08:00
Redon
09359c3c46 feat: 流式输出内容 (#93)
* feat: 流式输出内容

* fix: 修复异常状态

* feat: markdown 链接颜色
2023-02-22 23:03:20 +08:00
ChenZhaoYu
ba83856173 chore: v2.6.2 2023-02-22 22:57:09 +08:00
ChenZhaoYu
b84f7e4c72 fix: 还原配置 2023-02-22 22:55:53 +08:00
ChenZhaoYu
c0f8e4316e chore: version 2.6.1 2023-02-22 14:43:55 +08:00
Redon
bf5c0cdf04 fix: 手动打包 Proxy 问题(#91)
* perf: 检查代码

* feat: proxy setting

* chore: 调整为测试环境使用 `proxy`
2023-02-22 14:29:05 +08:00
Redon
66cecb6049 Update README.md 2023-02-22 10:40:26 +08:00
闫冰
808ae600c2 chore: 新增 Railway 部署模版! (#85)
* 新增使用 Railway 免费 一键部署模版!

* 修改描述

* 修改模版的必填项以及新增超时时间参数

* 移除推广code

* Update README.md

---------

Co-authored-by: Redon <790348264@qq.com>
2023-02-22 10:36:11 +08:00
22 changed files with 278 additions and 94 deletions

1
.env
View File

@@ -3,4 +3,5 @@ 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 VITE_GLOB_API_TIMEOUT=100000

View File

@@ -1,3 +1,50 @@
## 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 ## v2.6.0
`2023-02-21` `2023-02-21`

View File

@@ -1,10 +1,36 @@
# ChatGPT Web # ChatGPT Web
使用 `express``vue3` 搭建的支持 `ChatGPT` 双模型演示网页 > 使用 `express` 和 `vue3` 搭建的支持 `ChatGPT` 双模型演示网页
![cover](./docs/cover.png) ![cover](./docs/cover.png)
![cover2](./docs/cover2.png) ![cover2](./docs/cover2.png)
- [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` 方法 支持双模型,提供了两种非官方 `ChatGPT API` 方法
@@ -52,7 +78,7 @@ API_REVERSE_PROXY=
### 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
@@ -81,7 +107,7 @@ OPENAI_ACCESS_TOKEN=
> 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。 > 为了简便 `后端开发人员` 的了解负担,所以并没有采用前端 `workspace` 模式,而是分文件夹存放。如果只需要前端页面做二次开发,删除 `service` 文件夹即可。
### 后端服务 ### 后端
进入文件夹 `/service` 运行以下命令 进入文件夹 `/service` 运行以下命令
@@ -89,7 +115,7 @@ OPENAI_ACCESS_TOKEN=
pnpm install pnpm install
``` ```
### 网页 ### 前端
根目录下运行以下命令 根目录下运行以下命令
```shell ```shell
pnpm bootstrap pnpm bootstrap
@@ -114,7 +140,7 @@ pnpm dev
### 使用 Docker ### 使用 Docker
### Docker 参数示例 #### Docker 参数示例
- `OPENAI_API_KEY` 二选一 - `OPENAI_API_KEY` 二选一
- `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先 - `OPENAI_ACCESS_TOKEN` 二选一,同时存在时,`OPENAI_API_KEY` 优先
@@ -123,7 +149,7 @@ pnpm dev
![docker](./docs/docker.png) ![docker](./docs/docker.png)
### Docker build & Run #### Docker build & Run
```bash ```bash
docker build -t chatgpt-web . docker build -t chatgpt-web .
@@ -138,7 +164,7 @@ docker run --name chatgpt-web -d -p 3002:3002 --env OPENAI_API_KEY=your_api_key
http://localhost:3002/ 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)
@@ -161,9 +187,24 @@ services:
TIMEOUT_MS: 60000 TIMEOUT_MS: 60000
``` ```
### 使用 Railway 部署
## 手动打包 [![Deploy on Railway](https://railway.app/button.svg)](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` 服务环境的服务器上。 复制 `service` 文件夹到你有 `node` 服务环境的服务器上。
@@ -181,7 +222,7 @@ pnpm prod
PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可 PS: 不进行打包,直接在服务器上运行 `pnpm start` 也可
### 前端网页 #### 前端网页
1、修改根目录下 `.env``VITE_APP_API_BASE_URL` 为你的实际后端接口地址 1、修改根目录下 `.env``VITE_APP_API_BASE_URL` 为你的实际后端接口地址
@@ -193,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
View File

@@ -0,0 +1 @@
export * from './proxy'

16
config/proxy.ts Normal file
View 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
}

View File

@@ -1,6 +1,6 @@
{ {
"name": "chatgpt-web", "name": "chatgpt-web",
"version": "2.6.0", "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,6 +24,7 @@
}, },
"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", "marked": "^4.2.12",
"naive-ui": "^2.34.3", "naive-ui": "^2.34.3",

6
pnpm-lock.yaml generated
View File

@@ -15,6 +15,7 @@ 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
@@ -34,6 +35,7 @@ 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 marked: 4.2.12
naive-ui: 2.34.3_vue@3.2.47 naive-ui: 2.34.3_vue@3.2.47
@@ -2524,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'}

View File

@@ -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",

View File

@@ -1,6 +1,6 @@
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 { ChatGPTUnofficialProxyAPI } from 'chatgpt'
import { sendResponse } from './utils' import { sendResponse } from './utils'
@@ -8,7 +8,7 @@ dotenv.config()
let apiModel: 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI' | undefined let apiModel: 'ChatGPTAPI' | 'ChatGPTUnofficialProxyAPI' | undefined
export interface ChatContext { interface ChatContext {
conversationId?: string conversationId?: string
parentMessageId?: string parentMessageId?: string
} }
@@ -76,4 +76,6 @@ async function chatConfig() {
}) })
} }
export type { ChatContext, ChatMessage }
export { chatReply, chatConfig } export { chatReply, chatConfig }

View File

@@ -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 {
@@ -55,9 +56,16 @@ 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>
免费并且协议为 MIT其他来源均为盗版使用时请注意如果你觉得此项目对你有帮助请帮我点个 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>

View File

@@ -1,21 +0,0 @@
import type { App, Directive } from 'vue'
import hljs from 'highlight.js'
import includeCode from '@/utils/functions/includeCode'
function highlightCode(el: HTMLElement) {
if (includeCode(el.textContent))
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)
}

View File

@@ -1,6 +1 @@
import type { App } from 'vue' export function setupDirectives() {}
import setupHighlightDirective from './highlight'
export function setupDirectives(app: App) {
setupHighlightDirective(app)
}

View File

@@ -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')

View File

@@ -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 */

View File

@@ -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) {

View File

@@ -1,8 +1,6 @@
function includeCode(text: string | null | undefined) { function includeCode(text: string | null | undefined) {
const regexp = /^(?:\s{4}|\t).+/gm const regexp = /^(?:\s{4}|\t).+/gm
if (text?.includes(' = ') || text?.match(regexp)) return !!(text?.includes(' = ') || text?.match(regexp))
return true
return false
} }
export default includeCode export default includeCode

View File

@@ -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,

View File

@@ -1,7 +1,16 @@
<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'
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
@@ -10,12 +19,10 @@ interface Props {
loading?: boolean loading?: boolean
} }
const props = defineProps<Props>()
const wrapClass = computed(() => { const wrapClass = computed(() => {
return [ return [
'text-wrap', 'text-wrap',
'p-2', 'p-3',
'min-w-[20px]', 'min-w-[20px]',
'rounded-md', 'rounded-md',
props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]', props.inversion ? 'bg-[#d2f9d1]' : 'bg-[#f4f6f8]',
@@ -24,11 +31,8 @@ const wrapClass = computed(() => {
}) })
const text = computed(() => { const text = computed(() => {
if (props.text) { if (props.text)
if (!includeCode(props.text)) return marked(props.text)
return marked.parse(props.text)
return props.text
}
return '' return ''
}) })
</script> </script>
@@ -36,25 +40,16 @@ const text = computed(() => {
<template> <template>
<div :class="wrapClass"> <div :class="wrapClass">
<template v-if="loading"> <template v-if="loading">
<span class="w-[3px] h-[20px] block animate-blink" /> <span class="w-[5px] 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 :class="[{ 'markdown-body': !inversion }]" v-html="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;
}
}
.hljs {
background-color: #fff0 !important;
white-space: break-spaces;
}
</style> </style>

View File

@@ -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,21 +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" :text="text" :loading="loading" /> <TextComponent
<button :inversion="inversion"
v-if="!inversion && !loading" :error="error"
class="mb-2 ml-2 transition text-neutral-400 hover:text-neutral-800" :text="text"
@click="handleRegenerate" :loading="loading"
> />
<SvgIcon icon="ri:restart-line" /> <div class="flex flex-col">
</button> <button
v-if="!inversion"
class="mb-2 transition text-neutral-400 hover:text-neutral-800"
@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>

View 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;
}
}

View File

@@ -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()
@@ -195,6 +196,22 @@ async function onRegenerate(index: number) {
} }
} }
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
@@ -217,6 +234,13 @@ 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() === ''
}) })
@@ -266,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>

View File

@@ -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': {