20 lines
364 B
Go
20 lines
364 B
Go
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()
|
|
}
|