From eea57790de7fa9690ecce58c47f9ec7bdc3d8488 Mon Sep 17 00:00:00 2001 From: RockYang Date: Wed, 28 May 2025 21:32:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=87=8D=E6=96=B0=E7=94=9F?= =?UTF-8?q?=E6=88=90=E7=9A=84=E9=80=BB=E8=BE=91=EF=BC=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E7=94=9F=E6=88=90=E4=B9=8B=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E8=81=8A=E5=A4=A9=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/handler/chat_handler.go | 6 ++++-- web/src/views/admin/ChatModel.vue | 16 +++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/api/handler/chat_handler.go b/api/handler/chat_handler.go index bdcbb99c..70569cff 100644 --- a/api/handler/chat_handler.go +++ b/api/handler/chat_handler.go @@ -220,8 +220,8 @@ func (h *ChatHandler) sendMessage(ctx context.Context, input ChatInput, c *gin.C } // 加载聊天上下文 - chatCtx := make([]interface{}, 0) - messages := make([]interface{}, 0) + chatCtx := make([]any, 0) + messages := make([]any, 0) if h.App.SysConfig.EnableContext { if h.ChatContexts.Has(input.ChatId) { messages = h.ChatContexts.Get(input.ChatId) @@ -232,6 +232,8 @@ func (h *ChatHandler) sendMessage(ctx context.Context, input ChatInput, c *gin.C dbSession := h.DB.Session(&gorm.Session{}).Where("chat_id", input.ChatId) if input.LastMsgId > 0 { // 重新生成逻辑 dbSession = dbSession.Where("id < ?", input.LastMsgId) + // 删除对应的聊天记录 + h.DB.Where("chat_id", input.ChatId).Where("id >= ?", input.LastMsgId).Delete(&model.ChatMessage{}) } err = dbSession.Limit(h.App.SysConfig.ContextDeep).Order("id DESC").Find(&historyMessages).Error if err == nil { diff --git a/web/src/views/admin/ChatModel.vue b/web/src/views/admin/ChatModel.vue index 0e9e91ad..5157fbca 100644 --- a/web/src/views/admin/ChatModel.vue +++ b/web/src/views/admin/ChatModel.vue @@ -265,16 +265,18 @@ const fetchData = () => { httpGet('/api/admin/model/list', query.value) .then((res) => { if (res.data) { - // 初始化数据 - const arr = res.data - for (let i = 0; i < arr.length; i++) { - arr[i].last_used_at = dateFormat(arr[i].last_used_at) - } - items.value = arr + res.data.forEach((item) => { + if (!item.options) { + item.options = {} + } + item.last_used_at = dateFormat(item.last_used_at) + }) + items.value = res.data } loading.value = false }) - .catch(() => { + .catch((e) => { + console.error(e) ElMessage.error('获取数据失败') }) }