forked from charmbracelet/mods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages_test.go
60 lines (54 loc) · 1.31 KB
/
messages_test.go
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
package main
import (
"testing"
"github.com/sashabaranov/go-openai"
"github.com/stretchr/testify/require"
)
func TestLastPrompt(t *testing.T) {
t.Run("no prompt", func(t *testing.T) {
require.Equal(t, "", lastPrompt(nil))
})
t.Run("single prompt", func(t *testing.T) {
require.Equal(t, "single", lastPrompt([]openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Content: "single",
},
}))
})
t.Run("multiple prompts", func(t *testing.T) {
require.Equal(t, "last", lastPrompt([]openai.ChatCompletionMessage{
{
Role: openai.ChatMessageRoleUser,
Content: "first",
},
{
Role: openai.ChatMessageRoleAssistant,
Content: "hallo",
},
{
Role: openai.ChatMessageRoleUser,
Content: "middle 1",
},
{
Role: openai.ChatMessageRoleUser,
Content: "middle 2",
},
{
Role: openai.ChatMessageRoleUser,
Content: "last",
},
}))
})
}
func TestFirstLine(t *testing.T) {
t.Run("single line", func(t *testing.T) {
require.Equal(t, "line", firstLine("line"))
})
t.Run("single line ending with \n", func(t *testing.T) {
require.Equal(t, "line", firstLine("line\n"))
})
t.Run("multiple lines", func(t *testing.T) {
require.Equal(t, "line", firstLine("line\nsomething else\nline3\nfoo\nends with a double \n\n"))
})
}