-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
119 lines (102 loc) · 2.4 KB
/
options.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
package chatglm
const (
RoleUser = "user"
RoleAssistant = "assistant"
RoleSystem = "system"
RoleObservation = "observation"
TypeFunction = "function"
TypeCode = "code"
DELIMITER = "<|delimiter|>"
)
type GenerationOptions struct {
MaxLength int
MaxContextLength int
DoSample bool
TopK int
TopP float32
Temperature float32
RepetitionPenalty float32
NumThreads int
StreamCallback func(string) bool
}
type ChatMessage struct {
Role string
Content string
ToolCalls []*ToolCallMessage
}
type ToolCallMessage struct {
Type string
Function *FunctionMessage
Code *CodeMessage
}
type FunctionMessage struct {
Name string
Arguments string
}
type CodeMessage struct {
Input string
}
type GenerationOption func(g *GenerationOptions)
var DefaultGenerationOptions GenerationOptions = GenerationOptions{
MaxLength: 2048,
MaxContextLength: 512,
DoSample: true,
TopK: 0,
TopP: 0.7,
Temperature: 0.95,
RepetitionPenalty: 1.0,
NumThreads: 0,
StreamCallback: nil,
}
func NewGenerationOptions(opts ...GenerationOption) *GenerationOptions {
p := DefaultGenerationOptions
for _, opt := range opts {
opt(&p)
}
return &p
}
func SetMaxLength(maxLength int) GenerationOption {
return func(g *GenerationOptions) {
g.MaxLength = maxLength
}
}
func SetMaxContextLength(maxContextLength int) GenerationOption {
return func(g *GenerationOptions) {
g.MaxContextLength = maxContextLength
}
}
func SetDoSample(doSample bool) GenerationOption {
return func(g *GenerationOptions) {
g.DoSample = doSample
}
}
func SetTopK(topK int) GenerationOption {
return func(g *GenerationOptions) {
g.TopK = topK
}
}
func SetTopP(topP float32) GenerationOption {
return func(g *GenerationOptions) {
g.TopP = topP
}
}
func SetTemperature(temperature float32) GenerationOption {
return func(g *GenerationOptions) {
g.Temperature = temperature
}
}
func SetRepetitionPenalty(repetitionPenalty float32) GenerationOption {
return func(g *GenerationOptions) {
g.RepetitionPenalty = repetitionPenalty
}
}
func SetNumThreads(numThreads int) GenerationOption {
return func(g *GenerationOptions) {
g.NumThreads = numThreads
}
}
func SetStreamCallback(callback func(string) bool) GenerationOption {
return func(g *GenerationOptions) {
g.StreamCallback = callback
}
}