forked from zendev-sh/goai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaching_test.go
More file actions
87 lines (74 loc) · 2.24 KB
/
caching_test.go
File metadata and controls
87 lines (74 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package goai
import (
"testing"
"github.com/zendev-sh/goai/provider"
)
func TestApplyCaching_SystemMessages(t *testing.T) {
msgs := []provider.Message{
{
Role: provider.RoleSystem,
Content: []provider.Part{
{Type: provider.PartText, Text: "You are helpful."},
{Type: provider.PartText, Text: "Be concise."},
},
},
{
Role: provider.RoleUser,
Content: []provider.Part{{Type: provider.PartText, Text: "Hello"}},
},
}
result := applyCaching(msgs)
// First system part should not be marked.
if result[0].Content[0].CacheControl != "" {
t.Errorf("first part CacheControl = %q, want empty", result[0].Content[0].CacheControl)
}
// Last system part should be marked.
if result[0].Content[1].CacheControl != "ephemeral" {
t.Errorf("last part CacheControl = %q, want ephemeral", result[0].Content[1].CacheControl)
}
// User message should not be marked.
if result[1].Content[0].CacheControl != "" {
t.Errorf("user CacheControl = %q, want empty", result[1].Content[0].CacheControl)
}
}
func TestApplyCaching_NoSystemMessages(t *testing.T) {
msgs := []provider.Message{
{
Role: provider.RoleUser,
Content: []provider.Part{{Type: provider.PartText, Text: "Hello"}},
},
}
result := applyCaching(msgs)
if result[0].Content[0].CacheControl != "" {
t.Errorf("CacheControl = %q, want empty", result[0].Content[0].CacheControl)
}
}
func TestApplyCaching_EmptyContent(t *testing.T) {
msgs := []provider.Message{
{Role: provider.RoleSystem, Content: nil},
}
// Should not panic.
result := applyCaching(msgs)
if len(result[0].Content) != 0 {
t.Error("expected empty content")
}
}
func TestApplyCaching_MultipleSystemMessages(t *testing.T) {
msgs := []provider.Message{
{
Role: provider.RoleSystem,
Content: []provider.Part{{Type: provider.PartText, Text: "First system"}},
},
{
Role: provider.RoleSystem,
Content: []provider.Part{{Type: provider.PartText, Text: "Second system"}},
},
}
result := applyCaching(msgs)
if result[0].Content[0].CacheControl != "ephemeral" {
t.Errorf("first system CacheControl = %q", result[0].Content[0].CacheControl)
}
if result[1].Content[0].CacheControl != "ephemeral" {
t.Errorf("second system CacheControl = %q", result[1].Content[0].CacheControl)
}
}