refactor: extend user message history retention and increase maximum history size for improved context management in headmasterHandler

This commit is contained in:
lixiangwuxian 2025-01-10 02:24:10 +08:00
parent cd1e7cbe1c
commit d4d371fbbc

View File

@ -87,7 +87,7 @@ func enterFormatter(msgIn string) string {
}
func GenRequestFromUsr(from string, question string) []openai.ChatCompletionMessage {
if _, ok := histories[from]; !ok || histories_time[from].Add(2*time.Minute).Before(time.Now()) {
if _, ok := histories[from]; !ok || histories_time[from].Add(10*time.Minute).Before(time.Now()) {
histories[from] = make([]openai.ChatCompletionMessage, 0)
histories[from] = append(histories[from], openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleSystem,
@ -108,7 +108,7 @@ func AppendReplyToHistory(from string, reply string) {
Content: reply,
})
histories_time[from] = time.Now()
for len(histories[from]) > 10 {
for len(histories[from]) > 20 {
histories[from] = histories[from][1:]
histories[from][0] = openai.ChatCompletionMessage{
Role: openai.ChatMessageRoleSystem,