Skip to content

Commit 2fe4734

Browse files
committed
add memory time
1 parent 6a66a32 commit 2fe4734

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

conf/.env.sample

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ WX_HELP_REPLY=输入以下命令进行对话\n/help:查看帮助\n/gpt:与GP
1010

1111
# redis config
1212
KV_URL=redis://localhost:6479/0
13+
MSG_TIME=30 消息对话列表记忆时间(单位分钟)默认30分钟
1314

1415
# maxOutput config
1516
# 最大输出tokens, 可选项

db/db.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"os"
9+
"strconv"
910
"sync"
1011
"time"
1112

@@ -81,7 +82,13 @@ func (r *RedisChatDb) SetMsgList(botType string, userId string, msgList []Msg) {
8182
fmt.Println(err)
8283
return
8384
}
84-
r.client.Set(context.Background(), fmt.Sprintf("%v:%v:%v", MSG_KEY, botType, userId), res, time.Minute*30)
85+
msgTime := os.Getenv("MSG_TIME")
86+
//转换为数字
87+
msgT, err := strconv.Atoi(msgTime)
88+
if err != nil || msgT <= 0 {
89+
msgT = 30
90+
}
91+
r.client.Set(context.Background(), fmt.Sprintf("%v:%v:%v", MSG_KEY, botType, userId), res, time.Minute*time.Duration(msgT))
8592
}
8693

8794
func GetChatDb() (ChatDb, error) {

0 commit comments

Comments
 (0)