From b6fd9ae766500d78e6dee1599a8a5c01ec37d893 Mon Sep 17 00:00:00 2001 From: Redon <790348264@qq.com> Date: Fri, 24 Feb 2023 15:03:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20v2.7.2=20=E6=B6=88=E6=81=AF=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E7=BE=8E=E5=8C=96=E5=92=8C=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=20(#111)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 优化代码 * feat: 美化消息,支持 markdown 全语法 * chore: version 2.7.2 --- CHANGELOG.md | 7 ++++ config/proxy.ts | 4 +- package.json | 3 +- pnpm-lock.yaml | 6 +++ service/src/chatgpt.ts | 31 +-------------- service/src/index.ts | 22 +---------- src/api/index.ts | 18 +-------- src/directives/highlight.ts | 23 ----------- src/directives/index.ts | 7 +--- src/main.ts | 3 -- src/plugins/assets.ts | 1 + src/views/chat/components/Message/Text.vue | 40 ++++++++------------ src/views/chat/components/Message/index.vue | 8 ++-- src/views/chat/components/Message/style.less | 22 +++++++++++ 14 files changed, 65 insertions(+), 130 deletions(-) delete mode 100644 src/directives/highlight.ts create mode 100644 src/views/chat/components/Message/style.less diff --git a/CHANGELOG.md b/CHANGELOG.md index 968d78d..abd2607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## v2.7.2 + +`2023-02-24` +### Enhancement +- 消息使用 [github-markdown-css](https://www.npmjs.com/package/github-markdown-css) 进行美化,现在支持全语法 +- 移除测试无用函数 + ## v2.7.1 `2023-02-23` diff --git a/config/proxy.ts b/config/proxy.ts index cfb1e08..d724238 100644 --- a/config/proxy.ts +++ b/config/proxy.ts @@ -6,9 +6,9 @@ export function createViteProxy(isOpenProxy: boolean, viteEnv: ImportMetaEnv) { const proxy: Record = { '/api': { - target: viteEnv.VITE_GLOB_API_URL, + target: viteEnv.VITE_APP_API_BASE_URL, changeOrigin: true, - rewrite: path => path.replace(/^\/api/, ''), + rewrite: path => path.replace('/api/', '/'), }, } diff --git a/package.json b/package.json index 8ca4710..653409f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "chatgpt-web", - "version": "2.7.1", + "version": "2.7.2", "private": false, "description": "ChatGPT Web", "author": "ChenZhaoYu ", @@ -24,6 +24,7 @@ }, "dependencies": { "@vueuse/core": "^9.13.0", + "github-markdown-css": "^5.2.0", "highlight.js": "^11.7.0", "marked": "^4.2.12", "naive-ui": "^2.34.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f9191da..752d1e7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,6 +15,7 @@ specifiers: axios: ^1.3.3 crypto-js: ^4.1.1 eslint: ^8.34.0 + github-markdown-css: ^5.2.0 highlight.js: ^11.7.0 husky: ^8.0.3 less: ^4.1.3 @@ -34,6 +35,7 @@ specifiers: dependencies: '@vueuse/core': 9.13.0_vue@3.2.47 + github-markdown-css: 5.2.0 highlight.js: 11.7.0 marked: 4.2.12 naive-ui: 2.34.3_vue@3.2.47 @@ -2524,6 +2526,10 @@ packages: through2: 4.0.2 dev: true + /github-markdown-css/5.2.0: + resolution: {integrity: sha512-hq5RaCInSUZ48bImOZpkppW2/MT44StRgsbsZ8YA4vJFwLKB/Vo3k7R2t+pUGqO+ThG0QDMi96TewV/B3vyItg==} + dev: false + /glob-parent/5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} diff --git a/service/src/chatgpt.ts b/service/src/chatgpt.ts index d2142c3..518e739 100644 --- a/service/src/chatgpt.ts +++ b/service/src/chatgpt.ts @@ -65,35 +65,6 @@ async function chatReply( } } -/** 实验性质的函数,用于处理聊天过程中的中间结果 */ -async function chatReplyProcess( - message: string, - lastContext?: { conversationId?: string; parentMessageId?: string }, - process?: (chat: ChatMessage) => void, -) { - if (!message) - return sendResponse({ type: 'Fail', message: 'Message is empty' }) - - try { - let options: SendMessageOptions = { timeoutMs } - - if (lastContext) - options = { ...lastContext } - - const response = await api.sendMessage(message, { - ...options, - onProgress: (partialResponse) => { - process?.(partialResponse) - }, - }) - - return sendResponse({ type: 'Success', data: response }) - } - catch (error: any) { - return sendResponse({ type: 'Fail', message: error.message }) - } -} - async function chatConfig() { return sendResponse({ type: 'Success', @@ -107,4 +78,4 @@ async function chatConfig() { export type { ChatContext, ChatMessage } -export { chatReply, chatReplyProcess, chatConfig } +export { chatReply, chatConfig } diff --git a/service/src/index.ts b/service/src/index.ts index b56ee58..01faf4a 100644 --- a/service/src/index.ts +++ b/service/src/index.ts @@ -1,6 +1,6 @@ import express from 'express' -import type { ChatContext, ChatMessage } from './chatgpt' -import { chatConfig, chatReply, chatReplyProcess } from './chatgpt' +import type { ChatContext } from './chatgpt' +import { chatConfig, chatReply } from './chatgpt' const app = express() const router = express.Router() @@ -26,24 +26,6 @@ router.post('/chat', async (req, res) => { } }) -/** 实验性质的函数,用于处理聊天过程中的中间结果 */ -router.post('/chat-process', async (req, res) => { - res.setHeader('Content-type', 'application/octet-stream') - - try { - const { prompt, options = {} } = req.body as { prompt: string; options?: ChatContext } - await chatReplyProcess(prompt, options, (chat: ChatMessage) => { - res.write(JSON.stringify(chat)) - }) - } - catch (error) { - res.write(JSON.stringify(error)) - } - finally { - res.end() - } -}) - router.post('/config', async (req, res) => { try { const response = await chatConfig() diff --git a/src/api/index.ts b/src/api/index.ts index 19189bf..1d3811f 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1,4 +1,4 @@ -import type { AxiosProgressEvent, GenericAbortSignal } from 'axios' +import type { GenericAbortSignal } from 'axios' import { post } from '@/utils/request' export function fetchChatAPI( @@ -13,22 +13,6 @@ export function fetchChatAPI( }) } -/** 实验性质的函数,用于处理聊天过程中的中间结果 */ -export function fetchChatAPIProcess( - params: { - prompt: string - options?: { conversationId?: string; parentMessageId?: string } - signal?: GenericAbortSignal - onDownloadProgress?: (progressEvent: AxiosProgressEvent) => void }, -) { - return post({ - url: '/chat-process', - data: { prompt: params.prompt, options: params.options }, - signal: params.signal, - onDownloadProgress: params.onDownloadProgress, - }) -} - export function fetchChatConfig() { return post({ url: '/config', diff --git a/src/directives/highlight.ts b/src/directives/highlight.ts deleted file mode 100644 index ead6acf..0000000 --- a/src/directives/highlight.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type { App, Directive } from 'vue' -import hljs from 'highlight.js' -import includeCode from '@/utils/functions/includeCode' - -hljs.configure({ ignoreUnescapedHTML: true }) - -function highlightCode(el: HTMLElement) { - if (includeCode(el.textContent)) - hljs.highlightBlock(el) -} - -export default function setupHighlightDirective(app: App) { - const highLightDirective: Directive = { - mounted(el: HTMLElement) { - highlightCode(el) - }, - updated(el: HTMLElement) { - highlightCode(el) - }, - } - - app.directive('highlight', highLightDirective) -} diff --git a/src/directives/index.ts b/src/directives/index.ts index cdcaeef..5cc7923 100644 --- a/src/directives/index.ts +++ b/src/directives/index.ts @@ -1,6 +1 @@ -import type { App } from 'vue' -import setupHighlightDirective from './highlight' - -export function setupDirectives(app: App) { - setupHighlightDirective(app) -} +export function setupDirectives() {} diff --git a/src/main.ts b/src/main.ts index 115198d..acbe522 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,6 +1,5 @@ import { createApp } from 'vue' import App from './App.vue' -import { setupDirectives } from './directives' import { setupAssets } from '@/plugins' import { setupStore } from '@/store' import { setupRouter } from '@/router' @@ -11,8 +10,6 @@ async function bootstrap() { setupStore(app) - setupDirectives(app) - await setupRouter(app) app.mount('#app') diff --git a/src/plugins/assets.ts b/src/plugins/assets.ts index 88ffebd..593dc6f 100644 --- a/src/plugins/assets.ts +++ b/src/plugins/assets.ts @@ -1,4 +1,5 @@ import 'highlight.js/styles/xcode.css' +import 'github-markdown-css/github-markdown.css' import '@/styles/global.css' /** Tailwind's Preflight Style Override */ diff --git a/src/views/chat/components/Message/Text.vue b/src/views/chat/components/Message/Text.vue index 23a2ed8..f070aaa 100644 --- a/src/views/chat/components/Message/Text.vue +++ b/src/views/chat/components/Message/Text.vue @@ -1,7 +1,16 @@ @@ -39,25 +43,13 @@ const text = computed(() => { diff --git a/src/views/chat/components/Message/index.vue b/src/views/chat/components/Message/index.vue index 8b365cc..ffeb142 100644 --- a/src/views/chat/components/Message/index.vue +++ b/src/views/chat/components/Message/index.vue @@ -1,6 +1,6 @@