-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathbetamodel.go
More file actions
318 lines (293 loc) · 12.4 KB
/
betamodel.go
File metadata and controls
318 lines (293 loc) · 12.4 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package anthropic
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/anthropics/anthropic-sdk-go/internal/apijson"
"github.com/anthropics/anthropic-sdk-go/internal/apiquery"
"github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/anthropics/anthropic-sdk-go/packages/pagination"
"github.com/anthropics/anthropic-sdk-go/packages/param"
"github.com/anthropics/anthropic-sdk-go/packages/respjson"
"github.com/anthropics/anthropic-sdk-go/shared/constant"
)
// BetaModelService 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 [NewBetaModelService] method instead.
type BetaModelService struct {
Options []option.RequestOption
}
// NewBetaModelService 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 NewBetaModelService(opts ...option.RequestOption) (r BetaModelService) {
r = BetaModelService{}
r.Options = opts
return
}
// Get a specific model.
//
// The Models API response can be used to determine information about a specific
// model or resolve a model alias to a model ID.
func (r *BetaModelService) Get(ctx context.Context, modelID string, query BetaModelGetParams, opts ...option.RequestOption) (res *BetaModelInfo, err error) {
for _, v := range query.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
if modelID == "" {
err = errors.New("missing required model_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/models/%s?beta=true", modelID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// List available models.
//
// The Models API response can be used to determine which models are available for
// use in the API. More recently released models are listed first.
func (r *BetaModelService) List(ctx context.Context, params BetaModelListParams, opts ...option.RequestOption) (res *pagination.Page[BetaModelInfo], err error) {
var raw *http.Response
for _, v := range params.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithResponseInto(&raw)}, opts...)
path := "v1/models?beta=true"
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List available models.
//
// The Models API response can be used to determine which models are available for
// use in the API. More recently released models are listed first.
func (r *BetaModelService) ListAutoPaging(ctx context.Context, params BetaModelListParams, opts ...option.RequestOption) *pagination.PageAutoPager[BetaModelInfo] {
return pagination.NewPageAutoPager(r.List(ctx, params, opts...))
}
// Indicates whether a capability is supported.
type BetaCapabilitySupport struct {
// Whether this capability is supported by the model.
Supported bool `json:"supported" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Supported respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaCapabilitySupport) RawJSON() string { return r.JSON.raw }
func (r *BetaCapabilitySupport) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Context management capability details.
type BetaContextManagementCapability struct {
// Indicates whether a capability is supported.
ClearThinking20251015 BetaCapabilitySupport `json:"clear_thinking_20251015" api:"required"`
// Indicates whether a capability is supported.
ClearToolUses20250919 BetaCapabilitySupport `json:"clear_tool_uses_20250919" api:"required"`
// Indicates whether a capability is supported.
Compact20260112 BetaCapabilitySupport `json:"compact_20260112" api:"required"`
// Whether this capability is supported by the model.
Supported bool `json:"supported" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ClearThinking20251015 respjson.Field
ClearToolUses20250919 respjson.Field
Compact20260112 respjson.Field
Supported respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaContextManagementCapability) RawJSON() string { return r.JSON.raw }
func (r *BetaContextManagementCapability) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Effort (reasoning_effort) capability details.
type BetaEffortCapability struct {
// Whether the model supports high effort level.
High BetaCapabilitySupport `json:"high" api:"required"`
// Whether the model supports low effort level.
Low BetaCapabilitySupport `json:"low" api:"required"`
// Whether the model supports max effort level.
Max BetaCapabilitySupport `json:"max" api:"required"`
// Whether the model supports medium effort level.
Medium BetaCapabilitySupport `json:"medium" api:"required"`
// Whether this capability is supported by the model.
Supported bool `json:"supported" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
High respjson.Field
Low respjson.Field
Max respjson.Field
Medium respjson.Field
Supported respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaEffortCapability) RawJSON() string { return r.JSON.raw }
func (r *BetaEffortCapability) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Model capability information.
type BetaModelCapabilities struct {
// Whether the model supports the Batch API.
Batch BetaCapabilitySupport `json:"batch" api:"required"`
// Whether the model supports citation generation.
Citations BetaCapabilitySupport `json:"citations" api:"required"`
// Whether the model supports code execution tools.
CodeExecution BetaCapabilitySupport `json:"code_execution" api:"required"`
// Context management support and available strategies.
ContextManagement BetaContextManagementCapability `json:"context_management" api:"required"`
// Effort (reasoning_effort) support and available levels.
Effort BetaEffortCapability `json:"effort" api:"required"`
// Whether the model accepts image content blocks.
ImageInput BetaCapabilitySupport `json:"image_input" api:"required"`
// Whether the model accepts PDF content blocks.
PDFInput BetaCapabilitySupport `json:"pdf_input" api:"required"`
// Whether the model supports structured output / JSON mode / strict tool schemas.
StructuredOutputs BetaCapabilitySupport `json:"structured_outputs" api:"required"`
// Thinking capability and supported type configurations.
Thinking BetaThinkingCapability `json:"thinking" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Batch respjson.Field
Citations respjson.Field
CodeExecution respjson.Field
ContextManagement respjson.Field
Effort respjson.Field
ImageInput respjson.Field
PDFInput respjson.Field
StructuredOutputs respjson.Field
Thinking respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaModelCapabilities) RawJSON() string { return r.JSON.raw }
func (r *BetaModelCapabilities) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaModelInfo struct {
// Unique model identifier.
ID string `json:"id" api:"required"`
// Model capability information.
Capabilities BetaModelCapabilities `json:"capabilities" api:"required"`
// RFC 3339 datetime string representing the time at which the model was released.
// May be set to an epoch value if the release date is unknown.
CreatedAt time.Time `json:"created_at" api:"required" format:"date-time"`
// A human-readable name for the model.
DisplayName string `json:"display_name" api:"required"`
// Maximum input context window size in tokens for this model.
MaxInputTokens int64 `json:"max_input_tokens" api:"required"`
// Maximum value for the `max_tokens` parameter when using this model.
MaxTokens int64 `json:"max_tokens" api:"required"`
// Object type.
//
// For Models, this is always `"model"`.
Type constant.Model `json:"type" default:"model"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Capabilities respjson.Field
CreatedAt respjson.Field
DisplayName respjson.Field
MaxInputTokens respjson.Field
MaxTokens respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaModelInfo) RawJSON() string { return r.JSON.raw }
func (r *BetaModelInfo) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Thinking capability details.
type BetaThinkingCapability struct {
// Whether this capability is supported by the model.
Supported bool `json:"supported" api:"required"`
// Supported thinking type configurations.
Types BetaThinkingTypes `json:"types" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Supported respjson.Field
Types respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaThinkingCapability) RawJSON() string { return r.JSON.raw }
func (r *BetaThinkingCapability) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Supported thinking type configurations.
type BetaThinkingTypes struct {
// Whether the model supports thinking with type 'adaptive' (auto).
Adaptive BetaCapabilitySupport `json:"adaptive" api:"required"`
// Whether the model supports thinking with type 'enabled'.
Enabled BetaCapabilitySupport `json:"enabled" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Adaptive respjson.Field
Enabled respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaThinkingTypes) RawJSON() string { return r.JSON.raw }
func (r *BetaThinkingTypes) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaModelGetParams struct {
// Optional header to specify the beta version(s) you want to use.
Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
paramObj
}
type BetaModelListParams struct {
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately after this object.
AfterID param.Opt[string] `query:"after_id,omitzero" json:"-"`
// ID of the object to use as a cursor for pagination. When provided, returns the
// page of results immediately before this object.
BeforeID param.Opt[string] `query:"before_id,omitzero" json:"-"`
// Number of items to return per page.
//
// Defaults to `20`. Ranges from `1` to `1000`.
Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
// Optional header to specify the beta version(s) you want to use.
Betas []AnthropicBeta `header:"anthropic-beta,omitzero" json:"-"`
paramObj
}
// URLQuery serializes [BetaModelListParams]'s query parameters as `url.Values`.
func (r BetaModelListParams) URLQuery() (v url.Values, err error) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatComma,
NestedFormat: apiquery.NestedQueryFormatBrackets,
})
}