1// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3package openai
4
5import (
6 "context"
7 "encoding/json"
8 "errors"
9 "fmt"
10 "net/http"
11 "reflect"
12
13 "github.com/openai/openai-go/internal/apijson"
14 "github.com/openai/openai-go/internal/requestconfig"
15 "github.com/openai/openai-go/option"
16 "github.com/openai/openai-go/packages/param"
17 "github.com/openai/openai-go/packages/resp"
18 "github.com/openai/openai-go/packages/ssestream"
19 "github.com/openai/openai-go/shared"
20 "github.com/openai/openai-go/shared/constant"
21 "github.com/tidwall/gjson"
22)
23
24// BetaThreadService contains methods and other services that help with interacting
25// with the openai API.
26//
27// Note, unlike clients, this service does not read variables from the environment
28// automatically. You should not instantiate this service directly, and instead use
29// the [NewBetaThreadService] method instead.
30type BetaThreadService struct {
31 Options []option.RequestOption
32 Runs BetaThreadRunService
33 Messages BetaThreadMessageService
34}
35
36// NewBetaThreadService generates a new service that applies the given options to
37// each request. These options are applied after the parent client's options (if
38// there is one), and before any request-specific options.
39func NewBetaThreadService(opts ...option.RequestOption) (r BetaThreadService) {
40 r = BetaThreadService{}
41 r.Options = opts
42 r.Runs = NewBetaThreadRunService(opts...)
43 r.Messages = NewBetaThreadMessageService(opts...)
44 return
45}
46
47// Create a thread.
48func (r *BetaThreadService) New(ctx context.Context, body BetaThreadNewParams, opts ...option.RequestOption) (res *Thread, err error) {
49 opts = append(r.Options[:], opts...)
50 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
51 path := "threads"
52 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
53 return
54}
55
56// Create a thread and run it in one request. Poll the API until the run is complete.
57func (r *BetaThreadService) NewAndRunPoll(ctx context.Context, body BetaThreadNewAndRunParams, pollIntervalMs int, opts ...option.RequestOption) (res *Run, err error) {
58 run, err := r.NewAndRun(ctx, body, opts...)
59 if err != nil {
60 return nil, err
61 }
62 return r.Runs.PollStatus(ctx, run.ThreadID, run.ID, pollIntervalMs, opts...)
63}
64
65// Retrieves a thread.
66func (r *BetaThreadService) Get(ctx context.Context, threadID string, opts ...option.RequestOption) (res *Thread, err error) {
67 opts = append(r.Options[:], opts...)
68 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
69 if threadID == "" {
70 err = errors.New("missing required thread_id parameter")
71 return
72 }
73 path := fmt.Sprintf("threads/%s", threadID)
74 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
75 return
76}
77
78// Modifies a thread.
79func (r *BetaThreadService) Update(ctx context.Context, threadID string, body BetaThreadUpdateParams, opts ...option.RequestOption) (res *Thread, err error) {
80 opts = append(r.Options[:], opts...)
81 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
82 if threadID == "" {
83 err = errors.New("missing required thread_id parameter")
84 return
85 }
86 path := fmt.Sprintf("threads/%s", threadID)
87 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
88 return
89}
90
91// Delete a thread.
92func (r *BetaThreadService) Delete(ctx context.Context, threadID string, opts ...option.RequestOption) (res *ThreadDeleted, err error) {
93 opts = append(r.Options[:], opts...)
94 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
95 if threadID == "" {
96 err = errors.New("missing required thread_id parameter")
97 return
98 }
99 path := fmt.Sprintf("threads/%s", threadID)
100 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
101 return
102}
103
104// Create a thread and run it in one request.
105func (r *BetaThreadService) NewAndRun(ctx context.Context, body BetaThreadNewAndRunParams, opts ...option.RequestOption) (res *Run, err error) {
106 opts = append(r.Options[:], opts...)
107 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
108 path := "threads/runs"
109 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
110 return
111}
112
113// Create a thread and run it in one request.
114func (r *BetaThreadService) NewAndRunStreaming(ctx context.Context, body BetaThreadNewAndRunParams, opts ...option.RequestOption) (stream *ssestream.Stream[AssistantStreamEventUnion]) {
115 var (
116 raw *http.Response
117 err error
118 )
119 opts = append(r.Options[:], opts...)
120 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithJSONSet("stream", true)}, opts...)
121 path := "threads/runs"
122 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
123 return ssestream.NewStream[AssistantStreamEventUnion](ssestream.NewDecoder(raw), err)
124}
125
126// AssistantResponseFormatOptionUnion contains all possible properties and values
127// from [constant.Auto], [shared.ResponseFormatText],
128// [shared.ResponseFormatJSONObject], [shared.ResponseFormatJSONSchema].
129//
130// Use the methods beginning with 'As' to cast the union to one of its variants.
131//
132// If the underlying value is not a json object, one of the following properties
133// will be valid: OfAuto]
134type AssistantResponseFormatOptionUnion struct {
135 // This field will be present if the value is a [constant.Auto] instead of an
136 // object.
137 OfAuto constant.Auto `json:",inline"`
138 Type string `json:"type"`
139 // This field is from variant [shared.ResponseFormatJSONSchema].
140 JSONSchema shared.ResponseFormatJSONSchemaJSONSchema `json:"json_schema"`
141 JSON struct {
142 OfAuto resp.Field
143 Type resp.Field
144 JSONSchema resp.Field
145 raw string
146 } `json:"-"`
147}
148
149func (u AssistantResponseFormatOptionUnion) AsAuto() (v constant.Auto) {
150 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
151 return
152}
153
154func (u AssistantResponseFormatOptionUnion) AsText() (v shared.ResponseFormatText) {
155 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
156 return
157}
158
159func (u AssistantResponseFormatOptionUnion) AsJSONObject() (v shared.ResponseFormatJSONObject) {
160 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
161 return
162}
163
164func (u AssistantResponseFormatOptionUnion) AsJSONSchema() (v shared.ResponseFormatJSONSchema) {
165 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
166 return
167}
168
169// Returns the unmodified JSON received from the API
170func (u AssistantResponseFormatOptionUnion) RawJSON() string { return u.JSON.raw }
171
172func (r *AssistantResponseFormatOptionUnion) UnmarshalJSON(data []byte) error {
173 return apijson.UnmarshalRoot(data, r)
174}
175
176// ToParam converts this AssistantResponseFormatOptionUnion to a
177// AssistantResponseFormatOptionUnionParam.
178//
179// Warning: the fields of the param type will not be present. ToParam should only
180// be used at the last possible moment before sending a request. Test for this with
181// AssistantResponseFormatOptionUnionParam.IsOverridden()
182func (r AssistantResponseFormatOptionUnion) ToParam() AssistantResponseFormatOptionUnionParam {
183 return param.OverrideObj[AssistantResponseFormatOptionUnionParam](r.RawJSON())
184}
185
186func AssistantResponseFormatOptionParamOfAuto() AssistantResponseFormatOptionUnionParam {
187 return AssistantResponseFormatOptionUnionParam{OfAuto: constant.ValueOf[constant.Auto]()}
188}
189
190func AssistantResponseFormatOptionParamOfJSONSchema(jsonSchema shared.ResponseFormatJSONSchemaJSONSchemaParam) AssistantResponseFormatOptionUnionParam {
191 var variant shared.ResponseFormatJSONSchemaParam
192 variant.JSONSchema = jsonSchema
193 return AssistantResponseFormatOptionUnionParam{OfJSONSchema: &variant}
194}
195
196// Only one field can be non-zero.
197//
198// Use [param.IsOmitted] to confirm if a field is set.
199type AssistantResponseFormatOptionUnionParam struct {
200 // Construct this variant with constant.New[constant.Auto]() Check if union is this
201 // variant with !param.IsOmitted(union.OfAuto)
202 OfAuto constant.Auto `json:",omitzero,inline"`
203 OfText *shared.ResponseFormatTextParam `json:",omitzero,inline"`
204 OfJSONObject *shared.ResponseFormatJSONObjectParam `json:",omitzero,inline"`
205 OfJSONSchema *shared.ResponseFormatJSONSchemaParam `json:",omitzero,inline"`
206 paramUnion
207}
208
209// IsPresent returns true if the field's value is not omitted and not the JSON
210// "null". To check if this field is omitted, use [param.IsOmitted].
211func (u AssistantResponseFormatOptionUnionParam) IsPresent() bool {
212 return !param.IsOmitted(u) && !u.IsNull()
213}
214func (u AssistantResponseFormatOptionUnionParam) MarshalJSON() ([]byte, error) {
215 return param.MarshalUnion[AssistantResponseFormatOptionUnionParam](u.OfAuto, u.OfText, u.OfJSONObject, u.OfJSONSchema)
216}
217
218func (u *AssistantResponseFormatOptionUnionParam) asAny() any {
219 if !param.IsOmitted(u.OfAuto) {
220 return &u.OfAuto
221 } else if !param.IsOmitted(u.OfText) {
222 return u.OfText
223 } else if !param.IsOmitted(u.OfJSONObject) {
224 return u.OfJSONObject
225 } else if !param.IsOmitted(u.OfJSONSchema) {
226 return u.OfJSONSchema
227 }
228 return nil
229}
230
231// Returns a pointer to the underlying variant's property, if present.
232func (u AssistantResponseFormatOptionUnionParam) GetJSONSchema() *shared.ResponseFormatJSONSchemaJSONSchemaParam {
233 if vt := u.OfJSONSchema; vt != nil {
234 return &vt.JSONSchema
235 }
236 return nil
237}
238
239// Returns a pointer to the underlying variant's property, if present.
240func (u AssistantResponseFormatOptionUnionParam) GetType() *string {
241 if vt := u.OfText; vt != nil {
242 return (*string)(&vt.Type)
243 } else if vt := u.OfJSONObject; vt != nil {
244 return (*string)(&vt.Type)
245 } else if vt := u.OfJSONSchema; vt != nil {
246 return (*string)(&vt.Type)
247 }
248 return nil
249}
250
251// Specifies a tool the model should use. Use to force the model to call a specific
252// tool.
253type AssistantToolChoice struct {
254 // The type of the tool. If type is `function`, the function name must be set
255 //
256 // Any of "function", "code_interpreter", "file_search".
257 Type AssistantToolChoiceType `json:"type,required"`
258 Function AssistantToolChoiceFunction `json:"function"`
259 // Metadata for the response, check the presence of optional fields with the
260 // [resp.Field.IsPresent] method.
261 JSON struct {
262 Type resp.Field
263 Function resp.Field
264 ExtraFields map[string]resp.Field
265 raw string
266 } `json:"-"`
267}
268
269// Returns the unmodified JSON received from the API
270func (r AssistantToolChoice) RawJSON() string { return r.JSON.raw }
271func (r *AssistantToolChoice) UnmarshalJSON(data []byte) error {
272 return apijson.UnmarshalRoot(data, r)
273}
274
275// ToParam converts this AssistantToolChoice to a AssistantToolChoiceParam.
276//
277// Warning: the fields of the param type will not be present. ToParam should only
278// be used at the last possible moment before sending a request. Test for this with
279// AssistantToolChoiceParam.IsOverridden()
280func (r AssistantToolChoice) ToParam() AssistantToolChoiceParam {
281 return param.OverrideObj[AssistantToolChoiceParam](r.RawJSON())
282}
283
284// The type of the tool. If type is `function`, the function name must be set
285type AssistantToolChoiceType string
286
287const (
288 AssistantToolChoiceTypeFunction AssistantToolChoiceType = "function"
289 AssistantToolChoiceTypeCodeInterpreter AssistantToolChoiceType = "code_interpreter"
290 AssistantToolChoiceTypeFileSearch AssistantToolChoiceType = "file_search"
291)
292
293// Specifies a tool the model should use. Use to force the model to call a specific
294// tool.
295//
296// The property Type is required.
297type AssistantToolChoiceParam struct {
298 // The type of the tool. If type is `function`, the function name must be set
299 //
300 // Any of "function", "code_interpreter", "file_search".
301 Type AssistantToolChoiceType `json:"type,omitzero,required"`
302 Function AssistantToolChoiceFunctionParam `json:"function,omitzero"`
303 paramObj
304}
305
306// IsPresent returns true if the field's value is not omitted and not the JSON
307// "null". To check if this field is omitted, use [param.IsOmitted].
308func (f AssistantToolChoiceParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
309func (r AssistantToolChoiceParam) MarshalJSON() (data []byte, err error) {
310 type shadow AssistantToolChoiceParam
311 return param.MarshalObject(r, (*shadow)(&r))
312}
313
314type AssistantToolChoiceFunction struct {
315 // The name of the function to call.
316 Name string `json:"name,required"`
317 // Metadata for the response, check the presence of optional fields with the
318 // [resp.Field.IsPresent] method.
319 JSON struct {
320 Name resp.Field
321 ExtraFields map[string]resp.Field
322 raw string
323 } `json:"-"`
324}
325
326// Returns the unmodified JSON received from the API
327func (r AssistantToolChoiceFunction) RawJSON() string { return r.JSON.raw }
328func (r *AssistantToolChoiceFunction) UnmarshalJSON(data []byte) error {
329 return apijson.UnmarshalRoot(data, r)
330}
331
332// ToParam converts this AssistantToolChoiceFunction to a
333// AssistantToolChoiceFunctionParam.
334//
335// Warning: the fields of the param type will not be present. ToParam should only
336// be used at the last possible moment before sending a request. Test for this with
337// AssistantToolChoiceFunctionParam.IsOverridden()
338func (r AssistantToolChoiceFunction) ToParam() AssistantToolChoiceFunctionParam {
339 return param.OverrideObj[AssistantToolChoiceFunctionParam](r.RawJSON())
340}
341
342// The property Name is required.
343type AssistantToolChoiceFunctionParam struct {
344 // The name of the function to call.
345 Name string `json:"name,required"`
346 paramObj
347}
348
349// IsPresent returns true if the field's value is not omitted and not the JSON
350// "null". To check if this field is omitted, use [param.IsOmitted].
351func (f AssistantToolChoiceFunctionParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
352func (r AssistantToolChoiceFunctionParam) MarshalJSON() (data []byte, err error) {
353 type shadow AssistantToolChoiceFunctionParam
354 return param.MarshalObject(r, (*shadow)(&r))
355}
356
357// AssistantToolChoiceOptionUnion contains all possible properties and values from
358// [string], [AssistantToolChoice].
359//
360// Use the methods beginning with 'As' to cast the union to one of its variants.
361//
362// If the underlying value is not a json object, one of the following properties
363// will be valid: OfAuto]
364type AssistantToolChoiceOptionUnion struct {
365 // This field will be present if the value is a [string] instead of an object.
366 OfAuto string `json:",inline"`
367 // This field is from variant [AssistantToolChoice].
368 Type AssistantToolChoiceType `json:"type"`
369 // This field is from variant [AssistantToolChoice].
370 Function AssistantToolChoiceFunction `json:"function"`
371 JSON struct {
372 OfAuto resp.Field
373 Type resp.Field
374 Function resp.Field
375 raw string
376 } `json:"-"`
377}
378
379func (u AssistantToolChoiceOptionUnion) AsAuto() (v string) {
380 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
381 return
382}
383
384func (u AssistantToolChoiceOptionUnion) AsAssistantToolChoice() (v AssistantToolChoice) {
385 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
386 return
387}
388
389// Returns the unmodified JSON received from the API
390func (u AssistantToolChoiceOptionUnion) RawJSON() string { return u.JSON.raw }
391
392func (r *AssistantToolChoiceOptionUnion) UnmarshalJSON(data []byte) error {
393 return apijson.UnmarshalRoot(data, r)
394}
395
396// ToParam converts this AssistantToolChoiceOptionUnion to a
397// AssistantToolChoiceOptionUnionParam.
398//
399// Warning: the fields of the param type will not be present. ToParam should only
400// be used at the last possible moment before sending a request. Test for this with
401// AssistantToolChoiceOptionUnionParam.IsOverridden()
402func (r AssistantToolChoiceOptionUnion) ToParam() AssistantToolChoiceOptionUnionParam {
403 return param.OverrideObj[AssistantToolChoiceOptionUnionParam](r.RawJSON())
404}
405
406func AssistantToolChoiceOptionParamOfAssistantToolChoice(type_ AssistantToolChoiceType) AssistantToolChoiceOptionUnionParam {
407 var variant AssistantToolChoiceParam
408 variant.Type = type_
409 return AssistantToolChoiceOptionUnionParam{OfAssistantToolChoice: &variant}
410}
411
412// Only one field can be non-zero.
413//
414// Use [param.IsOmitted] to confirm if a field is set.
415type AssistantToolChoiceOptionUnionParam struct {
416 // Check if union is this variant with !param.IsOmitted(union.OfAuto)
417 OfAuto param.Opt[string] `json:",omitzero,inline"`
418 OfAssistantToolChoice *AssistantToolChoiceParam `json:",omitzero,inline"`
419 paramUnion
420}
421
422// IsPresent returns true if the field's value is not omitted and not the JSON
423// "null". To check if this field is omitted, use [param.IsOmitted].
424func (u AssistantToolChoiceOptionUnionParam) IsPresent() bool {
425 return !param.IsOmitted(u) && !u.IsNull()
426}
427func (u AssistantToolChoiceOptionUnionParam) MarshalJSON() ([]byte, error) {
428 return param.MarshalUnion[AssistantToolChoiceOptionUnionParam](u.OfAuto, u.OfAssistantToolChoice)
429}
430
431func (u *AssistantToolChoiceOptionUnionParam) asAny() any {
432 if !param.IsOmitted(u.OfAuto) {
433 return &u.OfAuto
434 } else if !param.IsOmitted(u.OfAssistantToolChoice) {
435 return u.OfAssistantToolChoice
436 }
437 return nil
438}
439
440// Returns a pointer to the underlying variant's property, if present.
441func (u AssistantToolChoiceOptionUnionParam) GetType() *string {
442 if vt := u.OfAssistantToolChoice; vt != nil {
443 return (*string)(&vt.Type)
444 }
445 return nil
446}
447
448// Returns a pointer to the underlying variant's property, if present.
449func (u AssistantToolChoiceOptionUnionParam) GetFunction() *AssistantToolChoiceFunctionParam {
450 if vt := u.OfAssistantToolChoice; vt != nil {
451 return &vt.Function
452 }
453 return nil
454}
455
456// Represents a thread that contains
457// [messages](https://platform.openai.com/docs/api-reference/messages).
458type Thread struct {
459 // The identifier, which can be referenced in API endpoints.
460 ID string `json:"id,required"`
461 // The Unix timestamp (in seconds) for when the thread was created.
462 CreatedAt int64 `json:"created_at,required"`
463 // Set of 16 key-value pairs that can be attached to an object. This can be useful
464 // for storing additional information about the object in a structured format, and
465 // querying for objects via API or the dashboard.
466 //
467 // Keys are strings with a maximum length of 64 characters. Values are strings with
468 // a maximum length of 512 characters.
469 Metadata shared.Metadata `json:"metadata,required"`
470 // The object type, which is always `thread`.
471 Object constant.Thread `json:"object,required"`
472 // A set of resources that are made available to the assistant's tools in this
473 // thread. The resources are specific to the type of tool. For example, the
474 // `code_interpreter` tool requires a list of file IDs, while the `file_search`
475 // tool requires a list of vector store IDs.
476 ToolResources ThreadToolResources `json:"tool_resources,required"`
477 // Metadata for the response, check the presence of optional fields with the
478 // [resp.Field.IsPresent] method.
479 JSON struct {
480 ID resp.Field
481 CreatedAt resp.Field
482 Metadata resp.Field
483 Object resp.Field
484 ToolResources resp.Field
485 ExtraFields map[string]resp.Field
486 raw string
487 } `json:"-"`
488}
489
490// Returns the unmodified JSON received from the API
491func (r Thread) RawJSON() string { return r.JSON.raw }
492func (r *Thread) UnmarshalJSON(data []byte) error {
493 return apijson.UnmarshalRoot(data, r)
494}
495
496// A set of resources that are made available to the assistant's tools in this
497// thread. The resources are specific to the type of tool. For example, the
498// `code_interpreter` tool requires a list of file IDs, while the `file_search`
499// tool requires a list of vector store IDs.
500type ThreadToolResources struct {
501 CodeInterpreter ThreadToolResourcesCodeInterpreter `json:"code_interpreter"`
502 FileSearch ThreadToolResourcesFileSearch `json:"file_search"`
503 // Metadata for the response, check the presence of optional fields with the
504 // [resp.Field.IsPresent] method.
505 JSON struct {
506 CodeInterpreter resp.Field
507 FileSearch resp.Field
508 ExtraFields map[string]resp.Field
509 raw string
510 } `json:"-"`
511}
512
513// Returns the unmodified JSON received from the API
514func (r ThreadToolResources) RawJSON() string { return r.JSON.raw }
515func (r *ThreadToolResources) UnmarshalJSON(data []byte) error {
516 return apijson.UnmarshalRoot(data, r)
517}
518
519type ThreadToolResourcesCodeInterpreter struct {
520 // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
521 // available to the `code_interpreter` tool. There can be a maximum of 20 files
522 // associated with the tool.
523 FileIDs []string `json:"file_ids"`
524 // Metadata for the response, check the presence of optional fields with the
525 // [resp.Field.IsPresent] method.
526 JSON struct {
527 FileIDs resp.Field
528 ExtraFields map[string]resp.Field
529 raw string
530 } `json:"-"`
531}
532
533// Returns the unmodified JSON received from the API
534func (r ThreadToolResourcesCodeInterpreter) RawJSON() string { return r.JSON.raw }
535func (r *ThreadToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
536 return apijson.UnmarshalRoot(data, r)
537}
538
539type ThreadToolResourcesFileSearch struct {
540 // The
541 // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
542 // attached to this thread. There can be a maximum of 1 vector store attached to
543 // the thread.
544 VectorStoreIDs []string `json:"vector_store_ids"`
545 // Metadata for the response, check the presence of optional fields with the
546 // [resp.Field.IsPresent] method.
547 JSON struct {
548 VectorStoreIDs resp.Field
549 ExtraFields map[string]resp.Field
550 raw string
551 } `json:"-"`
552}
553
554// Returns the unmodified JSON received from the API
555func (r ThreadToolResourcesFileSearch) RawJSON() string { return r.JSON.raw }
556func (r *ThreadToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
557 return apijson.UnmarshalRoot(data, r)
558}
559
560type ThreadDeleted struct {
561 ID string `json:"id,required"`
562 Deleted bool `json:"deleted,required"`
563 Object constant.ThreadDeleted `json:"object,required"`
564 // Metadata for the response, check the presence of optional fields with the
565 // [resp.Field.IsPresent] method.
566 JSON struct {
567 ID resp.Field
568 Deleted resp.Field
569 Object resp.Field
570 ExtraFields map[string]resp.Field
571 raw string
572 } `json:"-"`
573}
574
575// Returns the unmodified JSON received from the API
576func (r ThreadDeleted) RawJSON() string { return r.JSON.raw }
577func (r *ThreadDeleted) UnmarshalJSON(data []byte) error {
578 return apijson.UnmarshalRoot(data, r)
579}
580
581type BetaThreadNewParams struct {
582 // Set of 16 key-value pairs that can be attached to an object. This can be useful
583 // for storing additional information about the object in a structured format, and
584 // querying for objects via API or the dashboard.
585 //
586 // Keys are strings with a maximum length of 64 characters. Values are strings with
587 // a maximum length of 512 characters.
588 Metadata shared.MetadataParam `json:"metadata,omitzero"`
589 // A set of resources that are made available to the assistant's tools in this
590 // thread. The resources are specific to the type of tool. For example, the
591 // `code_interpreter` tool requires a list of file IDs, while the `file_search`
592 // tool requires a list of vector store IDs.
593 ToolResources BetaThreadNewParamsToolResources `json:"tool_resources,omitzero"`
594 // A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
595 // start the thread with.
596 Messages []BetaThreadNewParamsMessage `json:"messages,omitzero"`
597 paramObj
598}
599
600// IsPresent returns true if the field's value is not omitted and not the JSON
601// "null". To check if this field is omitted, use [param.IsOmitted].
602func (f BetaThreadNewParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
603
604func (r BetaThreadNewParams) MarshalJSON() (data []byte, err error) {
605 type shadow BetaThreadNewParams
606 return param.MarshalObject(r, (*shadow)(&r))
607}
608
609// The properties Content, Role are required.
610type BetaThreadNewParamsMessage struct {
611 // The text contents of the message.
612 Content BetaThreadNewParamsMessageContentUnion `json:"content,omitzero,required"`
613 // The role of the entity that is creating the message. Allowed values include:
614 //
615 // - `user`: Indicates the message is sent by an actual user and should be used in
616 // most cases to represent user-generated messages.
617 // - `assistant`: Indicates the message is generated by the assistant. Use this
618 // value to insert messages from the assistant into the conversation.
619 //
620 // Any of "user", "assistant".
621 Role string `json:"role,omitzero,required"`
622 // A list of files attached to the message, and the tools they should be added to.
623 Attachments []BetaThreadNewParamsMessageAttachment `json:"attachments,omitzero"`
624 // Set of 16 key-value pairs that can be attached to an object. This can be useful
625 // for storing additional information about the object in a structured format, and
626 // querying for objects via API or the dashboard.
627 //
628 // Keys are strings with a maximum length of 64 characters. Values are strings with
629 // a maximum length of 512 characters.
630 Metadata shared.MetadataParam `json:"metadata,omitzero"`
631 paramObj
632}
633
634// IsPresent returns true if the field's value is not omitted and not the JSON
635// "null". To check if this field is omitted, use [param.IsOmitted].
636func (f BetaThreadNewParamsMessage) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
637func (r BetaThreadNewParamsMessage) MarshalJSON() (data []byte, err error) {
638 type shadow BetaThreadNewParamsMessage
639 return param.MarshalObject(r, (*shadow)(&r))
640}
641
642func init() {
643 apijson.RegisterFieldValidator[BetaThreadNewParamsMessage](
644 "Role", false, "user", "assistant",
645 )
646}
647
648// Only one field can be non-zero.
649//
650// Use [param.IsOmitted] to confirm if a field is set.
651type BetaThreadNewParamsMessageContentUnion struct {
652 OfString param.Opt[string] `json:",omitzero,inline"`
653 OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
654 paramUnion
655}
656
657// IsPresent returns true if the field's value is not omitted and not the JSON
658// "null". To check if this field is omitted, use [param.IsOmitted].
659func (u BetaThreadNewParamsMessageContentUnion) IsPresent() bool {
660 return !param.IsOmitted(u) && !u.IsNull()
661}
662func (u BetaThreadNewParamsMessageContentUnion) MarshalJSON() ([]byte, error) {
663 return param.MarshalUnion[BetaThreadNewParamsMessageContentUnion](u.OfString, u.OfArrayOfContentParts)
664}
665
666func (u *BetaThreadNewParamsMessageContentUnion) asAny() any {
667 if !param.IsOmitted(u.OfString) {
668 return &u.OfString.Value
669 } else if !param.IsOmitted(u.OfArrayOfContentParts) {
670 return &u.OfArrayOfContentParts
671 }
672 return nil
673}
674
675type BetaThreadNewParamsMessageAttachment struct {
676 // The ID of the file to attach to the message.
677 FileID param.Opt[string] `json:"file_id,omitzero"`
678 // The tools to add this file to.
679 Tools []BetaThreadNewParamsMessageAttachmentToolUnion `json:"tools,omitzero"`
680 paramObj
681}
682
683// IsPresent returns true if the field's value is not omitted and not the JSON
684// "null". To check if this field is omitted, use [param.IsOmitted].
685func (f BetaThreadNewParamsMessageAttachment) IsPresent() bool {
686 return !param.IsOmitted(f) && !f.IsNull()
687}
688func (r BetaThreadNewParamsMessageAttachment) MarshalJSON() (data []byte, err error) {
689 type shadow BetaThreadNewParamsMessageAttachment
690 return param.MarshalObject(r, (*shadow)(&r))
691}
692
693// Only one field can be non-zero.
694//
695// Use [param.IsOmitted] to confirm if a field is set.
696type BetaThreadNewParamsMessageAttachmentToolUnion struct {
697 OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
698 OfFileSearch *BetaThreadNewParamsMessageAttachmentToolFileSearch `json:",omitzero,inline"`
699 paramUnion
700}
701
702// IsPresent returns true if the field's value is not omitted and not the JSON
703// "null". To check if this field is omitted, use [param.IsOmitted].
704func (u BetaThreadNewParamsMessageAttachmentToolUnion) IsPresent() bool {
705 return !param.IsOmitted(u) && !u.IsNull()
706}
707func (u BetaThreadNewParamsMessageAttachmentToolUnion) MarshalJSON() ([]byte, error) {
708 return param.MarshalUnion[BetaThreadNewParamsMessageAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
709}
710
711func (u *BetaThreadNewParamsMessageAttachmentToolUnion) asAny() any {
712 if !param.IsOmitted(u.OfCodeInterpreter) {
713 return u.OfCodeInterpreter
714 } else if !param.IsOmitted(u.OfFileSearch) {
715 return u.OfFileSearch
716 }
717 return nil
718}
719
720// Returns a pointer to the underlying variant's property, if present.
721func (u BetaThreadNewParamsMessageAttachmentToolUnion) GetType() *string {
722 if vt := u.OfCodeInterpreter; vt != nil {
723 return (*string)(&vt.Type)
724 } else if vt := u.OfFileSearch; vt != nil {
725 return (*string)(&vt.Type)
726 }
727 return nil
728}
729
730func init() {
731 apijson.RegisterUnion[BetaThreadNewParamsMessageAttachmentToolUnion](
732 "type",
733 apijson.UnionVariant{
734 TypeFilter: gjson.JSON,
735 Type: reflect.TypeOf(CodeInterpreterToolParam{}),
736 DiscriminatorValue: "code_interpreter",
737 },
738 apijson.UnionVariant{
739 TypeFilter: gjson.JSON,
740 Type: reflect.TypeOf(BetaThreadNewParamsMessageAttachmentToolFileSearch{}),
741 DiscriminatorValue: "file_search",
742 },
743 )
744}
745
746// The property Type is required.
747type BetaThreadNewParamsMessageAttachmentToolFileSearch struct {
748 // The type of tool being defined: `file_search`
749 //
750 // This field can be elided, and will marshal its zero value as "file_search".
751 Type constant.FileSearch `json:"type,required"`
752 paramObj
753}
754
755// IsPresent returns true if the field's value is not omitted and not the JSON
756// "null". To check if this field is omitted, use [param.IsOmitted].
757func (f BetaThreadNewParamsMessageAttachmentToolFileSearch) IsPresent() bool {
758 return !param.IsOmitted(f) && !f.IsNull()
759}
760func (r BetaThreadNewParamsMessageAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
761 type shadow BetaThreadNewParamsMessageAttachmentToolFileSearch
762 return param.MarshalObject(r, (*shadow)(&r))
763}
764
765// A set of resources that are made available to the assistant's tools in this
766// thread. The resources are specific to the type of tool. For example, the
767// `code_interpreter` tool requires a list of file IDs, while the `file_search`
768// tool requires a list of vector store IDs.
769type BetaThreadNewParamsToolResources struct {
770 CodeInterpreter BetaThreadNewParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
771 FileSearch BetaThreadNewParamsToolResourcesFileSearch `json:"file_search,omitzero"`
772 paramObj
773}
774
775// IsPresent returns true if the field's value is not omitted and not the JSON
776// "null". To check if this field is omitted, use [param.IsOmitted].
777func (f BetaThreadNewParamsToolResources) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
778func (r BetaThreadNewParamsToolResources) MarshalJSON() (data []byte, err error) {
779 type shadow BetaThreadNewParamsToolResources
780 return param.MarshalObject(r, (*shadow)(&r))
781}
782
783type BetaThreadNewParamsToolResourcesCodeInterpreter struct {
784 // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
785 // available to the `code_interpreter` tool. There can be a maximum of 20 files
786 // associated with the tool.
787 FileIDs []string `json:"file_ids,omitzero"`
788 paramObj
789}
790
791// IsPresent returns true if the field's value is not omitted and not the JSON
792// "null". To check if this field is omitted, use [param.IsOmitted].
793func (f BetaThreadNewParamsToolResourcesCodeInterpreter) IsPresent() bool {
794 return !param.IsOmitted(f) && !f.IsNull()
795}
796func (r BetaThreadNewParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
797 type shadow BetaThreadNewParamsToolResourcesCodeInterpreter
798 return param.MarshalObject(r, (*shadow)(&r))
799}
800
801type BetaThreadNewParamsToolResourcesFileSearch struct {
802 // The
803 // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
804 // attached to this thread. There can be a maximum of 1 vector store attached to
805 // the thread.
806 VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
807 // A helper to create a
808 // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
809 // with file_ids and attach it to this thread. There can be a maximum of 1 vector
810 // store attached to the thread.
811 VectorStores []BetaThreadNewParamsToolResourcesFileSearchVectorStore `json:"vector_stores,omitzero"`
812 paramObj
813}
814
815// IsPresent returns true if the field's value is not omitted and not the JSON
816// "null". To check if this field is omitted, use [param.IsOmitted].
817func (f BetaThreadNewParamsToolResourcesFileSearch) IsPresent() bool {
818 return !param.IsOmitted(f) && !f.IsNull()
819}
820func (r BetaThreadNewParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
821 type shadow BetaThreadNewParamsToolResourcesFileSearch
822 return param.MarshalObject(r, (*shadow)(&r))
823}
824
825type BetaThreadNewParamsToolResourcesFileSearchVectorStore struct {
826 // Set of 16 key-value pairs that can be attached to an object. This can be useful
827 // for storing additional information about the object in a structured format, and
828 // querying for objects via API or the dashboard.
829 //
830 // Keys are strings with a maximum length of 64 characters. Values are strings with
831 // a maximum length of 512 characters.
832 Metadata shared.MetadataParam `json:"metadata,omitzero"`
833 // The chunking strategy used to chunk the file(s). If not set, will use the `auto`
834 // strategy.
835 ChunkingStrategy BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion `json:"chunking_strategy,omitzero"`
836 // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
837 // add to the vector store. There can be a maximum of 10000 files in a vector
838 // store.
839 FileIDs []string `json:"file_ids,omitzero"`
840 paramObj
841}
842
843// IsPresent returns true if the field's value is not omitted and not the JSON
844// "null". To check if this field is omitted, use [param.IsOmitted].
845func (f BetaThreadNewParamsToolResourcesFileSearchVectorStore) IsPresent() bool {
846 return !param.IsOmitted(f) && !f.IsNull()
847}
848func (r BetaThreadNewParamsToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
849 type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStore
850 return param.MarshalObject(r, (*shadow)(&r))
851}
852
853// Only one field can be non-zero.
854//
855// Use [param.IsOmitted] to confirm if a field is set.
856type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion struct {
857 OfAuto *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto `json:",omitzero,inline"`
858 OfStatic *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic `json:",omitzero,inline"`
859 paramUnion
860}
861
862// IsPresent returns true if the field's value is not omitted and not the JSON
863// "null". To check if this field is omitted, use [param.IsOmitted].
864func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) IsPresent() bool {
865 return !param.IsOmitted(u) && !u.IsNull()
866}
867func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) MarshalJSON() ([]byte, error) {
868 return param.MarshalUnion[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](u.OfAuto, u.OfStatic)
869}
870
871func (u *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) asAny() any {
872 if !param.IsOmitted(u.OfAuto) {
873 return u.OfAuto
874 } else if !param.IsOmitted(u.OfStatic) {
875 return u.OfStatic
876 }
877 return nil
878}
879
880// Returns a pointer to the underlying variant's property, if present.
881func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetStatic() *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic {
882 if vt := u.OfStatic; vt != nil {
883 return &vt.Static
884 }
885 return nil
886}
887
888// Returns a pointer to the underlying variant's property, if present.
889func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetType() *string {
890 if vt := u.OfAuto; vt != nil {
891 return (*string)(&vt.Type)
892 } else if vt := u.OfStatic; vt != nil {
893 return (*string)(&vt.Type)
894 }
895 return nil
896}
897
898func init() {
899 apijson.RegisterUnion[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](
900 "type",
901 apijson.UnionVariant{
902 TypeFilter: gjson.JSON,
903 Type: reflect.TypeOf(BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto{}),
904 DiscriminatorValue: "auto",
905 },
906 apijson.UnionVariant{
907 TypeFilter: gjson.JSON,
908 Type: reflect.TypeOf(BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic{}),
909 DiscriminatorValue: "static",
910 },
911 )
912}
913
914// The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
915// `800` and `chunk_overlap_tokens` of `400`.
916//
917// The property Type is required.
918type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto struct {
919 // Always `auto`.
920 //
921 // This field can be elided, and will marshal its zero value as "auto".
922 Type constant.Auto `json:"type,required"`
923 paramObj
924}
925
926// IsPresent returns true if the field's value is not omitted and not the JSON
927// "null". To check if this field is omitted, use [param.IsOmitted].
928func (f BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) IsPresent() bool {
929 return !param.IsOmitted(f) && !f.IsNull()
930}
931func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) MarshalJSON() (data []byte, err error) {
932 type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto
933 return param.MarshalObject(r, (*shadow)(&r))
934}
935
936// The properties Static, Type are required.
937type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic struct {
938 Static BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic `json:"static,omitzero,required"`
939 // Always `static`.
940 //
941 // This field can be elided, and will marshal its zero value as "static".
942 Type constant.Static `json:"type,required"`
943 paramObj
944}
945
946// IsPresent returns true if the field's value is not omitted and not the JSON
947// "null". To check if this field is omitted, use [param.IsOmitted].
948func (f BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) IsPresent() bool {
949 return !param.IsOmitted(f) && !f.IsNull()
950}
951func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) MarshalJSON() (data []byte, err error) {
952 type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic
953 return param.MarshalObject(r, (*shadow)(&r))
954}
955
956// The properties ChunkOverlapTokens, MaxChunkSizeTokens are required.
957type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic struct {
958 // The number of tokens that overlap between chunks. The default value is `400`.
959 //
960 // Note that the overlap must not exceed half of `max_chunk_size_tokens`.
961 ChunkOverlapTokens int64 `json:"chunk_overlap_tokens,required"`
962 // The maximum number of tokens in each chunk. The default value is `800`. The
963 // minimum value is `100` and the maximum value is `4096`.
964 MaxChunkSizeTokens int64 `json:"max_chunk_size_tokens,required"`
965 paramObj
966}
967
968// IsPresent returns true if the field's value is not omitted and not the JSON
969// "null". To check if this field is omitted, use [param.IsOmitted].
970func (f BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) IsPresent() bool {
971 return !param.IsOmitted(f) && !f.IsNull()
972}
973func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) MarshalJSON() (data []byte, err error) {
974 type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic
975 return param.MarshalObject(r, (*shadow)(&r))
976}
977
978type BetaThreadUpdateParams struct {
979 // Set of 16 key-value pairs that can be attached to an object. This can be useful
980 // for storing additional information about the object in a structured format, and
981 // querying for objects via API or the dashboard.
982 //
983 // Keys are strings with a maximum length of 64 characters. Values are strings with
984 // a maximum length of 512 characters.
985 Metadata shared.MetadataParam `json:"metadata,omitzero"`
986 // A set of resources that are made available to the assistant's tools in this
987 // thread. The resources are specific to the type of tool. For example, the
988 // `code_interpreter` tool requires a list of file IDs, while the `file_search`
989 // tool requires a list of vector store IDs.
990 ToolResources BetaThreadUpdateParamsToolResources `json:"tool_resources,omitzero"`
991 paramObj
992}
993
994// IsPresent returns true if the field's value is not omitted and not the JSON
995// "null". To check if this field is omitted, use [param.IsOmitted].
996func (f BetaThreadUpdateParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
997
998func (r BetaThreadUpdateParams) MarshalJSON() (data []byte, err error) {
999 type shadow BetaThreadUpdateParams
1000 return param.MarshalObject(r, (*shadow)(&r))
1001}
1002
1003// A set of resources that are made available to the assistant's tools in this
1004// thread. The resources are specific to the type of tool. For example, the
1005// `code_interpreter` tool requires a list of file IDs, while the `file_search`
1006// tool requires a list of vector store IDs.
1007type BetaThreadUpdateParamsToolResources struct {
1008 CodeInterpreter BetaThreadUpdateParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
1009 FileSearch BetaThreadUpdateParamsToolResourcesFileSearch `json:"file_search,omitzero"`
1010 paramObj
1011}
1012
1013// IsPresent returns true if the field's value is not omitted and not the JSON
1014// "null". To check if this field is omitted, use [param.IsOmitted].
1015func (f BetaThreadUpdateParamsToolResources) IsPresent() bool {
1016 return !param.IsOmitted(f) && !f.IsNull()
1017}
1018func (r BetaThreadUpdateParamsToolResources) MarshalJSON() (data []byte, err error) {
1019 type shadow BetaThreadUpdateParamsToolResources
1020 return param.MarshalObject(r, (*shadow)(&r))
1021}
1022
1023type BetaThreadUpdateParamsToolResourcesCodeInterpreter struct {
1024 // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
1025 // available to the `code_interpreter` tool. There can be a maximum of 20 files
1026 // associated with the tool.
1027 FileIDs []string `json:"file_ids,omitzero"`
1028 paramObj
1029}
1030
1031// IsPresent returns true if the field's value is not omitted and not the JSON
1032// "null". To check if this field is omitted, use [param.IsOmitted].
1033func (f BetaThreadUpdateParamsToolResourcesCodeInterpreter) IsPresent() bool {
1034 return !param.IsOmitted(f) && !f.IsNull()
1035}
1036func (r BetaThreadUpdateParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
1037 type shadow BetaThreadUpdateParamsToolResourcesCodeInterpreter
1038 return param.MarshalObject(r, (*shadow)(&r))
1039}
1040
1041type BetaThreadUpdateParamsToolResourcesFileSearch struct {
1042 // The
1043 // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
1044 // attached to this thread. There can be a maximum of 1 vector store attached to
1045 // the thread.
1046 VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
1047 paramObj
1048}
1049
1050// IsPresent returns true if the field's value is not omitted and not the JSON
1051// "null". To check if this field is omitted, use [param.IsOmitted].
1052func (f BetaThreadUpdateParamsToolResourcesFileSearch) IsPresent() bool {
1053 return !param.IsOmitted(f) && !f.IsNull()
1054}
1055func (r BetaThreadUpdateParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
1056 type shadow BetaThreadUpdateParamsToolResourcesFileSearch
1057 return param.MarshalObject(r, (*shadow)(&r))
1058}
1059
1060type BetaThreadNewAndRunParams struct {
1061 // The ID of the
1062 // [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
1063 // execute this run.
1064 AssistantID string `json:"assistant_id,required"`
1065 // Override the default system message of the assistant. This is useful for
1066 // modifying the behavior on a per-run basis.
1067 Instructions param.Opt[string] `json:"instructions,omitzero"`
1068 // The maximum number of completion tokens that may be used over the course of the
1069 // run. The run will make a best effort to use only the number of completion tokens
1070 // specified, across multiple turns of the run. If the run exceeds the number of
1071 // completion tokens specified, the run will end with status `incomplete`. See
1072 // `incomplete_details` for more info.
1073 MaxCompletionTokens param.Opt[int64] `json:"max_completion_tokens,omitzero"`
1074 // The maximum number of prompt tokens that may be used over the course of the run.
1075 // The run will make a best effort to use only the number of prompt tokens
1076 // specified, across multiple turns of the run. If the run exceeds the number of
1077 // prompt tokens specified, the run will end with status `incomplete`. See
1078 // `incomplete_details` for more info.
1079 MaxPromptTokens param.Opt[int64] `json:"max_prompt_tokens,omitzero"`
1080 // What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
1081 // make the output more random, while lower values like 0.2 will make it more
1082 // focused and deterministic.
1083 Temperature param.Opt[float64] `json:"temperature,omitzero"`
1084 // An alternative to sampling with temperature, called nucleus sampling, where the
1085 // model considers the results of the tokens with top_p probability mass. So 0.1
1086 // means only the tokens comprising the top 10% probability mass are considered.
1087 //
1088 // We generally recommend altering this or temperature but not both.
1089 TopP param.Opt[float64] `json:"top_p,omitzero"`
1090 // Whether to enable
1091 // [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
1092 // during tool use.
1093 ParallelToolCalls param.Opt[bool] `json:"parallel_tool_calls,omitzero"`
1094 // Set of 16 key-value pairs that can be attached to an object. This can be useful
1095 // for storing additional information about the object in a structured format, and
1096 // querying for objects via API or the dashboard.
1097 //
1098 // Keys are strings with a maximum length of 64 characters. Values are strings with
1099 // a maximum length of 512 characters.
1100 Metadata shared.MetadataParam `json:"metadata,omitzero"`
1101 // The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
1102 // be used to execute this run. If a value is provided here, it will override the
1103 // model associated with the assistant. If not, the model associated with the
1104 // assistant will be used.
1105 Model shared.ChatModel `json:"model,omitzero"`
1106 // A set of resources that are used by the assistant's tools. The resources are
1107 // specific to the type of tool. For example, the `code_interpreter` tool requires
1108 // a list of file IDs, while the `file_search` tool requires a list of vector store
1109 // IDs.
1110 ToolResources BetaThreadNewAndRunParamsToolResources `json:"tool_resources,omitzero"`
1111 // Override the tools the assistant can use for this run. This is useful for
1112 // modifying the behavior on a per-run basis.
1113 Tools []BetaThreadNewAndRunParamsToolUnion `json:"tools,omitzero"`
1114 // Controls for how a thread will be truncated prior to the run. Use this to
1115 // control the intial context window of the run.
1116 TruncationStrategy BetaThreadNewAndRunParamsTruncationStrategy `json:"truncation_strategy,omitzero"`
1117 // Specifies the format that the model must output. Compatible with
1118 // [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
1119 // [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
1120 // and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
1121 //
1122 // Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
1123 // Outputs which ensures the model will match your supplied JSON schema. Learn more
1124 // in the
1125 // [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
1126 //
1127 // Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
1128 // message the model generates is valid JSON.
1129 //
1130 // **Important:** when using JSON mode, you **must** also instruct the model to
1131 // produce JSON yourself via a system or user message. Without this, the model may
1132 // generate an unending stream of whitespace until the generation reaches the token
1133 // limit, resulting in a long-running and seemingly "stuck" request. Also note that
1134 // the message content may be partially cut off if `finish_reason="length"`, which
1135 // indicates the generation exceeded `max_tokens` or the conversation exceeded the
1136 // max context length.
1137 ResponseFormat AssistantResponseFormatOptionUnionParam `json:"response_format,omitzero"`
1138 // Options to create a new thread. If no thread is provided when running a request,
1139 // an empty thread will be created.
1140 Thread BetaThreadNewAndRunParamsThread `json:"thread,omitzero"`
1141 // Controls which (if any) tool is called by the model. `none` means the model will
1142 // not call any tools and instead generates a message. `auto` is the default value
1143 // and means the model can pick between generating a message or calling one or more
1144 // tools. `required` means the model must call one or more tools before responding
1145 // to the user. Specifying a particular tool like `{"type": "file_search"}` or
1146 // `{"type": "function", "function": {"name": "my_function"}}` forces the model to
1147 // call that tool.
1148 ToolChoice AssistantToolChoiceOptionUnionParam `json:"tool_choice,omitzero"`
1149 paramObj
1150}
1151
1152// IsPresent returns true if the field's value is not omitted and not the JSON
1153// "null". To check if this field is omitted, use [param.IsOmitted].
1154func (f BetaThreadNewAndRunParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
1155
1156func (r BetaThreadNewAndRunParams) MarshalJSON() (data []byte, err error) {
1157 type shadow BetaThreadNewAndRunParams
1158 return param.MarshalObject(r, (*shadow)(&r))
1159}
1160
1161// Options to create a new thread. If no thread is provided when running a request,
1162// an empty thread will be created.
1163type BetaThreadNewAndRunParamsThread struct {
1164 // Set of 16 key-value pairs that can be attached to an object. This can be useful
1165 // for storing additional information about the object in a structured format, and
1166 // querying for objects via API or the dashboard.
1167 //
1168 // Keys are strings with a maximum length of 64 characters. Values are strings with
1169 // a maximum length of 512 characters.
1170 Metadata shared.MetadataParam `json:"metadata,omitzero"`
1171 // A set of resources that are made available to the assistant's tools in this
1172 // thread. The resources are specific to the type of tool. For example, the
1173 // `code_interpreter` tool requires a list of file IDs, while the `file_search`
1174 // tool requires a list of vector store IDs.
1175 ToolResources BetaThreadNewAndRunParamsThreadToolResources `json:"tool_resources,omitzero"`
1176 // A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
1177 // start the thread with.
1178 Messages []BetaThreadNewAndRunParamsThreadMessage `json:"messages,omitzero"`
1179 paramObj
1180}
1181
1182// IsPresent returns true if the field's value is not omitted and not the JSON
1183// "null". To check if this field is omitted, use [param.IsOmitted].
1184func (f BetaThreadNewAndRunParamsThread) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
1185func (r BetaThreadNewAndRunParamsThread) MarshalJSON() (data []byte, err error) {
1186 type shadow BetaThreadNewAndRunParamsThread
1187 return param.MarshalObject(r, (*shadow)(&r))
1188}
1189
1190// The properties Content, Role are required.
1191type BetaThreadNewAndRunParamsThreadMessage struct {
1192 // The text contents of the message.
1193 Content BetaThreadNewAndRunParamsThreadMessageContentUnion `json:"content,omitzero,required"`
1194 // The role of the entity that is creating the message. Allowed values include:
1195 //
1196 // - `user`: Indicates the message is sent by an actual user and should be used in
1197 // most cases to represent user-generated messages.
1198 // - `assistant`: Indicates the message is generated by the assistant. Use this
1199 // value to insert messages from the assistant into the conversation.
1200 //
1201 // Any of "user", "assistant".
1202 Role string `json:"role,omitzero,required"`
1203 // A list of files attached to the message, and the tools they should be added to.
1204 Attachments []BetaThreadNewAndRunParamsThreadMessageAttachment `json:"attachments,omitzero"`
1205 // Set of 16 key-value pairs that can be attached to an object. This can be useful
1206 // for storing additional information about the object in a structured format, and
1207 // querying for objects via API or the dashboard.
1208 //
1209 // Keys are strings with a maximum length of 64 characters. Values are strings with
1210 // a maximum length of 512 characters.
1211 Metadata shared.MetadataParam `json:"metadata,omitzero"`
1212 paramObj
1213}
1214
1215// IsPresent returns true if the field's value is not omitted and not the JSON
1216// "null". To check if this field is omitted, use [param.IsOmitted].
1217func (f BetaThreadNewAndRunParamsThreadMessage) IsPresent() bool {
1218 return !param.IsOmitted(f) && !f.IsNull()
1219}
1220func (r BetaThreadNewAndRunParamsThreadMessage) MarshalJSON() (data []byte, err error) {
1221 type shadow BetaThreadNewAndRunParamsThreadMessage
1222 return param.MarshalObject(r, (*shadow)(&r))
1223}
1224
1225func init() {
1226 apijson.RegisterFieldValidator[BetaThreadNewAndRunParamsThreadMessage](
1227 "Role", false, "user", "assistant",
1228 )
1229}
1230
1231// Only one field can be non-zero.
1232//
1233// Use [param.IsOmitted] to confirm if a field is set.
1234type BetaThreadNewAndRunParamsThreadMessageContentUnion struct {
1235 OfString param.Opt[string] `json:",omitzero,inline"`
1236 OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
1237 paramUnion
1238}
1239
1240// IsPresent returns true if the field's value is not omitted and not the JSON
1241// "null". To check if this field is omitted, use [param.IsOmitted].
1242func (u BetaThreadNewAndRunParamsThreadMessageContentUnion) IsPresent() bool {
1243 return !param.IsOmitted(u) && !u.IsNull()
1244}
1245func (u BetaThreadNewAndRunParamsThreadMessageContentUnion) MarshalJSON() ([]byte, error) {
1246 return param.MarshalUnion[BetaThreadNewAndRunParamsThreadMessageContentUnion](u.OfString, u.OfArrayOfContentParts)
1247}
1248
1249func (u *BetaThreadNewAndRunParamsThreadMessageContentUnion) asAny() any {
1250 if !param.IsOmitted(u.OfString) {
1251 return &u.OfString.Value
1252 } else if !param.IsOmitted(u.OfArrayOfContentParts) {
1253 return &u.OfArrayOfContentParts
1254 }
1255 return nil
1256}
1257
1258type BetaThreadNewAndRunParamsThreadMessageAttachment struct {
1259 // The ID of the file to attach to the message.
1260 FileID param.Opt[string] `json:"file_id,omitzero"`
1261 // The tools to add this file to.
1262 Tools []BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion `json:"tools,omitzero"`
1263 paramObj
1264}
1265
1266// IsPresent returns true if the field's value is not omitted and not the JSON
1267// "null". To check if this field is omitted, use [param.IsOmitted].
1268func (f BetaThreadNewAndRunParamsThreadMessageAttachment) IsPresent() bool {
1269 return !param.IsOmitted(f) && !f.IsNull()
1270}
1271func (r BetaThreadNewAndRunParamsThreadMessageAttachment) MarshalJSON() (data []byte, err error) {
1272 type shadow BetaThreadNewAndRunParamsThreadMessageAttachment
1273 return param.MarshalObject(r, (*shadow)(&r))
1274}
1275
1276// Only one field can be non-zero.
1277//
1278// Use [param.IsOmitted] to confirm if a field is set.
1279type BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion struct {
1280 OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
1281 OfFileSearch *BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch `json:",omitzero,inline"`
1282 paramUnion
1283}
1284
1285// IsPresent returns true if the field's value is not omitted and not the JSON
1286// "null". To check if this field is omitted, use [param.IsOmitted].
1287func (u BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) IsPresent() bool {
1288 return !param.IsOmitted(u) && !u.IsNull()
1289}
1290func (u BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) MarshalJSON() ([]byte, error) {
1291 return param.MarshalUnion[BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
1292}
1293
1294func (u *BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) asAny() any {
1295 if !param.IsOmitted(u.OfCodeInterpreter) {
1296 return u.OfCodeInterpreter
1297 } else if !param.IsOmitted(u.OfFileSearch) {
1298 return u.OfFileSearch
1299 }
1300 return nil
1301}
1302
1303// Returns a pointer to the underlying variant's property, if present.
1304func (u BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion) GetType() *string {
1305 if vt := u.OfCodeInterpreter; vt != nil {
1306 return (*string)(&vt.Type)
1307 } else if vt := u.OfFileSearch; vt != nil {
1308 return (*string)(&vt.Type)
1309 }
1310 return nil
1311}
1312
1313func init() {
1314 apijson.RegisterUnion[BetaThreadNewAndRunParamsThreadMessageAttachmentToolUnion](
1315 "type",
1316 apijson.UnionVariant{
1317 TypeFilter: gjson.JSON,
1318 Type: reflect.TypeOf(CodeInterpreterToolParam{}),
1319 DiscriminatorValue: "code_interpreter",
1320 },
1321 apijson.UnionVariant{
1322 TypeFilter: gjson.JSON,
1323 Type: reflect.TypeOf(BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch{}),
1324 DiscriminatorValue: "file_search",
1325 },
1326 )
1327}
1328
1329// The property Type is required.
1330type BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch struct {
1331 // The type of tool being defined: `file_search`
1332 //
1333 // This field can be elided, and will marshal its zero value as "file_search".
1334 Type constant.FileSearch `json:"type,required"`
1335 paramObj
1336}
1337
1338// IsPresent returns true if the field's value is not omitted and not the JSON
1339// "null". To check if this field is omitted, use [param.IsOmitted].
1340func (f BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch) IsPresent() bool {
1341 return !param.IsOmitted(f) && !f.IsNull()
1342}
1343func (r BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
1344 type shadow BetaThreadNewAndRunParamsThreadMessageAttachmentToolFileSearch
1345 return param.MarshalObject(r, (*shadow)(&r))
1346}
1347
1348// A set of resources that are made available to the assistant's tools in this
1349// thread. The resources are specific to the type of tool. For example, the
1350// `code_interpreter` tool requires a list of file IDs, while the `file_search`
1351// tool requires a list of vector store IDs.
1352type BetaThreadNewAndRunParamsThreadToolResources struct {
1353 CodeInterpreter BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
1354 FileSearch BetaThreadNewAndRunParamsThreadToolResourcesFileSearch `json:"file_search,omitzero"`
1355 paramObj
1356}
1357
1358// IsPresent returns true if the field's value is not omitted and not the JSON
1359// "null". To check if this field is omitted, use [param.IsOmitted].
1360func (f BetaThreadNewAndRunParamsThreadToolResources) IsPresent() bool {
1361 return !param.IsOmitted(f) && !f.IsNull()
1362}
1363func (r BetaThreadNewAndRunParamsThreadToolResources) MarshalJSON() (data []byte, err error) {
1364 type shadow BetaThreadNewAndRunParamsThreadToolResources
1365 return param.MarshalObject(r, (*shadow)(&r))
1366}
1367
1368type BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter struct {
1369 // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
1370 // available to the `code_interpreter` tool. There can be a maximum of 20 files
1371 // associated with the tool.
1372 FileIDs []string `json:"file_ids,omitzero"`
1373 paramObj
1374}
1375
1376// IsPresent returns true if the field's value is not omitted and not the JSON
1377// "null". To check if this field is omitted, use [param.IsOmitted].
1378func (f BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter) IsPresent() bool {
1379 return !param.IsOmitted(f) && !f.IsNull()
1380}
1381func (r BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
1382 type shadow BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter
1383 return param.MarshalObject(r, (*shadow)(&r))
1384}
1385
1386type BetaThreadNewAndRunParamsThreadToolResourcesFileSearch struct {
1387 // The
1388 // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
1389 // attached to this thread. There can be a maximum of 1 vector store attached to
1390 // the thread.
1391 VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
1392 // A helper to create a
1393 // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
1394 // with file_ids and attach it to this thread. There can be a maximum of 1 vector
1395 // store attached to the thread.
1396 VectorStores []BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore `json:"vector_stores,omitzero"`
1397 paramObj
1398}
1399
1400// IsPresent returns true if the field's value is not omitted and not the JSON
1401// "null". To check if this field is omitted, use [param.IsOmitted].
1402func (f BetaThreadNewAndRunParamsThreadToolResourcesFileSearch) IsPresent() bool {
1403 return !param.IsOmitted(f) && !f.IsNull()
1404}
1405func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
1406 type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearch
1407 return param.MarshalObject(r, (*shadow)(&r))
1408}
1409
1410type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore struct {
1411 // Set of 16 key-value pairs that can be attached to an object. This can be useful
1412 // for storing additional information about the object in a structured format, and
1413 // querying for objects via API or the dashboard.
1414 //
1415 // Keys are strings with a maximum length of 64 characters. Values are strings with
1416 // a maximum length of 512 characters.
1417 Metadata shared.MetadataParam `json:"metadata,omitzero"`
1418 // The chunking strategy used to chunk the file(s). If not set, will use the `auto`
1419 // strategy.
1420 ChunkingStrategy BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion `json:"chunking_strategy,omitzero"`
1421 // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
1422 // add to the vector store. There can be a maximum of 10000 files in a vector
1423 // store.
1424 FileIDs []string `json:"file_ids,omitzero"`
1425 paramObj
1426}
1427
1428// IsPresent returns true if the field's value is not omitted and not the JSON
1429// "null". To check if this field is omitted, use [param.IsOmitted].
1430func (f BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore) IsPresent() bool {
1431 return !param.IsOmitted(f) && !f.IsNull()
1432}
1433func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
1434 type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore
1435 return param.MarshalObject(r, (*shadow)(&r))
1436}
1437
1438// Only one field can be non-zero.
1439//
1440// Use [param.IsOmitted] to confirm if a field is set.
1441type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion struct {
1442 OfAuto *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto `json:",omitzero,inline"`
1443 OfStatic *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic `json:",omitzero,inline"`
1444 paramUnion
1445}
1446
1447// IsPresent returns true if the field's value is not omitted and not the JSON
1448// "null". To check if this field is omitted, use [param.IsOmitted].
1449func (u BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) IsPresent() bool {
1450 return !param.IsOmitted(u) && !u.IsNull()
1451}
1452func (u BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) MarshalJSON() ([]byte, error) {
1453 return param.MarshalUnion[BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion](u.OfAuto, u.OfStatic)
1454}
1455
1456func (u *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) asAny() any {
1457 if !param.IsOmitted(u.OfAuto) {
1458 return u.OfAuto
1459 } else if !param.IsOmitted(u.OfStatic) {
1460 return u.OfStatic
1461 }
1462 return nil
1463}
1464
1465// Returns a pointer to the underlying variant's property, if present.
1466func (u BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetStatic() *BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic {
1467 if vt := u.OfStatic; vt != nil {
1468 return &vt.Static
1469 }
1470 return nil
1471}
1472
1473// Returns a pointer to the underlying variant's property, if present.
1474func (u BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetType() *string {
1475 if vt := u.OfAuto; vt != nil {
1476 return (*string)(&vt.Type)
1477 } else if vt := u.OfStatic; vt != nil {
1478 return (*string)(&vt.Type)
1479 }
1480 return nil
1481}
1482
1483func init() {
1484 apijson.RegisterUnion[BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyUnion](
1485 "type",
1486 apijson.UnionVariant{
1487 TypeFilter: gjson.JSON,
1488 Type: reflect.TypeOf(BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto{}),
1489 DiscriminatorValue: "auto",
1490 },
1491 apijson.UnionVariant{
1492 TypeFilter: gjson.JSON,
1493 Type: reflect.TypeOf(BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic{}),
1494 DiscriminatorValue: "static",
1495 },
1496 )
1497}
1498
1499// The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
1500// `800` and `chunk_overlap_tokens` of `400`.
1501//
1502// The property Type is required.
1503type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto struct {
1504 // Always `auto`.
1505 //
1506 // This field can be elided, and will marshal its zero value as "auto".
1507 Type constant.Auto `json:"type,required"`
1508 paramObj
1509}
1510
1511// IsPresent returns true if the field's value is not omitted and not the JSON
1512// "null". To check if this field is omitted, use [param.IsOmitted].
1513func (f BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto) IsPresent() bool {
1514 return !param.IsOmitted(f) && !f.IsNull()
1515}
1516func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto) MarshalJSON() (data []byte, err error) {
1517 type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyAuto
1518 return param.MarshalObject(r, (*shadow)(&r))
1519}
1520
1521// The properties Static, Type are required.
1522type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic struct {
1523 Static BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic `json:"static,omitzero,required"`
1524 // Always `static`.
1525 //
1526 // This field can be elided, and will marshal its zero value as "static".
1527 Type constant.Static `json:"type,required"`
1528 paramObj
1529}
1530
1531// IsPresent returns true if the field's value is not omitted and not the JSON
1532// "null". To check if this field is omitted, use [param.IsOmitted].
1533func (f BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic) IsPresent() bool {
1534 return !param.IsOmitted(f) && !f.IsNull()
1535}
1536func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic) MarshalJSON() (data []byte, err error) {
1537 type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStatic
1538 return param.MarshalObject(r, (*shadow)(&r))
1539}
1540
1541// The properties ChunkOverlapTokens, MaxChunkSizeTokens are required.
1542type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic struct {
1543 // The number of tokens that overlap between chunks. The default value is `400`.
1544 //
1545 // Note that the overlap must not exceed half of `max_chunk_size_tokens`.
1546 ChunkOverlapTokens int64 `json:"chunk_overlap_tokens,required"`
1547 // The maximum number of tokens in each chunk. The default value is `800`. The
1548 // minimum value is `100` and the maximum value is `4096`.
1549 MaxChunkSizeTokens int64 `json:"max_chunk_size_tokens,required"`
1550 paramObj
1551}
1552
1553// IsPresent returns true if the field's value is not omitted and not the JSON
1554// "null". To check if this field is omitted, use [param.IsOmitted].
1555func (f BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) IsPresent() bool {
1556 return !param.IsOmitted(f) && !f.IsNull()
1557}
1558func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) MarshalJSON() (data []byte, err error) {
1559 type shadow BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic
1560 return param.MarshalObject(r, (*shadow)(&r))
1561}
1562
1563// A set of resources that are used by the assistant's tools. The resources are
1564// specific to the type of tool. For example, the `code_interpreter` tool requires
1565// a list of file IDs, while the `file_search` tool requires a list of vector store
1566// IDs.
1567type BetaThreadNewAndRunParamsToolResources struct {
1568 CodeInterpreter BetaThreadNewAndRunParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
1569 FileSearch BetaThreadNewAndRunParamsToolResourcesFileSearch `json:"file_search,omitzero"`
1570 paramObj
1571}
1572
1573// IsPresent returns true if the field's value is not omitted and not the JSON
1574// "null". To check if this field is omitted, use [param.IsOmitted].
1575func (f BetaThreadNewAndRunParamsToolResources) IsPresent() bool {
1576 return !param.IsOmitted(f) && !f.IsNull()
1577}
1578func (r BetaThreadNewAndRunParamsToolResources) MarshalJSON() (data []byte, err error) {
1579 type shadow BetaThreadNewAndRunParamsToolResources
1580 return param.MarshalObject(r, (*shadow)(&r))
1581}
1582
1583type BetaThreadNewAndRunParamsToolResourcesCodeInterpreter struct {
1584 // A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
1585 // available to the `code_interpreter` tool. There can be a maximum of 20 files
1586 // associated with the tool.
1587 FileIDs []string `json:"file_ids,omitzero"`
1588 paramObj
1589}
1590
1591// IsPresent returns true if the field's value is not omitted and not the JSON
1592// "null". To check if this field is omitted, use [param.IsOmitted].
1593func (f BetaThreadNewAndRunParamsToolResourcesCodeInterpreter) IsPresent() bool {
1594 return !param.IsOmitted(f) && !f.IsNull()
1595}
1596func (r BetaThreadNewAndRunParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
1597 type shadow BetaThreadNewAndRunParamsToolResourcesCodeInterpreter
1598 return param.MarshalObject(r, (*shadow)(&r))
1599}
1600
1601type BetaThreadNewAndRunParamsToolResourcesFileSearch struct {
1602 // The ID of the
1603 // [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
1604 // attached to this assistant. There can be a maximum of 1 vector store attached to
1605 // the assistant.
1606 VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
1607 paramObj
1608}
1609
1610// IsPresent returns true if the field's value is not omitted and not the JSON
1611// "null". To check if this field is omitted, use [param.IsOmitted].
1612func (f BetaThreadNewAndRunParamsToolResourcesFileSearch) IsPresent() bool {
1613 return !param.IsOmitted(f) && !f.IsNull()
1614}
1615func (r BetaThreadNewAndRunParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
1616 type shadow BetaThreadNewAndRunParamsToolResourcesFileSearch
1617 return param.MarshalObject(r, (*shadow)(&r))
1618}
1619
1620// Only one field can be non-zero.
1621//
1622// Use [param.IsOmitted] to confirm if a field is set.
1623type BetaThreadNewAndRunParamsToolUnion struct {
1624 OfCodeInterpreterTool *CodeInterpreterToolParam `json:",omitzero,inline"`
1625 OfFileSearchTool *FileSearchToolParam `json:",omitzero,inline"`
1626 OfFunctionTool *FunctionToolParam `json:",omitzero,inline"`
1627 paramUnion
1628}
1629
1630// IsPresent returns true if the field's value is not omitted and not the JSON
1631// "null". To check if this field is omitted, use [param.IsOmitted].
1632func (u BetaThreadNewAndRunParamsToolUnion) IsPresent() bool {
1633 return !param.IsOmitted(u) && !u.IsNull()
1634}
1635func (u BetaThreadNewAndRunParamsToolUnion) MarshalJSON() ([]byte, error) {
1636 return param.MarshalUnion[BetaThreadNewAndRunParamsToolUnion](u.OfCodeInterpreterTool, u.OfFileSearchTool, u.OfFunctionTool)
1637}
1638
1639func (u *BetaThreadNewAndRunParamsToolUnion) asAny() any {
1640 if !param.IsOmitted(u.OfCodeInterpreterTool) {
1641 return u.OfCodeInterpreterTool
1642 } else if !param.IsOmitted(u.OfFileSearchTool) {
1643 return u.OfFileSearchTool
1644 } else if !param.IsOmitted(u.OfFunctionTool) {
1645 return u.OfFunctionTool
1646 }
1647 return nil
1648}
1649
1650// Returns a pointer to the underlying variant's property, if present.
1651func (u BetaThreadNewAndRunParamsToolUnion) GetFileSearch() *FileSearchToolFileSearchParam {
1652 if vt := u.OfFileSearchTool; vt != nil {
1653 return &vt.FileSearch
1654 }
1655 return nil
1656}
1657
1658// Returns a pointer to the underlying variant's property, if present.
1659func (u BetaThreadNewAndRunParamsToolUnion) GetFunction() *shared.FunctionDefinitionParam {
1660 if vt := u.OfFunctionTool; vt != nil {
1661 return &vt.Function
1662 }
1663 return nil
1664}
1665
1666// Returns a pointer to the underlying variant's property, if present.
1667func (u BetaThreadNewAndRunParamsToolUnion) GetType() *string {
1668 if vt := u.OfCodeInterpreterTool; vt != nil {
1669 return (*string)(&vt.Type)
1670 } else if vt := u.OfFileSearchTool; vt != nil {
1671 return (*string)(&vt.Type)
1672 } else if vt := u.OfFunctionTool; vt != nil {
1673 return (*string)(&vt.Type)
1674 }
1675 return nil
1676}
1677
1678// Controls for how a thread will be truncated prior to the run. Use this to
1679// control the intial context window of the run.
1680//
1681// The property Type is required.
1682type BetaThreadNewAndRunParamsTruncationStrategy struct {
1683 // The truncation strategy to use for the thread. The default is `auto`. If set to
1684 // `last_messages`, the thread will be truncated to the n most recent messages in
1685 // the thread. When set to `auto`, messages in the middle of the thread will be
1686 // dropped to fit the context length of the model, `max_prompt_tokens`.
1687 //
1688 // Any of "auto", "last_messages".
1689 Type string `json:"type,omitzero,required"`
1690 // The number of most recent messages from the thread when constructing the context
1691 // for the run.
1692 LastMessages param.Opt[int64] `json:"last_messages,omitzero"`
1693 paramObj
1694}
1695
1696// IsPresent returns true if the field's value is not omitted and not the JSON
1697// "null". To check if this field is omitted, use [param.IsOmitted].
1698func (f BetaThreadNewAndRunParamsTruncationStrategy) IsPresent() bool {
1699 return !param.IsOmitted(f) && !f.IsNull()
1700}
1701func (r BetaThreadNewAndRunParamsTruncationStrategy) MarshalJSON() (data []byte, err error) {
1702 type shadow BetaThreadNewAndRunParamsTruncationStrategy
1703 return param.MarshalObject(r, (*shadow)(&r))
1704}
1705
1706func init() {
1707 apijson.RegisterFieldValidator[BetaThreadNewAndRunParamsTruncationStrategy](
1708 "Type", false, "auto", "last_messages",
1709 )
1710}