openai/openai-go

Public

mirrored from https://github.com/openai/openai-goAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feat-client-unwrap-error-message

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

shared/shared.go

509lines · modecode

1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3package shared
4
5import (
6 "github.com/openai/openai-go/internal/apijson"
7 "github.com/openai/openai-go/internal/param"
8)
9
10type ChatModel = string
11
12const (
13 ChatModelO3Mini ChatModel = "o3-mini"
14 ChatModelO3Mini2025_01_31 ChatModel = "o3-mini-2025-01-31"
15 ChatModelO1 ChatModel = "o1"
16 ChatModelO1_2024_12_17 ChatModel = "o1-2024-12-17"
17 ChatModelO1Preview ChatModel = "o1-preview"
18 ChatModelO1Preview2024_09_12 ChatModel = "o1-preview-2024-09-12"
19 ChatModelO1Mini ChatModel = "o1-mini"
20 ChatModelO1Mini2024_09_12 ChatModel = "o1-mini-2024-09-12"
21 ChatModelComputerUsePreview ChatModel = "computer-use-preview"
22 ChatModelComputerUsePreview2025_02_04 ChatModel = "computer-use-preview-2025-02-04"
23 ChatModelComputerUsePreview2025_03_11 ChatModel = "computer-use-preview-2025-03-11"
24 ChatModelGPT4_5Preview ChatModel = "gpt-4.5-preview"
25 ChatModelGPT4_5Preview2025_02_27 ChatModel = "gpt-4.5-preview-2025-02-27"
26 ChatModelGPT4o ChatModel = "gpt-4o"
27 ChatModelGPT4o2024_11_20 ChatModel = "gpt-4o-2024-11-20"
28 ChatModelGPT4o2024_08_06 ChatModel = "gpt-4o-2024-08-06"
29 ChatModelGPT4o2024_05_13 ChatModel = "gpt-4o-2024-05-13"
30 ChatModelGPT4oAudioPreview ChatModel = "gpt-4o-audio-preview"
31 ChatModelGPT4oAudioPreview2024_10_01 ChatModel = "gpt-4o-audio-preview-2024-10-01"
32 ChatModelGPT4oAudioPreview2024_12_17 ChatModel = "gpt-4o-audio-preview-2024-12-17"
33 ChatModelGPT4oMiniAudioPreview ChatModel = "gpt-4o-mini-audio-preview"
34 ChatModelGPT4oMiniAudioPreview2024_12_17 ChatModel = "gpt-4o-mini-audio-preview-2024-12-17"
35 ChatModelChatgpt4oLatest ChatModel = "chatgpt-4o-latest"
36 ChatModelGPT4oMini ChatModel = "gpt-4o-mini"
37 ChatModelGPT4oMini2024_07_18 ChatModel = "gpt-4o-mini-2024-07-18"
38 ChatModelGPT4Turbo ChatModel = "gpt-4-turbo"
39 ChatModelGPT4Turbo2024_04_09 ChatModel = "gpt-4-turbo-2024-04-09"
40 ChatModelGPT4_0125Preview ChatModel = "gpt-4-0125-preview"
41 ChatModelGPT4TurboPreview ChatModel = "gpt-4-turbo-preview"
42 ChatModelGPT4_1106Preview ChatModel = "gpt-4-1106-preview"
43 ChatModelGPT4VisionPreview ChatModel = "gpt-4-vision-preview"
44 ChatModelGPT4 ChatModel = "gpt-4"
45 ChatModelGPT4_0314 ChatModel = "gpt-4-0314"
46 ChatModelGPT4_0613 ChatModel = "gpt-4-0613"
47 ChatModelGPT4_32k ChatModel = "gpt-4-32k"
48 ChatModelGPT4_32k0314 ChatModel = "gpt-4-32k-0314"
49 ChatModelGPT4_32k0613 ChatModel = "gpt-4-32k-0613"
50 ChatModelGPT3_5Turbo ChatModel = "gpt-3.5-turbo"
51 ChatModelGPT3_5Turbo16k ChatModel = "gpt-3.5-turbo-16k"
52 ChatModelGPT3_5Turbo0301 ChatModel = "gpt-3.5-turbo-0301"
53 ChatModelGPT3_5Turbo0613 ChatModel = "gpt-3.5-turbo-0613"
54 ChatModelGPT3_5Turbo1106 ChatModel = "gpt-3.5-turbo-1106"
55 ChatModelGPT3_5Turbo0125 ChatModel = "gpt-3.5-turbo-0125"
56 ChatModelGPT3_5Turbo16k0613 ChatModel = "gpt-3.5-turbo-16k-0613"
57)
58
59// A filter used to compare a specified attribute key to a given value using a
60// defined comparison operation.
61type ComparisonFilterParam struct {
62 // The key to compare against the value.
63 Key param.Field[string] `json:"key,required"`
64 // Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`.
65 //
66 // - `eq`: equals
67 // - `ne`: not equal
68 // - `gt`: greater than
69 // - `gte`: greater than or equal
70 // - `lt`: less than
71 // - `lte`: less than or equal
72 Type param.Field[ComparisonFilterType] `json:"type,required"`
73 // The value to compare against the attribute key; supports string, number, or
74 // boolean types.
75 Value param.Field[ComparisonFilterValueUnionParam] `json:"value,required"`
76}
77
78func (r ComparisonFilterParam) MarshalJSON() (data []byte, err error) {
79 return apijson.MarshalRoot(r)
80}
81
82func (r ComparisonFilterParam) ImplementsVectorStoreSearchParamsFiltersUnion() {}
83
84// Specifies the comparison operator: `eq`, `ne`, `gt`, `gte`, `lt`, `lte`.
85//
86// - `eq`: equals
87// - `ne`: not equal
88// - `gt`: greater than
89// - `gte`: greater than or equal
90// - `lt`: less than
91// - `lte`: less than or equal
92type ComparisonFilterType string
93
94const (
95 ComparisonFilterTypeEq ComparisonFilterType = "eq"
96 ComparisonFilterTypeNe ComparisonFilterType = "ne"
97 ComparisonFilterTypeGt ComparisonFilterType = "gt"
98 ComparisonFilterTypeGte ComparisonFilterType = "gte"
99 ComparisonFilterTypeLt ComparisonFilterType = "lt"
100 ComparisonFilterTypeLte ComparisonFilterType = "lte"
101)
102
103func (r ComparisonFilterType) IsKnown() bool {
104 switch r {
105 case ComparisonFilterTypeEq, ComparisonFilterTypeNe, ComparisonFilterTypeGt, ComparisonFilterTypeGte, ComparisonFilterTypeLt, ComparisonFilterTypeLte:
106 return true
107 }
108 return false
109}
110
111// The value to compare against the attribute key; supports string, number, or
112// boolean types.
113//
114// Satisfied by [shared.UnionString], [shared.UnionFloat], [shared.UnionBool].
115type ComparisonFilterValueUnionParam interface {
116 ImplementsComparisonFilterValueUnionParam()
117}
118
119// Combine multiple filters using `and` or `or`.
120type CompoundFilterParam struct {
121 // Array of filters to combine. Items can be `ComparisonFilter` or
122 // `CompoundFilter`.
123 Filters param.Field[[]ComparisonFilterParam] `json:"filters,required"`
124 // Type of operation: `and` or `or`.
125 Type param.Field[CompoundFilterType] `json:"type,required"`
126}
127
128func (r CompoundFilterParam) MarshalJSON() (data []byte, err error) {
129 return apijson.MarshalRoot(r)
130}
131
132func (r CompoundFilterParam) ImplementsVectorStoreSearchParamsFiltersUnion() {}
133
134// Type of operation: `and` or `or`.
135type CompoundFilterType string
136
137const (
138 CompoundFilterTypeAnd CompoundFilterType = "and"
139 CompoundFilterTypeOr CompoundFilterType = "or"
140)
141
142func (r CompoundFilterType) IsKnown() bool {
143 switch r {
144 case CompoundFilterTypeAnd, CompoundFilterTypeOr:
145 return true
146 }
147 return false
148}
149
150type ErrorObject struct {
151 Code string `json:"code,required,nullable"`
152 Message string `json:"message,required"`
153 Param string `json:"param,required,nullable"`
154 Type string `json:"type,required"`
155 JSON errorObjectJSON `json:"-"`
156}
157
158// errorObjectJSON contains the JSON metadata for the struct [ErrorObject]
159type errorObjectJSON struct {
160 Code apijson.Field
161 Message apijson.Field
162 Param apijson.Field
163 Type apijson.Field
164 raw string
165 ExtraFields map[string]apijson.Field
166}
167
168func (r *ErrorObject) UnmarshalJSON(data []byte) (err error) {
169 return apijson.UnmarshalRoot(data, r)
170}
171
172func (r errorObjectJSON) RawJSON() string {
173 return r.raw
174}
175
176type FunctionDefinition struct {
177 // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
178 // underscores and dashes, with a maximum length of 64.
179 Name string `json:"name,required"`
180 // A description of what the function does, used by the model to choose when and
181 // how to call the function.
182 Description string `json:"description"`
183 // The parameters the functions accepts, described as a JSON Schema object. See the
184 // [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
185 // and the
186 // [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
187 // documentation about the format.
188 //
189 // Omitting `parameters` defines a function with an empty parameter list.
190 Parameters FunctionParameters `json:"parameters"`
191 // Whether to enable strict schema adherence when generating the function call. If
192 // set to true, the model will follow the exact schema defined in the `parameters`
193 // field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn
194 // more about Structured Outputs in the
195 // [function calling guide](docs/guides/function-calling).
196 Strict bool `json:"strict,nullable"`
197 JSON functionDefinitionJSON `json:"-"`
198}
199
200// functionDefinitionJSON contains the JSON metadata for the struct
201// [FunctionDefinition]
202type functionDefinitionJSON struct {
203 Name apijson.Field
204 Description apijson.Field
205 Parameters apijson.Field
206 Strict apijson.Field
207 raw string
208 ExtraFields map[string]apijson.Field
209}
210
211func (r *FunctionDefinition) UnmarshalJSON(data []byte) (err error) {
212 return apijson.UnmarshalRoot(data, r)
213}
214
215func (r functionDefinitionJSON) RawJSON() string {
216 return r.raw
217}
218
219type FunctionDefinitionParam struct {
220 // The name of the function to be called. Must be a-z, A-Z, 0-9, or contain
221 // underscores and dashes, with a maximum length of 64.
222 Name param.Field[string] `json:"name,required"`
223 // A description of what the function does, used by the model to choose when and
224 // how to call the function.
225 Description param.Field[string] `json:"description"`
226 // The parameters the functions accepts, described as a JSON Schema object. See the
227 // [guide](https://platform.openai.com/docs/guides/function-calling) for examples,
228 // and the
229 // [JSON Schema reference](https://json-schema.org/understanding-json-schema/) for
230 // documentation about the format.
231 //
232 // Omitting `parameters` defines a function with an empty parameter list.
233 Parameters param.Field[FunctionParameters] `json:"parameters"`
234 // Whether to enable strict schema adherence when generating the function call. If
235 // set to true, the model will follow the exact schema defined in the `parameters`
236 // field. Only a subset of JSON Schema is supported when `strict` is `true`. Learn
237 // more about Structured Outputs in the
238 // [function calling guide](docs/guides/function-calling).
239 Strict param.Field[bool] `json:"strict"`
240}
241
242func (r FunctionDefinitionParam) MarshalJSON() (data []byte, err error) {
243 return apijson.MarshalRoot(r)
244}
245
246type FunctionParameters map[string]interface{}
247
248type Metadata map[string]string
249
250type MetadataParam map[string]string
251
252// **o-series models only**
253//
254// Constrains effort on reasoning for
255// [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
256// supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
257// result in faster responses and fewer tokens used on reasoning in a response.
258type ReasoningEffort string
259
260const (
261 ReasoningEffortLow ReasoningEffort = "low"
262 ReasoningEffortMedium ReasoningEffort = "medium"
263 ReasoningEffortHigh ReasoningEffort = "high"
264)
265
266func (r ReasoningEffort) IsKnown() bool {
267 switch r {
268 case ReasoningEffortLow, ReasoningEffortMedium, ReasoningEffortHigh:
269 return true
270 }
271 return false
272}
273
274// JSON object response format. An older method of generating JSON responses. Using
275// `json_schema` is recommended for models that support it. Note that the model
276// will not generate JSON without a system or user message instructing it to do so.
277type ResponseFormatJSONObject struct {
278 // The type of response format being defined. Always `json_object`.
279 Type ResponseFormatJSONObjectType `json:"type,required"`
280 JSON responseFormatJSONObjectJSON `json:"-"`
281}
282
283// responseFormatJSONObjectJSON contains the JSON metadata for the struct
284// [ResponseFormatJSONObject]
285type responseFormatJSONObjectJSON struct {
286 Type apijson.Field
287 raw string
288 ExtraFields map[string]apijson.Field
289}
290
291func (r *ResponseFormatJSONObject) UnmarshalJSON(data []byte) (err error) {
292 return apijson.UnmarshalRoot(data, r)
293}
294
295func (r responseFormatJSONObjectJSON) RawJSON() string {
296 return r.raw
297}
298
299func (r ResponseFormatJSONObject) ImplementsAssistantResponseFormatOptionUnion() {}
300
301// The type of response format being defined. Always `json_object`.
302type ResponseFormatJSONObjectType string
303
304const (
305 ResponseFormatJSONObjectTypeJSONObject ResponseFormatJSONObjectType = "json_object"
306)
307
308func (r ResponseFormatJSONObjectType) IsKnown() bool {
309 switch r {
310 case ResponseFormatJSONObjectTypeJSONObject:
311 return true
312 }
313 return false
314}
315
316// JSON object response format. An older method of generating JSON responses. Using
317// `json_schema` is recommended for models that support it. Note that the model
318// will not generate JSON without a system or user message instructing it to do so.
319type ResponseFormatJSONObjectParam struct {
320 // The type of response format being defined. Always `json_object`.
321 Type param.Field[ResponseFormatJSONObjectType] `json:"type,required"`
322}
323
324func (r ResponseFormatJSONObjectParam) MarshalJSON() (data []byte, err error) {
325 return apijson.MarshalRoot(r)
326}
327
328func (r ResponseFormatJSONObjectParam) ImplementsChatCompletionNewParamsResponseFormatUnion() {}
329
330func (r ResponseFormatJSONObjectParam) ImplementsAssistantResponseFormatOptionUnionParam() {}
331
332// JSON Schema response format. Used to generate structured JSON responses. Learn
333// more about
334// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
335type ResponseFormatJSONSchema struct {
336 // Structured Outputs configuration options, including a JSON Schema.
337 JSONSchema ResponseFormatJSONSchemaJSONSchema `json:"json_schema,required"`
338 // The type of response format being defined. Always `json_schema`.
339 Type ResponseFormatJSONSchemaType `json:"type,required"`
340 JSON responseFormatJSONSchemaJSON `json:"-"`
341}
342
343// responseFormatJSONSchemaJSON contains the JSON metadata for the struct
344// [ResponseFormatJSONSchema]
345type responseFormatJSONSchemaJSON struct {
346 JSONSchema apijson.Field
347 Type apijson.Field
348 raw string
349 ExtraFields map[string]apijson.Field
350}
351
352func (r *ResponseFormatJSONSchema) UnmarshalJSON(data []byte) (err error) {
353 return apijson.UnmarshalRoot(data, r)
354}
355
356func (r responseFormatJSONSchemaJSON) RawJSON() string {
357 return r.raw
358}
359
360func (r ResponseFormatJSONSchema) ImplementsAssistantResponseFormatOptionUnion() {}
361
362// Structured Outputs configuration options, including a JSON Schema.
363type ResponseFormatJSONSchemaJSONSchema struct {
364 // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores
365 // and dashes, with a maximum length of 64.
366 Name string `json:"name,required"`
367 // A description of what the response format is for, used by the model to determine
368 // how to respond in the format.
369 Description string `json:"description"`
370 // The schema for the response format, described as a JSON Schema object. Learn how
371 // to build JSON schemas [here](https://json-schema.org/).
372 Schema map[string]interface{} `json:"schema"`
373 // Whether to enable strict schema adherence when generating the output. If set to
374 // true, the model will always follow the exact schema defined in the `schema`
375 // field. Only a subset of JSON Schema is supported when `strict` is `true`. To
376 // learn more, read the
377 // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
378 Strict bool `json:"strict,nullable"`
379 JSON responseFormatJSONSchemaJSONSchemaJSON `json:"-"`
380}
381
382// responseFormatJSONSchemaJSONSchemaJSON contains the JSON metadata for the struct
383// [ResponseFormatJSONSchemaJSONSchema]
384type responseFormatJSONSchemaJSONSchemaJSON struct {
385 Name apijson.Field
386 Description apijson.Field
387 Schema apijson.Field
388 Strict apijson.Field
389 raw string
390 ExtraFields map[string]apijson.Field
391}
392
393func (r *ResponseFormatJSONSchemaJSONSchema) UnmarshalJSON(data []byte) (err error) {
394 return apijson.UnmarshalRoot(data, r)
395}
396
397func (r responseFormatJSONSchemaJSONSchemaJSON) RawJSON() string {
398 return r.raw
399}
400
401// The type of response format being defined. Always `json_schema`.
402type ResponseFormatJSONSchemaType string
403
404const (
405 ResponseFormatJSONSchemaTypeJSONSchema ResponseFormatJSONSchemaType = "json_schema"
406)
407
408func (r ResponseFormatJSONSchemaType) IsKnown() bool {
409 switch r {
410 case ResponseFormatJSONSchemaTypeJSONSchema:
411 return true
412 }
413 return false
414}
415
416// JSON Schema response format. Used to generate structured JSON responses. Learn
417// more about
418// [Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs).
419type ResponseFormatJSONSchemaParam struct {
420 // Structured Outputs configuration options, including a JSON Schema.
421 JSONSchema param.Field[ResponseFormatJSONSchemaJSONSchemaParam] `json:"json_schema,required"`
422 // The type of response format being defined. Always `json_schema`.
423 Type param.Field[ResponseFormatJSONSchemaType] `json:"type,required"`
424}
425
426func (r ResponseFormatJSONSchemaParam) MarshalJSON() (data []byte, err error) {
427 return apijson.MarshalRoot(r)
428}
429
430func (r ResponseFormatJSONSchemaParam) ImplementsChatCompletionNewParamsResponseFormatUnion() {}
431
432func (r ResponseFormatJSONSchemaParam) ImplementsAssistantResponseFormatOptionUnionParam() {}
433
434// Structured Outputs configuration options, including a JSON Schema.
435type ResponseFormatJSONSchemaJSONSchemaParam struct {
436 // The name of the response format. Must be a-z, A-Z, 0-9, or contain underscores
437 // and dashes, with a maximum length of 64.
438 Name param.Field[string] `json:"name,required"`
439 // A description of what the response format is for, used by the model to determine
440 // how to respond in the format.
441 Description param.Field[string] `json:"description"`
442 // The schema for the response format, described as a JSON Schema object. Learn how
443 // to build JSON schemas [here](https://json-schema.org/).
444 Schema param.Field[map[string]interface{}] `json:"schema"`
445 // Whether to enable strict schema adherence when generating the output. If set to
446 // true, the model will always follow the exact schema defined in the `schema`
447 // field. Only a subset of JSON Schema is supported when `strict` is `true`. To
448 // learn more, read the
449 // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
450 Strict param.Field[bool] `json:"strict"`
451}
452
453func (r ResponseFormatJSONSchemaJSONSchemaParam) MarshalJSON() (data []byte, err error) {
454 return apijson.MarshalRoot(r)
455}
456
457// Default response format. Used to generate text responses.
458type ResponseFormatText struct {
459 // The type of response format being defined. Always `text`.
460 Type ResponseFormatTextType `json:"type,required"`
461 JSON responseFormatTextJSON `json:"-"`
462}
463
464// responseFormatTextJSON contains the JSON metadata for the struct
465// [ResponseFormatText]
466type responseFormatTextJSON struct {
467 Type apijson.Field
468 raw string
469 ExtraFields map[string]apijson.Field
470}
471
472func (r *ResponseFormatText) UnmarshalJSON(data []byte) (err error) {
473 return apijson.UnmarshalRoot(data, r)
474}
475
476func (r responseFormatTextJSON) RawJSON() string {
477 return r.raw
478}
479
480func (r ResponseFormatText) ImplementsAssistantResponseFormatOptionUnion() {}
481
482// The type of response format being defined. Always `text`.
483type ResponseFormatTextType string
484
485const (
486 ResponseFormatTextTypeText ResponseFormatTextType = "text"
487)
488
489func (r ResponseFormatTextType) IsKnown() bool {
490 switch r {
491 case ResponseFormatTextTypeText:
492 return true
493 }
494 return false
495}
496
497// Default response format. Used to generate text responses.
498type ResponseFormatTextParam struct {
499 // The type of response format being defined. Always `text`.
500 Type param.Field[ResponseFormatTextType] `json:"type,required"`
501}
502
503func (r ResponseFormatTextParam) MarshalJSON() (data []byte, err error) {
504 return apijson.MarshalRoot(r)
505}
506
507func (r ResponseFormatTextParam) ImplementsChatCompletionNewParamsResponseFormatUnion() {}
508
509func (r ResponseFormatTextParam) ImplementsAssistantResponseFormatOptionUnionParam() {}
510