From 03d33c784c43cda2192598c3e42f865e59fcde0c Mon Sep 17 00:00:00 2001 From: RockYang Date: Thu, 20 Feb 2025 11:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=AC=E5=BC=8F=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E7=9A=84=20Bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/handler/chat_handler.go | 3 +- api/handler/chat_openai_handler.go | 7 ---- web/package-lock.json | 25 +++++++++++ web/package.json | 2 +- web/src/components/ChatPrompt.vue | 66 +++++++++++++++--------------- web/src/components/ChatReply.vue | 5 +++ web/src/utils/libs.js | 4 ++ web/src/views/ChatPlus.vue | 1 - 8 files changed, 69 insertions(+), 44 deletions(-) diff --git a/api/handler/chat_handler.go b/api/handler/chat_handler.go index 79530b69..89eaf001 100644 --- a/api/handler/chat_handler.go +++ b/api/handler/chat_handler.go @@ -90,7 +90,7 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio } // 检查 prompt 长度是否超过了当前模型允许的最大上下文长度 - promptTokens, err := utils.CalcTokens(prompt, session.Model.Value) + promptTokens, _ := utils.CalcTokens(prompt, session.Model.Value) if promptTokens > session.Model.MaxContext { return errors.New("对话内容超出了当前模型允许的最大上下文长度!") @@ -105,7 +105,6 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session *types.ChatSessio if strings.HasPrefix(session.Model.Value, "o1-") || strings.HasPrefix(session.Model.Value, "o3-") || strings.HasPrefix(session.Model.Value, "gpt") { - utils.SendChunkMsg(ws, "> AI 正在思考...\n") req.MaxCompletionTokens = session.Model.MaxTokens session.Start = time.Now().Unix() } else { diff --git a/api/handler/chat_openai_handler.go b/api/handler/chat_openai_handler.go index df4a8637..f7ac6e2a 100644 --- a/api/handler/chat_openai_handler.go +++ b/api/handler/chat_openai_handler.go @@ -90,13 +90,6 @@ func (h *ChatHandler) sendOpenAiMessage( var toolCall = false var arguments = make([]string, 0) - if strings.HasPrefix(req.Model, "o1-") { - content := fmt.Sprintf("AI 思考结束,耗时:%d 秒。\n\n", time.Now().Unix()-session.Start) - contents = append(contents, "> AI 正在思考中...\n") - contents = append(contents, content) - utils.SendChunkMsg(ws, content) - } - scanner := bufio.NewScanner(response.Body) for scanner.Scan() { line := scanner.Text() diff --git a/web/package-lock.json b/web/package-lock.json index 19caefee..f06bb156 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -23,6 +23,7 @@ "lodash": "^4.17.21", "markdown-it": "^13.0.1", "markdown-it-emoji": "^2.0.0", + "markdown-it-katex": "^2.0.3", "markdown-it-mathjax3": "^4.3.2", "markmap-common": "^0.16.0", "markmap-lib": "^0.16.1", @@ -8654,6 +8655,25 @@ "resolved": "https://registry.npmmirror.com/markdown-it-emoji/-/markdown-it-emoji-2.0.2.tgz", "integrity": "sha512-zLftSaNrKuYl0kR5zm4gxXjHaOI3FAOEaloKmRA5hijmJZvSjmxcokOLlzycb/HXlUFWzXqpIEoyEMCE4i9MvQ==" }, + "node_modules/markdown-it-katex": { + "version": "2.0.3", + "resolved": "https://registry.npmmirror.com/markdown-it-katex/-/markdown-it-katex-2.0.3.tgz", + "integrity": "sha512-nUkkMtRWeg7OpdflamflE/Ho/pWl64Lk9wNBKOmaj33XkQdumhXAIYhI0WO03GeiycPCsxbmX536V5NEXpC3Ng==", + "dependencies": { + "katex": "^0.6.0" + } + }, + "node_modules/markdown-it-katex/node_modules/katex": { + "version": "0.6.0", + "resolved": "https://registry.npmmirror.com/katex/-/katex-0.6.0.tgz", + "integrity": "sha512-rS4mY3SvHYg5LtQV6RBcK0if7ur6plyEukAOV+jGGPqFImuzu8fHL6M752iBmRGoUyF0bhZbAPoezehn7xYksA==", + "dependencies": { + "match-at": "^0.1.0" + }, + "bin": { + "katex": "cli.js" + } + }, "node_modules/markdown-it-mathjax3": { "version": "4.3.2", "resolved": "https://registry.npmjs.org/markdown-it-mathjax3/-/markdown-it-mathjax3-4.3.2.tgz", @@ -8895,6 +8915,11 @@ "markmap-common": "*" } }, + "node_modules/match-at": { + "version": "0.1.1", + "resolved": "https://registry.npmmirror.com/match-at/-/match-at-0.1.1.tgz", + "integrity": "sha512-h4Yd392z9mST+dzc+yjuybOGFNOZjmXIPKWjxBd1Bb23r4SmDOsk2NYCU2BMUBGbSpZqwVsZYNq26QS3xfaT3Q==" + }, "node_modules/mathjax-full": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/mathjax-full/-/mathjax-full-3.2.2.tgz", diff --git a/web/package.json b/web/package.json index e2d405cd..2a099a60 100644 --- a/web/package.json +++ b/web/package.json @@ -22,7 +22,7 @@ "json-bigint": "^1.0.0", "lodash": "^4.17.21", "markdown-it": "^13.0.1", - "markdown-it-emoji": "^2.0.0", + "markdown-it-emoji": "^2.0.0", "markdown-it-mathjax3": "^4.3.2", "markmap-common": "^0.16.0", "markmap-lib": "^0.16.1", diff --git a/web/src/components/ChatPrompt.vue b/web/src/components/ChatPrompt.vue index d9517cca..798051bd 100644 --- a/web/src/components/ChatPrompt.vue +++ b/web/src/components/ChatPrompt.vue @@ -2,25 +2,22 @@
- User + User
- +
- +
- {{ - file.name - }} - + {{ file.name }}
{{ GetFileType(file.ext) }} @@ -33,7 +30,7 @@
{{ dateFormat(data.created_at) }} {{ dateFormat(data.created_at) }} tokens: {{ finalTokens }}
@@ -44,25 +41,22 @@
- User + User
- +
- +
- {{ - file.name - }} - + {{ file.name }}
{{ GetFileType(file.ext) }} @@ -77,7 +71,7 @@
{{ dateFormat(data.created_at) }} {{ dateFormat(data.created_at) }}
@@ -87,12 +81,12 @@