-
Notifications
You must be signed in to change notification settings - Fork 12
/
beta.go
552 lines (456 loc) · 14.6 KB
/
beta.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
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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package anthropic
import (
"reflect"
"github.com/anthropics/anthropic-sdk-go/internal/apijson"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/tidwall/gjson"
)
// BetaService contains methods and other services that help with interacting with
// the anthropic API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewBetaService] method instead.
type BetaService struct {
Options []option.RequestOption
Models *BetaModelService
Messages *BetaMessageService
}
// NewBetaService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewBetaService(opts ...option.RequestOption) (r *BetaService) {
r = &BetaService{}
r.Options = opts
r.Models = NewBetaModelService(opts...)
r.Messages = NewBetaMessageService(opts...)
return
}
type AnthropicBeta = string
const (
AnthropicBetaMessageBatches2024_09_24 AnthropicBeta = "message-batches-2024-09-24"
AnthropicBetaPromptCaching2024_07_31 AnthropicBeta = "prompt-caching-2024-07-31"
AnthropicBetaComputerUse2024_10_22 AnthropicBeta = "computer-use-2024-10-22"
AnthropicBetaPDFs2024_09_25 AnthropicBeta = "pdfs-2024-09-25"
AnthropicBetaTokenCounting2024_11_01 AnthropicBeta = "token-counting-2024-11-01"
)
type BetaAPIError struct {
Message string `json:"message,required"`
Type BetaAPIErrorType `json:"type,required"`
JSON betaAPIErrorJSON `json:"-"`
}
// betaAPIErrorJSON contains the JSON metadata for the struct [BetaAPIError]
type betaAPIErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaAPIError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaAPIErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaAPIError) implementsBetaError() {}
type BetaAPIErrorType string
const (
BetaAPIErrorTypeAPIError BetaAPIErrorType = "api_error"
)
func (r BetaAPIErrorType) IsKnown() bool {
switch r {
case BetaAPIErrorTypeAPIError:
return true
}
return false
}
type BetaAuthenticationError struct {
Message string `json:"message,required"`
Type BetaAuthenticationErrorType `json:"type,required"`
JSON betaAuthenticationErrorJSON `json:"-"`
}
// betaAuthenticationErrorJSON contains the JSON metadata for the struct
// [BetaAuthenticationError]
type betaAuthenticationErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaAuthenticationError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaAuthenticationErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaAuthenticationError) implementsBetaError() {}
type BetaAuthenticationErrorType string
const (
BetaAuthenticationErrorTypeAuthenticationError BetaAuthenticationErrorType = "authentication_error"
)
func (r BetaAuthenticationErrorType) IsKnown() bool {
switch r {
case BetaAuthenticationErrorTypeAuthenticationError:
return true
}
return false
}
type BetaBillingError struct {
Message string `json:"message,required"`
Type BetaBillingErrorType `json:"type,required"`
JSON betaBillingErrorJSON `json:"-"`
}
// betaBillingErrorJSON contains the JSON metadata for the struct
// [BetaBillingError]
type betaBillingErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaBillingError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaBillingErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaBillingError) implementsBetaError() {}
type BetaBillingErrorType string
const (
BetaBillingErrorTypeBillingError BetaBillingErrorType = "billing_error"
)
func (r BetaBillingErrorType) IsKnown() bool {
switch r {
case BetaBillingErrorTypeBillingError:
return true
}
return false
}
type BetaError struct {
Message string `json:"message,required"`
Type BetaErrorType `json:"type,required"`
JSON betaErrorJSON `json:"-"`
union BetaErrorUnion
}
// betaErrorJSON contains the JSON metadata for the struct [BetaError]
type betaErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r betaErrorJSON) RawJSON() string {
return r.raw
}
func (r *BetaError) UnmarshalJSON(data []byte) (err error) {
*r = BetaError{}
err = apijson.UnmarshalRoot(data, &r.union)
if err != nil {
return err
}
return apijson.Port(r.union, &r)
}
// AsUnion returns a [BetaErrorUnion] interface which you can cast to the specific
// types for more type safety.
//
// Possible runtime types of the union are [BetaInvalidRequestError],
// [BetaAuthenticationError], [BetaBillingError], [BetaPermissionError],
// [BetaNotFoundError], [BetaRateLimitError], [BetaGatewayTimeoutError],
// [BetaAPIError], [BetaOverloadedError].
func (r BetaError) AsUnion() BetaErrorUnion {
return r.union
}
// Union satisfied by [BetaInvalidRequestError], [BetaAuthenticationError],
// [BetaBillingError], [BetaPermissionError], [BetaNotFoundError],
// [BetaRateLimitError], [BetaGatewayTimeoutError], [BetaAPIError] or
// [BetaOverloadedError].
type BetaErrorUnion interface {
implementsBetaError()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*BetaErrorUnion)(nil)).Elem(),
"type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaInvalidRequestError{}),
DiscriminatorValue: "invalid_request_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaAuthenticationError{}),
DiscriminatorValue: "authentication_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaBillingError{}),
DiscriminatorValue: "billing_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaPermissionError{}),
DiscriminatorValue: "permission_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaNotFoundError{}),
DiscriminatorValue: "not_found_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaRateLimitError{}),
DiscriminatorValue: "rate_limit_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaGatewayTimeoutError{}),
DiscriminatorValue: "timeout_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaAPIError{}),
DiscriminatorValue: "api_error",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaOverloadedError{}),
DiscriminatorValue: "overloaded_error",
},
)
}
type BetaErrorType string
const (
BetaErrorTypeInvalidRequestError BetaErrorType = "invalid_request_error"
BetaErrorTypeAuthenticationError BetaErrorType = "authentication_error"
BetaErrorTypeBillingError BetaErrorType = "billing_error"
BetaErrorTypePermissionError BetaErrorType = "permission_error"
BetaErrorTypeNotFoundError BetaErrorType = "not_found_error"
BetaErrorTypeRateLimitError BetaErrorType = "rate_limit_error"
BetaErrorTypeTimeoutError BetaErrorType = "timeout_error"
BetaErrorTypeAPIError BetaErrorType = "api_error"
BetaErrorTypeOverloadedError BetaErrorType = "overloaded_error"
)
func (r BetaErrorType) IsKnown() bool {
switch r {
case BetaErrorTypeInvalidRequestError, BetaErrorTypeAuthenticationError, BetaErrorTypeBillingError, BetaErrorTypePermissionError, BetaErrorTypeNotFoundError, BetaErrorTypeRateLimitError, BetaErrorTypeTimeoutError, BetaErrorTypeAPIError, BetaErrorTypeOverloadedError:
return true
}
return false
}
type BetaErrorResponse struct {
Error BetaError `json:"error,required"`
Type BetaErrorResponseType `json:"type,required"`
JSON betaErrorResponseJSON `json:"-"`
}
// betaErrorResponseJSON contains the JSON metadata for the struct
// [BetaErrorResponse]
type betaErrorResponseJSON struct {
Error apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaErrorResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaErrorResponseJSON) RawJSON() string {
return r.raw
}
type BetaErrorResponseType string
const (
BetaErrorResponseTypeError BetaErrorResponseType = "error"
)
func (r BetaErrorResponseType) IsKnown() bool {
switch r {
case BetaErrorResponseTypeError:
return true
}
return false
}
type BetaGatewayTimeoutError struct {
Message string `json:"message,required"`
Type BetaGatewayTimeoutErrorType `json:"type,required"`
JSON betaGatewayTimeoutErrorJSON `json:"-"`
}
// betaGatewayTimeoutErrorJSON contains the JSON metadata for the struct
// [BetaGatewayTimeoutError]
type betaGatewayTimeoutErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaGatewayTimeoutError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaGatewayTimeoutErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaGatewayTimeoutError) implementsBetaError() {}
type BetaGatewayTimeoutErrorType string
const (
BetaGatewayTimeoutErrorTypeTimeoutError BetaGatewayTimeoutErrorType = "timeout_error"
)
func (r BetaGatewayTimeoutErrorType) IsKnown() bool {
switch r {
case BetaGatewayTimeoutErrorTypeTimeoutError:
return true
}
return false
}
type BetaInvalidRequestError struct {
Message string `json:"message,required"`
Type BetaInvalidRequestErrorType `json:"type,required"`
JSON betaInvalidRequestErrorJSON `json:"-"`
}
// betaInvalidRequestErrorJSON contains the JSON metadata for the struct
// [BetaInvalidRequestError]
type betaInvalidRequestErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaInvalidRequestError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaInvalidRequestErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaInvalidRequestError) implementsBetaError() {}
type BetaInvalidRequestErrorType string
const (
BetaInvalidRequestErrorTypeInvalidRequestError BetaInvalidRequestErrorType = "invalid_request_error"
)
func (r BetaInvalidRequestErrorType) IsKnown() bool {
switch r {
case BetaInvalidRequestErrorTypeInvalidRequestError:
return true
}
return false
}
type BetaNotFoundError struct {
Message string `json:"message,required"`
Type BetaNotFoundErrorType `json:"type,required"`
JSON betaNotFoundErrorJSON `json:"-"`
}
// betaNotFoundErrorJSON contains the JSON metadata for the struct
// [BetaNotFoundError]
type betaNotFoundErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaNotFoundError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaNotFoundErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaNotFoundError) implementsBetaError() {}
type BetaNotFoundErrorType string
const (
BetaNotFoundErrorTypeNotFoundError BetaNotFoundErrorType = "not_found_error"
)
func (r BetaNotFoundErrorType) IsKnown() bool {
switch r {
case BetaNotFoundErrorTypeNotFoundError:
return true
}
return false
}
type BetaOverloadedError struct {
Message string `json:"message,required"`
Type BetaOverloadedErrorType `json:"type,required"`
JSON betaOverloadedErrorJSON `json:"-"`
}
// betaOverloadedErrorJSON contains the JSON metadata for the struct
// [BetaOverloadedError]
type betaOverloadedErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaOverloadedError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaOverloadedErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaOverloadedError) implementsBetaError() {}
type BetaOverloadedErrorType string
const (
BetaOverloadedErrorTypeOverloadedError BetaOverloadedErrorType = "overloaded_error"
)
func (r BetaOverloadedErrorType) IsKnown() bool {
switch r {
case BetaOverloadedErrorTypeOverloadedError:
return true
}
return false
}
type BetaPermissionError struct {
Message string `json:"message,required"`
Type BetaPermissionErrorType `json:"type,required"`
JSON betaPermissionErrorJSON `json:"-"`
}
// betaPermissionErrorJSON contains the JSON metadata for the struct
// [BetaPermissionError]
type betaPermissionErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaPermissionError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaPermissionErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaPermissionError) implementsBetaError() {}
type BetaPermissionErrorType string
const (
BetaPermissionErrorTypePermissionError BetaPermissionErrorType = "permission_error"
)
func (r BetaPermissionErrorType) IsKnown() bool {
switch r {
case BetaPermissionErrorTypePermissionError:
return true
}
return false
}
type BetaRateLimitError struct {
Message string `json:"message,required"`
Type BetaRateLimitErrorType `json:"type,required"`
JSON betaRateLimitErrorJSON `json:"-"`
}
// betaRateLimitErrorJSON contains the JSON metadata for the struct
// [BetaRateLimitError]
type betaRateLimitErrorJSON struct {
Message apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *BetaRateLimitError) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r betaRateLimitErrorJSON) RawJSON() string {
return r.raw
}
func (r BetaRateLimitError) implementsBetaError() {}
type BetaRateLimitErrorType string
const (
BetaRateLimitErrorTypeRateLimitError BetaRateLimitErrorType = "rate_limit_error"
)
func (r BetaRateLimitErrorType) IsKnown() bool {
switch r {
case BetaRateLimitErrorTypeRateLimitError:
return true
}
return false
}