Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/compaction/compaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func BuildPrompt(messages []chat.Message, additionalPrompt string) []chat.Messag
for i, msg := range messages {
cloned := msg
cloned.Cost = 0
cloned.CacheControl = false
out[i] = cloned
}
out = append(out, chat.Message{
Expand Down
20 changes: 20 additions & 0 deletions pkg/compaction/compaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@ func TestBuildPrompt(t *testing.T) {
assert.InDelta(t, 0.05, original[0].Cost, 1e-9)
assert.Len(t, original, 1)
})

t.Run("strips CacheControl from cloned messages", func(t *testing.T) {
t.Parallel()

input := []chat.Message{
{Role: chat.MessageRoleSystem, Content: "system", CacheControl: true},
{Role: chat.MessageRoleSystem, Content: "context", CacheControl: true},
{Role: chat.MessageRoleUser, Content: "hello"},
}

out := BuildPrompt(input, "")

// All cloned messages should have CacheControl=false
for i, msg := range out {
assert.False(t, msg.CacheControl, "message %d should have CacheControl stripped", i)
}
// Original should be unchanged
assert.True(t, input[0].CacheControl)
assert.True(t, input[1].CacheControl)
})
}

func TestPromptsAreEmbedded(t *testing.T) {
Expand Down
Loading