-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateRequestBuilder.go
161 lines (144 loc) · 4.4 KB
/
GenerateRequestBuilder.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
150
151
152
153
154
155
156
157
158
159
160
161
package ollama
// GenerateRequestBuilder represents the generate API request.
type GenerateRequestBuilder struct {
Model *string `json:"model"`
Prompt *string `json:"prompt"`
System *string `json:"system"`
Template *string `json:"template"`
Format *string `json:"format"`
Images []string `json:"images"`
Raw *bool `json:"raw"`
Context []int `json:"context,omitempty"`
KeepAlive *string `json:"keep_alive,omitempty"`
Options *Options `json:"options"`
Stream *bool `json:"stream"`
StreamBufferSize *int `json:"-"`
StreamFunc func(r *GenerateResponse, err error) `json:"-"`
}
// WithModel sets the model used for this request.
//
// Parameters:
// - v: The model name.
func (c GenerateFunc) WithModel(v string) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Model = &v
}
}
// WithPrompt sets the prompt for this request.
//
// Parameters:
// - v: The prompt string.
func (c GenerateFunc) WithPrompt(v string) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Prompt = &v
}
}
// WithSystem overrides the model's default system message/prompt.
//
// Parameters:
// - v: The system string.
func (c GenerateFunc) WithSystem(v string) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.System = &v
}
}
// WithTemplate overrides the model's default prompt template.
//
// Parameters:
// - v: The template string.
func (c GenerateFunc) WithTemplate(v string) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Template = &v
}
}
// WithContext overrides the model's default prompt template.
//
// Parameters:
// - v: The content int array.
func (c GenerateFunc) WithContext(v []int) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Context = v
}
}
// WithKeepAlive controls how long the model will stay loaded in memory following this request.
//
// Parameters:
// - v: The keep alive duration.
func (c GenerateFunc) WithKeepAlive(v string) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.KeepAlive = &v
}
}
// WithStream passes a function to allow reading stream types.
//
// Parameters:
// - v: A boolean indicating whether to use streaming.
// - bufferSize: The size of the streamed buffer
// - f: The function to handle streaming types.
func (c GenerateFunc) WithStream(v bool, bufferSize int, f func(r *GenerateResponse, err error)) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Stream = &v
r.StreamBufferSize = &bufferSize
r.StreamFunc = f
}
}
// WithFormat sets the format to return a response in. Currently, the only accepted value is "json".
//
// Parameters:
// - v: The format string.
func (c GenerateFunc) WithFormat(v string) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Format = &v
}
}
// WithImage appends an image to the message sent to Ollama. The image must be base64 encoded.
//
// Parameters:
// - v: The base64 encoded image string.
func (c GenerateFunc) WithImage(v string) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Images = append(r.Images, v)
}
}
// WithRaw bypasses the templating system and provides a full prompt.
//
// Parameters:
// - v: A boolean indicating whether to use raw mode.
func (c GenerateFunc) WithRaw(v bool) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Raw = &v
}
}
// WithTemperature sets the temperature for this request.
//
// Parameters:
// - v: The temperature value.
func (c GenerateFunc) WithTemperature(v float64) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
if r.Options == nil {
r.Options = &Options{}
}
r.Options.Temperature = &v
}
}
// WithSeed sets the seed for this request.
//
// Parameters:
// - v: The seed value.
func (c GenerateFunc) WithSeed(v int) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
if r.Options == nil {
r.Options = &Options{}
}
r.Options.Seed = &v
}
}
// WithOptions sets the options for this request. It will override any settings set before, such as temperature and seed.
//
// Parameters:
// - v: The options to set.
func (c GenerateFunc) WithOptions(v Options) func(*GenerateRequestBuilder) {
return func(r *GenerateRequestBuilder) {
r.Options = &v
}
}