From c008f33bc315182ac6da7ba87ba22443f12f39a1 Mon Sep 17 00:00:00 2001 From: RockYang Date: Fri, 16 Jun 2023 23:30:04 +0800 Subject: [PATCH] fix: fixed bu for 'slice bounds out of range' --- api/go/handler/chat_handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/go/handler/chat_handler.go b/api/go/handler/chat_handler.go index cac3239..2c5920e 100644 --- a/api/go/handler/chat_handler.go +++ b/api/go/handler/chat_handler.go @@ -350,7 +350,9 @@ func (h *ChatHandler) sendMessage(ctx context.Context, session types.ChatSession replyMessage(ws, "当前会话上下文长度超出限制,已为您删减会话上下文!") // 只保留最近的三条记录 chatContext := h.app.ChatContexts.Get(session.ChatId) - chatContext = chatContext[len(chatContext)-3:] + if len(chatContext) > 3 { + chatContext = chatContext[len(chatContext)-3:] + } h.app.ChatContexts.Put(session.ChatId, chatContext) return h.sendMessage(ctx, session, role, prompt, ws) } else {