Files
LaodingBot/internal/memory/compress.go

20 lines
364 B
Go
Raw Permalink Normal View History

2026-02-21 23:01:39 +08:00
package memory
import "strings"
func CompressForPrompt(messages []Message, maxChars int) string {
if maxChars <= 0 {
maxChars = 8000
}
builder := strings.Builder{}
for _, msg := range messages {
line := msg.Role + ": " + msg.Content + "\n"
if builder.Len()+len(line) > maxChars {
break
}
builder.WriteString(line)
}
return builder.String()
}