-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmodels.go
More file actions
411 lines (359 loc) · 13 KB
/
Copy pathmodels.go
File metadata and controls
411 lines (359 loc) · 13 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
// Code generated by Fern. DO NOT EDIT.
package api
import (
json "encoding/json"
fmt "fmt"
internal "github.com/cohere-ai/cohere-go/v2/internal"
big "math/big"
)
var (
modelsListRequestFieldPageSize = big.NewInt(1 << 0)
modelsListRequestFieldPageToken = big.NewInt(1 << 1)
modelsListRequestFieldEndpoint = big.NewInt(1 << 2)
modelsListRequestFieldDefaultOnly = big.NewInt(1 << 3)
)
type ModelsListRequest struct {
// Maximum number of models to include in a page
// Defaults to `20`, min value of `1`, max value of `1000`.
PageSize *float64 `json:"-" url:"page_size,omitempty"`
// Page token provided in the `next_page_token` field of a previous response.
PageToken *string `json:"-" url:"page_token,omitempty"`
// When provided, filters the list of models to only those that are compatible with the specified endpoint.
Endpoint *CompatibleEndpoint `json:"-" url:"endpoint,omitempty"`
// When provided, filters the list of models to only the default model to the endpoint. This parameter is only valid when `endpoint` is provided.
DefaultOnly *bool `json:"-" url:"default_only,omitempty"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
}
func (m *ModelsListRequest) require(field *big.Int) {
if m.explicitFields == nil {
m.explicitFields = big.NewInt(0)
}
m.explicitFields.Or(m.explicitFields, field)
}
// SetPageSize sets the PageSize field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (m *ModelsListRequest) SetPageSize(pageSize *float64) {
m.PageSize = pageSize
m.require(modelsListRequestFieldPageSize)
}
// SetPageToken sets the PageToken field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (m *ModelsListRequest) SetPageToken(pageToken *string) {
m.PageToken = pageToken
m.require(modelsListRequestFieldPageToken)
}
// SetEndpoint sets the Endpoint field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (m *ModelsListRequest) SetEndpoint(endpoint *CompatibleEndpoint) {
m.Endpoint = endpoint
m.require(modelsListRequestFieldEndpoint)
}
// SetDefaultOnly sets the DefaultOnly field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (m *ModelsListRequest) SetDefaultOnly(defaultOnly *bool) {
m.DefaultOnly = defaultOnly
m.require(modelsListRequestFieldDefaultOnly)
}
// One of the Cohere API endpoints that the model can be used with.
type CompatibleEndpoint string
const (
CompatibleEndpointChat CompatibleEndpoint = "chat"
CompatibleEndpointEmbed CompatibleEndpoint = "embed"
CompatibleEndpointClassify CompatibleEndpoint = "classify"
CompatibleEndpointSummarize CompatibleEndpoint = "summarize"
CompatibleEndpointRerank CompatibleEndpoint = "rerank"
CompatibleEndpointRate CompatibleEndpoint = "rate"
CompatibleEndpointGenerate CompatibleEndpoint = "generate"
)
func NewCompatibleEndpointFromString(s string) (CompatibleEndpoint, error) {
switch s {
case "chat":
return CompatibleEndpointChat, nil
case "embed":
return CompatibleEndpointEmbed, nil
case "classify":
return CompatibleEndpointClassify, nil
case "summarize":
return CompatibleEndpointSummarize, nil
case "rerank":
return CompatibleEndpointRerank, nil
case "rate":
return CompatibleEndpointRate, nil
case "generate":
return CompatibleEndpointGenerate, nil
}
var t CompatibleEndpoint
return "", fmt.Errorf("%s is not a valid %T", s, t)
}
func (c CompatibleEndpoint) Ptr() *CompatibleEndpoint {
return &c
}
// Contains information about the model and which API endpoints it can be used with.
var (
getModelResponseFieldName = big.NewInt(1 << 0)
getModelResponseFieldIsDeprecated = big.NewInt(1 << 1)
getModelResponseFieldEndpoints = big.NewInt(1 << 2)
getModelResponseFieldFinetuned = big.NewInt(1 << 3)
getModelResponseFieldContextLength = big.NewInt(1 << 4)
getModelResponseFieldTokenizerUrl = big.NewInt(1 << 5)
getModelResponseFieldDefaultEndpoints = big.NewInt(1 << 6)
getModelResponseFieldFeatures = big.NewInt(1 << 7)
)
type GetModelResponse struct {
// Specify this name in the `model` parameter of API requests to use your chosen model.
Name *string `json:"name,omitempty" url:"name,omitempty"`
// Whether the model is deprecated or not.
IsDeprecated *bool `json:"is_deprecated,omitempty" url:"is_deprecated,omitempty"`
// The API endpoints that the model is compatible with.
Endpoints []CompatibleEndpoint `json:"endpoints,omitempty" url:"endpoints,omitempty"`
// Whether the model has been fine-tuned or not.
Finetuned *bool `json:"finetuned,omitempty" url:"finetuned,omitempty"`
// The maximum number of tokens that the model can process in a single request. Note that not all of these tokens are always available due to special tokens and preambles that Cohere has added by default.
ContextLength *float64 `json:"context_length,omitempty" url:"context_length,omitempty"`
// Public URL to the tokenizer's configuration file.
TokenizerUrl *string `json:"tokenizer_url,omitempty" url:"tokenizer_url,omitempty"`
// The API endpoints that the model is default to.
DefaultEndpoints []CompatibleEndpoint `json:"default_endpoints,omitempty" url:"default_endpoints,omitempty"`
// The features that the model supports.
Features []string `json:"features,omitempty" url:"features,omitempty"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (g *GetModelResponse) GetName() *string {
if g == nil {
return nil
}
return g.Name
}
func (g *GetModelResponse) GetIsDeprecated() *bool {
if g == nil {
return nil
}
return g.IsDeprecated
}
func (g *GetModelResponse) GetEndpoints() []CompatibleEndpoint {
if g == nil {
return nil
}
return g.Endpoints
}
func (g *GetModelResponse) GetFinetuned() *bool {
if g == nil {
return nil
}
return g.Finetuned
}
func (g *GetModelResponse) GetContextLength() *float64 {
if g == nil {
return nil
}
return g.ContextLength
}
func (g *GetModelResponse) GetTokenizerUrl() *string {
if g == nil {
return nil
}
return g.TokenizerUrl
}
func (g *GetModelResponse) GetDefaultEndpoints() []CompatibleEndpoint {
if g == nil {
return nil
}
return g.DefaultEndpoints
}
func (g *GetModelResponse) GetFeatures() []string {
if g == nil {
return nil
}
return g.Features
}
func (g *GetModelResponse) GetExtraProperties() map[string]interface{} {
if g == nil {
return nil
}
return g.extraProperties
}
func (g *GetModelResponse) require(field *big.Int) {
if g.explicitFields == nil {
g.explicitFields = big.NewInt(0)
}
g.explicitFields.Or(g.explicitFields, field)
}
// SetName sets the Name field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetName(name *string) {
g.Name = name
g.require(getModelResponseFieldName)
}
// SetIsDeprecated sets the IsDeprecated field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetIsDeprecated(isDeprecated *bool) {
g.IsDeprecated = isDeprecated
g.require(getModelResponseFieldIsDeprecated)
}
// SetEndpoints sets the Endpoints field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetEndpoints(endpoints []CompatibleEndpoint) {
g.Endpoints = endpoints
g.require(getModelResponseFieldEndpoints)
}
// SetFinetuned sets the Finetuned field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetFinetuned(finetuned *bool) {
g.Finetuned = finetuned
g.require(getModelResponseFieldFinetuned)
}
// SetContextLength sets the ContextLength field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetContextLength(contextLength *float64) {
g.ContextLength = contextLength
g.require(getModelResponseFieldContextLength)
}
// SetTokenizerUrl sets the TokenizerUrl field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetTokenizerUrl(tokenizerUrl *string) {
g.TokenizerUrl = tokenizerUrl
g.require(getModelResponseFieldTokenizerUrl)
}
// SetDefaultEndpoints sets the DefaultEndpoints field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetDefaultEndpoints(defaultEndpoints []CompatibleEndpoint) {
g.DefaultEndpoints = defaultEndpoints
g.require(getModelResponseFieldDefaultEndpoints)
}
// SetFeatures sets the Features field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (g *GetModelResponse) SetFeatures(features []string) {
g.Features = features
g.require(getModelResponseFieldFeatures)
}
func (g *GetModelResponse) UnmarshalJSON(data []byte) error {
type unmarshaler GetModelResponse
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*g = GetModelResponse(value)
extraProperties, err := internal.ExtractExtraProperties(data, *g)
if err != nil {
return err
}
g.extraProperties = extraProperties
g.rawJSON = json.RawMessage(data)
return nil
}
func (g *GetModelResponse) MarshalJSON() ([]byte, error) {
type embed GetModelResponse
var marshaler = struct {
embed
}{
embed: embed(*g),
}
explicitMarshaler := internal.HandleExplicitFields(marshaler, g.explicitFields)
return json.Marshal(explicitMarshaler)
}
func (g *GetModelResponse) String() string {
if g == nil {
return "<nil>"
}
if len(g.rawJSON) > 0 {
if value, err := internal.StringifyJSON(g.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(g); err == nil {
return value
}
return fmt.Sprintf("%#v", g)
}
var (
listModelsResponseFieldModels = big.NewInt(1 << 0)
listModelsResponseFieldNextPageToken = big.NewInt(1 << 1)
)
type ListModelsResponse struct {
Models []*GetModelResponse `json:"models" url:"models"`
// A token to retrieve the next page of results. Provide in the page_token parameter of the next request.
NextPageToken *string `json:"next_page_token,omitempty" url:"next_page_token,omitempty"`
// Private bitmask of fields set to an explicit value and therefore not to be omitted
explicitFields *big.Int `json:"-" url:"-"`
extraProperties map[string]interface{}
rawJSON json.RawMessage
}
func (l *ListModelsResponse) GetModels() []*GetModelResponse {
if l == nil {
return nil
}
return l.Models
}
func (l *ListModelsResponse) GetNextPageToken() *string {
if l == nil {
return nil
}
return l.NextPageToken
}
func (l *ListModelsResponse) GetExtraProperties() map[string]interface{} {
if l == nil {
return nil
}
return l.extraProperties
}
func (l *ListModelsResponse) require(field *big.Int) {
if l.explicitFields == nil {
l.explicitFields = big.NewInt(0)
}
l.explicitFields.Or(l.explicitFields, field)
}
// SetModels sets the Models field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListModelsResponse) SetModels(models []*GetModelResponse) {
l.Models = models
l.require(listModelsResponseFieldModels)
}
// SetNextPageToken sets the NextPageToken field and marks it as non-optional;
// this prevents an empty or null value for this field from being omitted during serialization.
func (l *ListModelsResponse) SetNextPageToken(nextPageToken *string) {
l.NextPageToken = nextPageToken
l.require(listModelsResponseFieldNextPageToken)
}
func (l *ListModelsResponse) UnmarshalJSON(data []byte) error {
type unmarshaler ListModelsResponse
var value unmarshaler
if err := json.Unmarshal(data, &value); err != nil {
return err
}
*l = ListModelsResponse(value)
extraProperties, err := internal.ExtractExtraProperties(data, *l)
if err != nil {
return err
}
l.extraProperties = extraProperties
l.rawJSON = json.RawMessage(data)
return nil
}
func (l *ListModelsResponse) MarshalJSON() ([]byte, error) {
type embed ListModelsResponse
var marshaler = struct {
embed
}{
embed: embed(*l),
}
explicitMarshaler := internal.HandleExplicitFields(marshaler, l.explicitFields)
return json.Marshal(explicitMarshaler)
}
func (l *ListModelsResponse) String() string {
if l == nil {
return "<nil>"
}
if len(l.rawJSON) > 0 {
if value, err := internal.StringifyJSON(l.rawJSON); err == nil {
return value
}
}
if value, err := internal.StringifyJSON(l); err == nil {
return value
}
return fmt.Sprintf("%#v", l)
}