Skip to content

Commit

Permalink
fix: 修复会话满了之后清理
Browse files Browse the repository at this point in the history
  • Loading branch information
yqchilde committed Mar 13, 2023
1 parent 79b1f4a commit 08af9bd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions plugins/chatgpt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func init() {
ctx.ReplyTextAndAt("请发送菜单查看我还有哪些功能,无需@我哦")
return
case strings.TrimSpace(msg) == "清空会话":
chatRoomCtx.Store(chatRoom.chatId, chatRoom)
chatRoomCtx.LoadAndDelete(chatRoom.chatId)
ctx.ReplyTextAndAt("已清空和您的上下文会话")
return
case strings.HasPrefix(msg, "提问"):
Expand Down Expand Up @@ -142,7 +142,7 @@ func init() {
if c, ok := chatRoomCtx.Load(chatRoom.chatId); ok {
// 判断距离上次聊天是否超过10分钟了
if now.Sub(c.(ChatRoom).chatTime) > 10*time.Minute {
chatRoomCtx.Store(chatRoom.chatId, chatRoom)
chatRoomCtx.LoadAndDelete(chatRoom.chatId)
chatRoom.content = []openai.ChatCompletionMessage{{Role: "user", Content: msg}}
} else {
chatRoom.content = append(c.(ChatRoom).content, openai.ChatCompletionMessage{Role: "user", Content: msg})
Expand All @@ -158,7 +158,7 @@ func init() {
ctx.ReplyTextAndAt(err.Error())
case errors.Is(err, ErrMaxTokens):
ctx.ReplyTextAndAt("和你的聊天上下文内容太多啦,我的记忆好像在消退.. 糟糕,我忘记了..,请重新问我吧")
chatRoomCtx.Store(chatRoom.chatId, chatRoom)
chatRoomCtx.LoadAndDelete(chatRoom.chatId)
default:
ctx.ReplyTextAndAt("ChatGPT出错了,Err:" + err.Error())
}
Expand Down

0 comments on commit 08af9bd

Please sign in to comment.