chore: initial commit
This commit is contained in:
19
internal/memory/compress.go
Normal file
19
internal/memory/compress.go
Normal file
@@ -0,0 +1,19 @@
|
||||
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()
|
||||
}
|
||||
Reference in New Issue
Block a user