-
Notifications
You must be signed in to change notification settings - Fork 2
/
chat_completions_builder_test.go
77 lines (67 loc) · 2.08 KB
/
chat_completions_builder_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
package moonshot_test
import (
"testing"
"github.com/northes/go-moonshot"
"github.com/stretchr/testify/require"
)
func TestNewChatCompletionsBuilder(t *testing.T) {
tt := require.New(t)
builder := moonshot.NewChatCompletionsBuilder()
tt.NotNil(builder)
const (
promptContent = "你是 Kimi,由 Moonshot AI 提供的人工智能助手,你更擅长中文和英文的对话。你会为用户提供安全,有帮助,准确的回答。同时,你会拒绝一切涉及恐怖主义,种族歧视,黄色暴力等问题的回答。Moonshot AI 为专有名词,不可翻译成其他语言。"
userContent = "你好,我叫李雷,1+1等于多少?"
assistantContent = "我是小助手!"
)
wantedReq := &moonshot.ChatCompletionsRequest{
Messages: []*moonshot.ChatCompletionsMessage{
{
Role: moonshot.RoleSystem,
Content: promptContent,
},
{
Role: moonshot.RoleUser,
Content: userContent,
},
{
Role: moonshot.RoleAssistant,
Content: assistantContent,
},
{
Role: moonshot.RoleUser,
Content: userContent,
},
},
Model: moonshot.ModelMoonshotV132K,
MaxTokens: 1024,
Temperature: 0.3,
TopP: 1.0,
N: 1,
PresencePenalty: 1.2,
FrequencyPenalty: 1.5,
Stop: []string{"结束"},
Stream: true,
}
builder.AddPrompt(promptContent).
AddUserContent(userContent).
AddAssistantContent(assistantContent).
AddMessage(&moonshot.ChatCompletionsMessage{
Role: moonshot.RoleUser,
Content: userContent,
}).
SetModel(moonshot.ModelMoonshotV132K).
SetMaxTokens(1024).
SetTemperature(0.3).
SetTopP(1.0).
SetN(1).
SetPresencePenalty(1.2).
SetFrequencyPenalty(1.5).
SetStop([]string{"结束"}).
SetStream(true)
tt.Equal(wantedReq, builder.ToRequest())
tt.NotEqual(wantedReq, builder.SetModel(moonshot.ModelMoonshotV1128K).ToRequest())
builder2 := moonshot.NewChatCompletionsBuilder(*wantedReq)
tt.Equal(wantedReq, builder2.ToRequest())
builder2.SetPresencePenalty(2)
tt.NotEqual(wantedReq, builder2.ToRequest())
}