-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt_test.go
149 lines (117 loc) · 3.09 KB
/
prompt_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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Copyright (C) 2024 - 2025 Dmitry Kolesnikov
//
// This file may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details.
// https://github.com/kshard/chatter
//
package chatter
import (
"fmt"
"testing"
"github.com/fogfish/it/v2"
)
// func TestPromptWithRole(t *testing.T) {
// v := "assistant"
// p := &Prompt{}
// p.WithRole(v)
// txt, _ := p.MarshalText()
// it.Then(t).Should(
// it.Equal(p.Role, v),
// it.Equal(string(txt), v+"."),
// )
// }
func TestPromptWithTask(t *testing.T) {
v := "Translate the following text"
e := v + "."
p := &Prompt{}
p.WithTask(v)
it.Then(t).Should(
it.Equal(p.Task, e),
it.Equal(p.String(), e),
)
}
func TestPromptWithGuide(t *testing.T) {
v := "Use formal language"
e := v + "."
p := &Prompt{}
p.With(Guide("", v))
it.Then(t).Should(
it.Seq(p.Sections).Equal(Snippet{Type: TEXT, Note: "", Text: []string{e}}),
it.Equal(p.String(), e),
)
}
func TestPromptWithRules1(t *testing.T) {
v := "Ensure accuracy"
e := "1. " + v + "."
p := &Prompt{}
p.With(Rules("", v))
it.Then(t).Should(
it.Seq(p.Sections).Equal(Snippet{Type: RULES, Note: "", Text: []string{v + "."}}),
it.Equal(p.String(), e),
)
}
func TestPromptWithRules2(t *testing.T) {
v := "Ensure accuracy"
y := "Translate all text"
p := &Prompt{}
p.With(Rules(v, y, y))
it.Then(t).Should(
it.Seq(p.Sections).Equal(Snippet{Type: RULES, Note: v + ":", Text: []string{y + ".", y + "."}}),
it.Equal(p.String(), fmt.Sprintf("%s:\n1. %s.\n2. %s.", v, y, y)),
)
}
func TestPromptWithExample(t *testing.T) {
v := "Hello"
y := "Hola"
p := &Prompt{}
p.With(Example{Input: v, Reply: y})
it.Then(t).Should(
it.Seq(p.Sections).Equal(Example{Input: v, Reply: y}),
it.Equal(p.String(), fmt.Sprintf("Example Input: %s\nExpected Output: %s", v, y)),
)
}
func TestPromptWithInput(t *testing.T) {
a := "Translate the following"
h := "Hello"
w := "World"
p := &Prompt{}
p.With(Input(a, h, w))
it.Then(t).Should(
it.Seq(p.Sections).Equal(Snippet{Type: INPUT, Note: a + ":", Text: []string{h, w}}),
it.Equal(p.String(), fmt.Sprintf("%s:\n- %s.\n- %s.", a, h, w)),
)
}
func TestPromptWithAttach(t *testing.T) {
a := "Translate the following"
h := "Hello"
w := "World"
p := &Prompt{}
p.With(Blob(a, h, w))
it.Then(t).Should(
it.Seq(p.Sections).Equal(Snippet{Type: BLOB, Note: a + ":", Text: []string{h, w}}),
it.Equal(p.String(), fmt.Sprintf("%s:\n%s\n%s\n", a, h, w)),
)
}
func TestPromptWithContext(t *testing.T) {
a := "Context information"
h := "Hello"
w := "World"
p := &Prompt{}
p.With(Context(a, h, w))
it.Then(t).Should(
it.Seq(p.Sections).Equal(Snippet{Type: CONTEXT, Note: a + ":", Text: []string{h, w}}),
it.Equal(p.String(), fmt.Sprintf("%s:\n- %s.\n- %s.", a, h, w)),
)
}
func TestPromptWithFeedback(t *testing.T) {
a := "Context information"
h := "Hello"
w := "World"
p := &Prompt{}
p.With(Feedback(a, h, w))
it.Then(t).Should(
it.Seq(p.Sections).Equal(Snippet{Type: FEEDBACK, Note: a + ":", Text: []string{h + ".", w + "."}}),
it.Equal(p.String(), fmt.Sprintf("%s:\n- %s.\n- %s.", a, h, w)),
)
}