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 "net/url"
12
13 "github.com/openai/openai-go/internal/apijson"
14 "github.com/openai/openai-go/internal/apiquery"
15 "github.com/openai/openai-go/internal/requestconfig"
16 "github.com/openai/openai-go/option"
17 "github.com/openai/openai-go/packages/pagination"
18 "github.com/openai/openai-go/packages/param"
19 "github.com/openai/openai-go/packages/respjson"
20 "github.com/openai/openai-go/shared"
21 "github.com/openai/openai-go/shared/constant"
22)
23
24// BetaThreadMessageService contains methods and other services that help with
25// interacting 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 [NewBetaThreadMessageService] method instead.
30//
31// Deprecated: The Assistants API is deprecated in favor of the Responses API
32type BetaThreadMessageService struct {
33 Options []option.RequestOption
34}
35
36// NewBetaThreadMessageService generates a new service that applies the given
37// options to each request. These options are applied after the parent client's
38// options (if there is one), and before any request-specific options.
39func NewBetaThreadMessageService(opts ...option.RequestOption) (r BetaThreadMessageService) {
40 r = BetaThreadMessageService{}
41 r.Options = opts
42 return
43}
44
45// Create a message.
46//
47// Deprecated: The Assistants API is deprecated in favor of the Responses API
48func (r *BetaThreadMessageService) New(ctx context.Context, threadID string, body BetaThreadMessageNewParams, opts ...option.RequestOption) (res *Message, err error) {
49 opts = append(r.Options[:], opts...)
50 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
51 if threadID == "" {
52 err = errors.New("missing required thread_id parameter")
53 return
54 }
55 path := fmt.Sprintf("threads/%s/messages", threadID)
56 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
57 return
58}
59
60// Retrieve a message.
61//
62// Deprecated: The Assistants API is deprecated in favor of the Responses API
63func (r *BetaThreadMessageService) Get(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *Message, err error) {
64 opts = append(r.Options[:], opts...)
65 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
66 if threadID == "" {
67 err = errors.New("missing required thread_id parameter")
68 return
69 }
70 if messageID == "" {
71 err = errors.New("missing required message_id parameter")
72 return
73 }
74 path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
75 err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
76 return
77}
78
79// Modifies a message.
80//
81// Deprecated: The Assistants API is deprecated in favor of the Responses API
82func (r *BetaThreadMessageService) Update(ctx context.Context, threadID string, messageID string, body BetaThreadMessageUpdateParams, opts ...option.RequestOption) (res *Message, err error) {
83 opts = append(r.Options[:], opts...)
84 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
85 if threadID == "" {
86 err = errors.New("missing required thread_id parameter")
87 return
88 }
89 if messageID == "" {
90 err = errors.New("missing required message_id parameter")
91 return
92 }
93 path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
94 err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
95 return
96}
97
98// Returns a list of messages for a given thread.
99//
100// Deprecated: The Assistants API is deprecated in favor of the Responses API
101func (r *BetaThreadMessageService) List(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Message], err error) {
102 var raw *http.Response
103 opts = append(r.Options[:], opts...)
104 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
105 if threadID == "" {
106 err = errors.New("missing required thread_id parameter")
107 return
108 }
109 path := fmt.Sprintf("threads/%s/messages", threadID)
110 cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
111 if err != nil {
112 return nil, err
113 }
114 err = cfg.Execute()
115 if err != nil {
116 return nil, err
117 }
118 res.SetPageConfig(cfg, raw)
119 return res, nil
120}
121
122// Returns a list of messages for a given thread.
123//
124// Deprecated: The Assistants API is deprecated in favor of the Responses API
125func (r *BetaThreadMessageService) ListAutoPaging(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Message] {
126 return pagination.NewCursorPageAutoPager(r.List(ctx, threadID, query, opts...))
127}
128
129// Deletes a message.
130//
131// Deprecated: The Assistants API is deprecated in favor of the Responses API
132func (r *BetaThreadMessageService) Delete(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *MessageDeleted, err error) {
133 opts = append(r.Options[:], opts...)
134 opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
135 if threadID == "" {
136 err = errors.New("missing required thread_id parameter")
137 return
138 }
139 if messageID == "" {
140 err = errors.New("missing required message_id parameter")
141 return
142 }
143 path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
144 err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
145 return
146}
147
148// AnnotationUnion contains all possible properties and values from
149// [FileCitationAnnotation], [FilePathAnnotation].
150//
151// Use the [AnnotationUnion.AsAny] method to switch on the variant.
152//
153// Use the methods beginning with 'As' to cast the union to one of its variants.
154type AnnotationUnion struct {
155 EndIndex int64 `json:"end_index"`
156 // This field is from variant [FileCitationAnnotation].
157 FileCitation FileCitationAnnotationFileCitation `json:"file_citation"`
158 StartIndex int64 `json:"start_index"`
159 Text string `json:"text"`
160 // Any of "file_citation", "file_path".
161 Type string `json:"type"`
162 // This field is from variant [FilePathAnnotation].
163 FilePath FilePathAnnotationFilePath `json:"file_path"`
164 JSON struct {
165 EndIndex respjson.Field
166 FileCitation respjson.Field
167 StartIndex respjson.Field
168 Text respjson.Field
169 Type respjson.Field
170 FilePath respjson.Field
171 raw string
172 } `json:"-"`
173}
174
175// anyAnnotation is implemented by each variant of [AnnotationUnion] to add type
176// safety for the return type of [AnnotationUnion.AsAny]
177type anyAnnotation interface {
178 implAnnotationUnion()
179}
180
181func (FileCitationAnnotation) implAnnotationUnion() {}
182func (FilePathAnnotation) implAnnotationUnion() {}
183
184// Use the following switch statement to find the correct variant
185//
186// switch variant := AnnotationUnion.AsAny().(type) {
187// case openai.FileCitationAnnotation:
188// case openai.FilePathAnnotation:
189// default:
190// fmt.Errorf("no variant present")
191// }
192func (u AnnotationUnion) AsAny() anyAnnotation {
193 switch u.Type {
194 case "file_citation":
195 return u.AsFileCitation()
196 case "file_path":
197 return u.AsFilePath()
198 }
199 return nil
200}
201
202func (u AnnotationUnion) AsFileCitation() (v FileCitationAnnotation) {
203 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
204 return
205}
206
207func (u AnnotationUnion) AsFilePath() (v FilePathAnnotation) {
208 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
209 return
210}
211
212// Returns the unmodified JSON received from the API
213func (u AnnotationUnion) RawJSON() string { return u.JSON.raw }
214
215func (r *AnnotationUnion) UnmarshalJSON(data []byte) error {
216 return apijson.UnmarshalRoot(data, r)
217}
218
219// AnnotationDeltaUnion contains all possible properties and values from
220// [FileCitationDeltaAnnotation], [FilePathDeltaAnnotation].
221//
222// Use the [AnnotationDeltaUnion.AsAny] method to switch on the variant.
223//
224// Use the methods beginning with 'As' to cast the union to one of its variants.
225type AnnotationDeltaUnion struct {
226 Index int64 `json:"index"`
227 // Any of "file_citation", "file_path".
228 Type string `json:"type"`
229 EndIndex int64 `json:"end_index"`
230 // This field is from variant [FileCitationDeltaAnnotation].
231 FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
232 StartIndex int64 `json:"start_index"`
233 Text string `json:"text"`
234 // This field is from variant [FilePathDeltaAnnotation].
235 FilePath FilePathDeltaAnnotationFilePath `json:"file_path"`
236 JSON struct {
237 Index respjson.Field
238 Type respjson.Field
239 EndIndex respjson.Field
240 FileCitation respjson.Field
241 StartIndex respjson.Field
242 Text respjson.Field
243 FilePath respjson.Field
244 raw string
245 } `json:"-"`
246}
247
248// anyAnnotationDelta is implemented by each variant of [AnnotationDeltaUnion] to
249// add type safety for the return type of [AnnotationDeltaUnion.AsAny]
250type anyAnnotationDelta interface {
251 implAnnotationDeltaUnion()
252}
253
254func (FileCitationDeltaAnnotation) implAnnotationDeltaUnion() {}
255func (FilePathDeltaAnnotation) implAnnotationDeltaUnion() {}
256
257// Use the following switch statement to find the correct variant
258//
259// switch variant := AnnotationDeltaUnion.AsAny().(type) {
260// case openai.FileCitationDeltaAnnotation:
261// case openai.FilePathDeltaAnnotation:
262// default:
263// fmt.Errorf("no variant present")
264// }
265func (u AnnotationDeltaUnion) AsAny() anyAnnotationDelta {
266 switch u.Type {
267 case "file_citation":
268 return u.AsFileCitation()
269 case "file_path":
270 return u.AsFilePath()
271 }
272 return nil
273}
274
275func (u AnnotationDeltaUnion) AsFileCitation() (v FileCitationDeltaAnnotation) {
276 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
277 return
278}
279
280func (u AnnotationDeltaUnion) AsFilePath() (v FilePathDeltaAnnotation) {
281 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
282 return
283}
284
285// Returns the unmodified JSON received from the API
286func (u AnnotationDeltaUnion) RawJSON() string { return u.JSON.raw }
287
288func (r *AnnotationDeltaUnion) UnmarshalJSON(data []byte) error {
289 return apijson.UnmarshalRoot(data, r)
290}
291
292// A citation within the message that points to a specific quote from a specific
293// File associated with the assistant or the message. Generated when the assistant
294// uses the "file_search" tool to search files.
295type FileCitationAnnotation struct {
296 EndIndex int64 `json:"end_index,required"`
297 FileCitation FileCitationAnnotationFileCitation `json:"file_citation,required"`
298 StartIndex int64 `json:"start_index,required"`
299 // The text in the message content that needs to be replaced.
300 Text string `json:"text,required"`
301 // Always `file_citation`.
302 Type constant.FileCitation `json:"type,required"`
303 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
304 JSON struct {
305 EndIndex respjson.Field
306 FileCitation respjson.Field
307 StartIndex respjson.Field
308 Text respjson.Field
309 Type respjson.Field
310 ExtraFields map[string]respjson.Field
311 raw string
312 } `json:"-"`
313}
314
315// Returns the unmodified JSON received from the API
316func (r FileCitationAnnotation) RawJSON() string { return r.JSON.raw }
317func (r *FileCitationAnnotation) UnmarshalJSON(data []byte) error {
318 return apijson.UnmarshalRoot(data, r)
319}
320
321type FileCitationAnnotationFileCitation struct {
322 // The ID of the specific File the citation is from.
323 FileID string `json:"file_id,required"`
324 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
325 JSON struct {
326 FileID respjson.Field
327 ExtraFields map[string]respjson.Field
328 raw string
329 } `json:"-"`
330}
331
332// Returns the unmodified JSON received from the API
333func (r FileCitationAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
334func (r *FileCitationAnnotationFileCitation) UnmarshalJSON(data []byte) error {
335 return apijson.UnmarshalRoot(data, r)
336}
337
338// A citation within the message that points to a specific quote from a specific
339// File associated with the assistant or the message. Generated when the assistant
340// uses the "file_search" tool to search files.
341type FileCitationDeltaAnnotation struct {
342 // The index of the annotation in the text content part.
343 Index int64 `json:"index,required"`
344 // Always `file_citation`.
345 Type constant.FileCitation `json:"type,required"`
346 EndIndex int64 `json:"end_index"`
347 FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
348 StartIndex int64 `json:"start_index"`
349 // The text in the message content that needs to be replaced.
350 Text string `json:"text"`
351 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
352 JSON struct {
353 Index respjson.Field
354 Type respjson.Field
355 EndIndex respjson.Field
356 FileCitation respjson.Field
357 StartIndex respjson.Field
358 Text respjson.Field
359 ExtraFields map[string]respjson.Field
360 raw string
361 } `json:"-"`
362}
363
364// Returns the unmodified JSON received from the API
365func (r FileCitationDeltaAnnotation) RawJSON() string { return r.JSON.raw }
366func (r *FileCitationDeltaAnnotation) UnmarshalJSON(data []byte) error {
367 return apijson.UnmarshalRoot(data, r)
368}
369
370type FileCitationDeltaAnnotationFileCitation struct {
371 // The ID of the specific File the citation is from.
372 FileID string `json:"file_id"`
373 // The specific quote in the file.
374 Quote string `json:"quote"`
375 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
376 JSON struct {
377 FileID respjson.Field
378 Quote respjson.Field
379 ExtraFields map[string]respjson.Field
380 raw string
381 } `json:"-"`
382}
383
384// Returns the unmodified JSON received from the API
385func (r FileCitationDeltaAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
386func (r *FileCitationDeltaAnnotationFileCitation) UnmarshalJSON(data []byte) error {
387 return apijson.UnmarshalRoot(data, r)
388}
389
390// A URL for the file that's generated when the assistant used the
391// `code_interpreter` tool to generate a file.
392type FilePathAnnotation struct {
393 EndIndex int64 `json:"end_index,required"`
394 FilePath FilePathAnnotationFilePath `json:"file_path,required"`
395 StartIndex int64 `json:"start_index,required"`
396 // The text in the message content that needs to be replaced.
397 Text string `json:"text,required"`
398 // Always `file_path`.
399 Type constant.FilePath `json:"type,required"`
400 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
401 JSON struct {
402 EndIndex respjson.Field
403 FilePath respjson.Field
404 StartIndex respjson.Field
405 Text respjson.Field
406 Type respjson.Field
407 ExtraFields map[string]respjson.Field
408 raw string
409 } `json:"-"`
410}
411
412// Returns the unmodified JSON received from the API
413func (r FilePathAnnotation) RawJSON() string { return r.JSON.raw }
414func (r *FilePathAnnotation) UnmarshalJSON(data []byte) error {
415 return apijson.UnmarshalRoot(data, r)
416}
417
418type FilePathAnnotationFilePath struct {
419 // The ID of the file that was generated.
420 FileID string `json:"file_id,required"`
421 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
422 JSON struct {
423 FileID respjson.Field
424 ExtraFields map[string]respjson.Field
425 raw string
426 } `json:"-"`
427}
428
429// Returns the unmodified JSON received from the API
430func (r FilePathAnnotationFilePath) RawJSON() string { return r.JSON.raw }
431func (r *FilePathAnnotationFilePath) UnmarshalJSON(data []byte) error {
432 return apijson.UnmarshalRoot(data, r)
433}
434
435// A URL for the file that's generated when the assistant used the
436// `code_interpreter` tool to generate a file.
437type FilePathDeltaAnnotation struct {
438 // The index of the annotation in the text content part.
439 Index int64 `json:"index,required"`
440 // Always `file_path`.
441 Type constant.FilePath `json:"type,required"`
442 EndIndex int64 `json:"end_index"`
443 FilePath FilePathDeltaAnnotationFilePath `json:"file_path"`
444 StartIndex int64 `json:"start_index"`
445 // The text in the message content that needs to be replaced.
446 Text string `json:"text"`
447 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
448 JSON struct {
449 Index respjson.Field
450 Type respjson.Field
451 EndIndex respjson.Field
452 FilePath respjson.Field
453 StartIndex respjson.Field
454 Text respjson.Field
455 ExtraFields map[string]respjson.Field
456 raw string
457 } `json:"-"`
458}
459
460// Returns the unmodified JSON received from the API
461func (r FilePathDeltaAnnotation) RawJSON() string { return r.JSON.raw }
462func (r *FilePathDeltaAnnotation) UnmarshalJSON(data []byte) error {
463 return apijson.UnmarshalRoot(data, r)
464}
465
466type FilePathDeltaAnnotationFilePath struct {
467 // The ID of the file that was generated.
468 FileID string `json:"file_id"`
469 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
470 JSON struct {
471 FileID respjson.Field
472 ExtraFields map[string]respjson.Field
473 raw string
474 } `json:"-"`
475}
476
477// Returns the unmodified JSON received from the API
478func (r FilePathDeltaAnnotationFilePath) RawJSON() string { return r.JSON.raw }
479func (r *FilePathDeltaAnnotationFilePath) UnmarshalJSON(data []byte) error {
480 return apijson.UnmarshalRoot(data, r)
481}
482
483type ImageFile struct {
484 // The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
485 // in the message content. Set `purpose="vision"` when uploading the File if you
486 // need to later display the file content.
487 FileID string `json:"file_id,required"`
488 // Specifies the detail level of the image if specified by the user. `low` uses
489 // fewer tokens, you can opt in to high resolution using `high`.
490 //
491 // Any of "auto", "low", "high".
492 Detail ImageFileDetail `json:"detail"`
493 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
494 JSON struct {
495 FileID respjson.Field
496 Detail respjson.Field
497 ExtraFields map[string]respjson.Field
498 raw string
499 } `json:"-"`
500}
501
502// Returns the unmodified JSON received from the API
503func (r ImageFile) RawJSON() string { return r.JSON.raw }
504func (r *ImageFile) UnmarshalJSON(data []byte) error {
505 return apijson.UnmarshalRoot(data, r)
506}
507
508// ToParam converts this ImageFile to a ImageFileParam.
509//
510// Warning: the fields of the param type will not be present. ToParam should only
511// be used at the last possible moment before sending a request. Test for this with
512// ImageFileParam.Overrides()
513func (r ImageFile) ToParam() ImageFileParam {
514 return param.Override[ImageFileParam](json.RawMessage(r.RawJSON()))
515}
516
517// Specifies the detail level of the image if specified by the user. `low` uses
518// fewer tokens, you can opt in to high resolution using `high`.
519type ImageFileDetail string
520
521const (
522 ImageFileDetailAuto ImageFileDetail = "auto"
523 ImageFileDetailLow ImageFileDetail = "low"
524 ImageFileDetailHigh ImageFileDetail = "high"
525)
526
527// The property FileID is required.
528type ImageFileParam struct {
529 // The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
530 // in the message content. Set `purpose="vision"` when uploading the File if you
531 // need to later display the file content.
532 FileID string `json:"file_id,required"`
533 // Specifies the detail level of the image if specified by the user. `low` uses
534 // fewer tokens, you can opt in to high resolution using `high`.
535 //
536 // Any of "auto", "low", "high".
537 Detail ImageFileDetail `json:"detail,omitzero"`
538 paramObj
539}
540
541func (r ImageFileParam) MarshalJSON() (data []byte, err error) {
542 type shadow ImageFileParam
543 return param.MarshalObject(r, (*shadow)(&r))
544}
545func (r *ImageFileParam) UnmarshalJSON(data []byte) error {
546 return apijson.UnmarshalRoot(data, r)
547}
548
549// References an image [File](https://platform.openai.com/docs/api-reference/files)
550// in the content of a message.
551type ImageFileContentBlock struct {
552 ImageFile ImageFile `json:"image_file,required"`
553 // Always `image_file`.
554 Type constant.ImageFile `json:"type,required"`
555 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
556 JSON struct {
557 ImageFile respjson.Field
558 Type respjson.Field
559 ExtraFields map[string]respjson.Field
560 raw string
561 } `json:"-"`
562}
563
564// Returns the unmodified JSON received from the API
565func (r ImageFileContentBlock) RawJSON() string { return r.JSON.raw }
566func (r *ImageFileContentBlock) UnmarshalJSON(data []byte) error {
567 return apijson.UnmarshalRoot(data, r)
568}
569
570// ToParam converts this ImageFileContentBlock to a ImageFileContentBlockParam.
571//
572// Warning: the fields of the param type will not be present. ToParam should only
573// be used at the last possible moment before sending a request. Test for this with
574// ImageFileContentBlockParam.Overrides()
575func (r ImageFileContentBlock) ToParam() ImageFileContentBlockParam {
576 return param.Override[ImageFileContentBlockParam](json.RawMessage(r.RawJSON()))
577}
578
579// References an image [File](https://platform.openai.com/docs/api-reference/files)
580// in the content of a message.
581//
582// The properties ImageFile, Type are required.
583type ImageFileContentBlockParam struct {
584 ImageFile ImageFileParam `json:"image_file,omitzero,required"`
585 // Always `image_file`.
586 //
587 // This field can be elided, and will marshal its zero value as "image_file".
588 Type constant.ImageFile `json:"type,required"`
589 paramObj
590}
591
592func (r ImageFileContentBlockParam) MarshalJSON() (data []byte, err error) {
593 type shadow ImageFileContentBlockParam
594 return param.MarshalObject(r, (*shadow)(&r))
595}
596func (r *ImageFileContentBlockParam) UnmarshalJSON(data []byte) error {
597 return apijson.UnmarshalRoot(data, r)
598}
599
600type ImageFileDelta struct {
601 // Specifies the detail level of the image if specified by the user. `low` uses
602 // fewer tokens, you can opt in to high resolution using `high`.
603 //
604 // Any of "auto", "low", "high".
605 Detail ImageFileDeltaDetail `json:"detail"`
606 // The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
607 // in the message content. Set `purpose="vision"` when uploading the File if you
608 // need to later display the file content.
609 FileID string `json:"file_id"`
610 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
611 JSON struct {
612 Detail respjson.Field
613 FileID respjson.Field
614 ExtraFields map[string]respjson.Field
615 raw string
616 } `json:"-"`
617}
618
619// Returns the unmodified JSON received from the API
620func (r ImageFileDelta) RawJSON() string { return r.JSON.raw }
621func (r *ImageFileDelta) UnmarshalJSON(data []byte) error {
622 return apijson.UnmarshalRoot(data, r)
623}
624
625// Specifies the detail level of the image if specified by the user. `low` uses
626// fewer tokens, you can opt in to high resolution using `high`.
627type ImageFileDeltaDetail string
628
629const (
630 ImageFileDeltaDetailAuto ImageFileDeltaDetail = "auto"
631 ImageFileDeltaDetailLow ImageFileDeltaDetail = "low"
632 ImageFileDeltaDetailHigh ImageFileDeltaDetail = "high"
633)
634
635// References an image [File](https://platform.openai.com/docs/api-reference/files)
636// in the content of a message.
637type ImageFileDeltaBlock struct {
638 // The index of the content part in the message.
639 Index int64 `json:"index,required"`
640 // Always `image_file`.
641 Type constant.ImageFile `json:"type,required"`
642 ImageFile ImageFileDelta `json:"image_file"`
643 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
644 JSON struct {
645 Index respjson.Field
646 Type respjson.Field
647 ImageFile respjson.Field
648 ExtraFields map[string]respjson.Field
649 raw string
650 } `json:"-"`
651}
652
653// Returns the unmodified JSON received from the API
654func (r ImageFileDeltaBlock) RawJSON() string { return r.JSON.raw }
655func (r *ImageFileDeltaBlock) UnmarshalJSON(data []byte) error {
656 return apijson.UnmarshalRoot(data, r)
657}
658
659type ImageURL struct {
660 // The external URL of the image, must be a supported image types: jpeg, jpg, png,
661 // gif, webp.
662 URL string `json:"url,required" format:"uri"`
663 // Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
664 // to high resolution using `high`. Default value is `auto`
665 //
666 // Any of "auto", "low", "high".
667 Detail ImageURLDetail `json:"detail"`
668 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
669 JSON struct {
670 URL respjson.Field
671 Detail respjson.Field
672 ExtraFields map[string]respjson.Field
673 raw string
674 } `json:"-"`
675}
676
677// Returns the unmodified JSON received from the API
678func (r ImageURL) RawJSON() string { return r.JSON.raw }
679func (r *ImageURL) UnmarshalJSON(data []byte) error {
680 return apijson.UnmarshalRoot(data, r)
681}
682
683// ToParam converts this ImageURL to a ImageURLParam.
684//
685// Warning: the fields of the param type will not be present. ToParam should only
686// be used at the last possible moment before sending a request. Test for this with
687// ImageURLParam.Overrides()
688func (r ImageURL) ToParam() ImageURLParam {
689 return param.Override[ImageURLParam](json.RawMessage(r.RawJSON()))
690}
691
692// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
693// to high resolution using `high`. Default value is `auto`
694type ImageURLDetail string
695
696const (
697 ImageURLDetailAuto ImageURLDetail = "auto"
698 ImageURLDetailLow ImageURLDetail = "low"
699 ImageURLDetailHigh ImageURLDetail = "high"
700)
701
702// The property URL is required.
703type ImageURLParam struct {
704 // The external URL of the image, must be a supported image types: jpeg, jpg, png,
705 // gif, webp.
706 URL string `json:"url,required" format:"uri"`
707 // Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
708 // to high resolution using `high`. Default value is `auto`
709 //
710 // Any of "auto", "low", "high".
711 Detail ImageURLDetail `json:"detail,omitzero"`
712 paramObj
713}
714
715func (r ImageURLParam) MarshalJSON() (data []byte, err error) {
716 type shadow ImageURLParam
717 return param.MarshalObject(r, (*shadow)(&r))
718}
719func (r *ImageURLParam) UnmarshalJSON(data []byte) error {
720 return apijson.UnmarshalRoot(data, r)
721}
722
723// References an image URL in the content of a message.
724type ImageURLContentBlock struct {
725 ImageURL ImageURL `json:"image_url,required"`
726 // The type of the content part.
727 Type constant.ImageURL `json:"type,required"`
728 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
729 JSON struct {
730 ImageURL respjson.Field
731 Type respjson.Field
732 ExtraFields map[string]respjson.Field
733 raw string
734 } `json:"-"`
735}
736
737// Returns the unmodified JSON received from the API
738func (r ImageURLContentBlock) RawJSON() string { return r.JSON.raw }
739func (r *ImageURLContentBlock) UnmarshalJSON(data []byte) error {
740 return apijson.UnmarshalRoot(data, r)
741}
742
743// ToParam converts this ImageURLContentBlock to a ImageURLContentBlockParam.
744//
745// Warning: the fields of the param type will not be present. ToParam should only
746// be used at the last possible moment before sending a request. Test for this with
747// ImageURLContentBlockParam.Overrides()
748func (r ImageURLContentBlock) ToParam() ImageURLContentBlockParam {
749 return param.Override[ImageURLContentBlockParam](json.RawMessage(r.RawJSON()))
750}
751
752// References an image URL in the content of a message.
753//
754// The properties ImageURL, Type are required.
755type ImageURLContentBlockParam struct {
756 ImageURL ImageURLParam `json:"image_url,omitzero,required"`
757 // The type of the content part.
758 //
759 // This field can be elided, and will marshal its zero value as "image_url".
760 Type constant.ImageURL `json:"type,required"`
761 paramObj
762}
763
764func (r ImageURLContentBlockParam) MarshalJSON() (data []byte, err error) {
765 type shadow ImageURLContentBlockParam
766 return param.MarshalObject(r, (*shadow)(&r))
767}
768func (r *ImageURLContentBlockParam) UnmarshalJSON(data []byte) error {
769 return apijson.UnmarshalRoot(data, r)
770}
771
772type ImageURLDelta struct {
773 // Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
774 // to high resolution using `high`.
775 //
776 // Any of "auto", "low", "high".
777 Detail ImageURLDeltaDetail `json:"detail"`
778 // The URL of the image, must be a supported image types: jpeg, jpg, png, gif,
779 // webp.
780 URL string `json:"url"`
781 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
782 JSON struct {
783 Detail respjson.Field
784 URL respjson.Field
785 ExtraFields map[string]respjson.Field
786 raw string
787 } `json:"-"`
788}
789
790// Returns the unmodified JSON received from the API
791func (r ImageURLDelta) RawJSON() string { return r.JSON.raw }
792func (r *ImageURLDelta) UnmarshalJSON(data []byte) error {
793 return apijson.UnmarshalRoot(data, r)
794}
795
796// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
797// to high resolution using `high`.
798type ImageURLDeltaDetail string
799
800const (
801 ImageURLDeltaDetailAuto ImageURLDeltaDetail = "auto"
802 ImageURLDeltaDetailLow ImageURLDeltaDetail = "low"
803 ImageURLDeltaDetailHigh ImageURLDeltaDetail = "high"
804)
805
806// References an image URL in the content of a message.
807type ImageURLDeltaBlock struct {
808 // The index of the content part in the message.
809 Index int64 `json:"index,required"`
810 // Always `image_url`.
811 Type constant.ImageURL `json:"type,required"`
812 ImageURL ImageURLDelta `json:"image_url"`
813 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
814 JSON struct {
815 Index respjson.Field
816 Type respjson.Field
817 ImageURL respjson.Field
818 ExtraFields map[string]respjson.Field
819 raw string
820 } `json:"-"`
821}
822
823// Returns the unmodified JSON received from the API
824func (r ImageURLDeltaBlock) RawJSON() string { return r.JSON.raw }
825func (r *ImageURLDeltaBlock) UnmarshalJSON(data []byte) error {
826 return apijson.UnmarshalRoot(data, r)
827}
828
829// Represents a message within a
830// [thread](https://platform.openai.com/docs/api-reference/threads).
831type Message struct {
832 // The identifier, which can be referenced in API endpoints.
833 ID string `json:"id,required"`
834 // If applicable, the ID of the
835 // [assistant](https://platform.openai.com/docs/api-reference/assistants) that
836 // authored this message.
837 AssistantID string `json:"assistant_id,required"`
838 // A list of files attached to the message, and the tools they were added to.
839 Attachments []MessageAttachment `json:"attachments,required"`
840 // The Unix timestamp (in seconds) for when the message was completed.
841 CompletedAt int64 `json:"completed_at,required"`
842 // The content of the message in array of text and/or images.
843 Content []MessageContentUnion `json:"content,required"`
844 // The Unix timestamp (in seconds) for when the message was created.
845 CreatedAt int64 `json:"created_at,required"`
846 // The Unix timestamp (in seconds) for when the message was marked as incomplete.
847 IncompleteAt int64 `json:"incomplete_at,required"`
848 // On an incomplete message, details about why the message is incomplete.
849 IncompleteDetails MessageIncompleteDetails `json:"incomplete_details,required"`
850 // Set of 16 key-value pairs that can be attached to an object. This can be useful
851 // for storing additional information about the object in a structured format, and
852 // querying for objects via API or the dashboard.
853 //
854 // Keys are strings with a maximum length of 64 characters. Values are strings with
855 // a maximum length of 512 characters.
856 Metadata shared.Metadata `json:"metadata,required"`
857 // The object type, which is always `thread.message`.
858 Object constant.ThreadMessage `json:"object,required"`
859 // The entity that produced the message. One of `user` or `assistant`.
860 //
861 // Any of "user", "assistant".
862 Role MessageRole `json:"role,required"`
863 // The ID of the [run](https://platform.openai.com/docs/api-reference/runs)
864 // associated with the creation of this message. Value is `null` when messages are
865 // created manually using the create message or create thread endpoints.
866 RunID string `json:"run_id,required"`
867 // The status of the message, which can be either `in_progress`, `incomplete`, or
868 // `completed`.
869 //
870 // Any of "in_progress", "incomplete", "completed".
871 Status MessageStatus `json:"status,required"`
872 // The [thread](https://platform.openai.com/docs/api-reference/threads) ID that
873 // this message belongs to.
874 ThreadID string `json:"thread_id,required"`
875 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
876 JSON struct {
877 ID respjson.Field
878 AssistantID respjson.Field
879 Attachments respjson.Field
880 CompletedAt respjson.Field
881 Content respjson.Field
882 CreatedAt respjson.Field
883 IncompleteAt respjson.Field
884 IncompleteDetails respjson.Field
885 Metadata respjson.Field
886 Object respjson.Field
887 Role respjson.Field
888 RunID respjson.Field
889 Status respjson.Field
890 ThreadID respjson.Field
891 ExtraFields map[string]respjson.Field
892 raw string
893 } `json:"-"`
894}
895
896// Returns the unmodified JSON received from the API
897func (r Message) RawJSON() string { return r.JSON.raw }
898func (r *Message) UnmarshalJSON(data []byte) error {
899 return apijson.UnmarshalRoot(data, r)
900}
901
902type MessageAttachment struct {
903 // The ID of the file to attach to the message.
904 FileID string `json:"file_id"`
905 // The tools to add this file to.
906 Tools []MessageAttachmentToolUnion `json:"tools"`
907 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
908 JSON struct {
909 FileID respjson.Field
910 Tools respjson.Field
911 ExtraFields map[string]respjson.Field
912 raw string
913 } `json:"-"`
914}
915
916// Returns the unmodified JSON received from the API
917func (r MessageAttachment) RawJSON() string { return r.JSON.raw }
918func (r *MessageAttachment) UnmarshalJSON(data []byte) error {
919 return apijson.UnmarshalRoot(data, r)
920}
921
922// MessageAttachmentToolUnion contains all possible properties and values from
923// [CodeInterpreterTool], [MessageAttachmentToolFileSearchTool].
924//
925// Use the methods beginning with 'As' to cast the union to one of its variants.
926type MessageAttachmentToolUnion struct {
927 Type string `json:"type"`
928 JSON struct {
929 Type respjson.Field
930 raw string
931 } `json:"-"`
932}
933
934func (u MessageAttachmentToolUnion) AsCodeInterpreterTool() (v CodeInterpreterTool) {
935 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
936 return
937}
938
939func (u MessageAttachmentToolUnion) AsFileSearchTool() (v MessageAttachmentToolFileSearchTool) {
940 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
941 return
942}
943
944// Returns the unmodified JSON received from the API
945func (u MessageAttachmentToolUnion) RawJSON() string { return u.JSON.raw }
946
947func (r *MessageAttachmentToolUnion) UnmarshalJSON(data []byte) error {
948 return apijson.UnmarshalRoot(data, r)
949}
950
951type MessageAttachmentToolFileSearchTool struct {
952 // The type of tool being defined: `file_search`
953 Type constant.FileSearch `json:"type,required"`
954 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
955 JSON struct {
956 Type respjson.Field
957 ExtraFields map[string]respjson.Field
958 raw string
959 } `json:"-"`
960}
961
962// Returns the unmodified JSON received from the API
963func (r MessageAttachmentToolFileSearchTool) RawJSON() string { return r.JSON.raw }
964func (r *MessageAttachmentToolFileSearchTool) UnmarshalJSON(data []byte) error {
965 return apijson.UnmarshalRoot(data, r)
966}
967
968// On an incomplete message, details about why the message is incomplete.
969type MessageIncompleteDetails struct {
970 // The reason the message is incomplete.
971 //
972 // Any of "content_filter", "max_tokens", "run_cancelled", "run_expired",
973 // "run_failed".
974 Reason string `json:"reason,required"`
975 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
976 JSON struct {
977 Reason respjson.Field
978 ExtraFields map[string]respjson.Field
979 raw string
980 } `json:"-"`
981}
982
983// Returns the unmodified JSON received from the API
984func (r MessageIncompleteDetails) RawJSON() string { return r.JSON.raw }
985func (r *MessageIncompleteDetails) UnmarshalJSON(data []byte) error {
986 return apijson.UnmarshalRoot(data, r)
987}
988
989// The entity that produced the message. One of `user` or `assistant`.
990type MessageRole string
991
992const (
993 MessageRoleUser MessageRole = "user"
994 MessageRoleAssistant MessageRole = "assistant"
995)
996
997// The status of the message, which can be either `in_progress`, `incomplete`, or
998// `completed`.
999type MessageStatus string
1000
1001const (
1002 MessageStatusInProgress MessageStatus = "in_progress"
1003 MessageStatusIncomplete MessageStatus = "incomplete"
1004 MessageStatusCompleted MessageStatus = "completed"
1005)
1006
1007// MessageContentUnion contains all possible properties and values from
1008// [ImageFileContentBlock], [ImageURLContentBlock], [TextContentBlock],
1009// [RefusalContentBlock].
1010//
1011// Use the [MessageContentUnion.AsAny] method to switch on the variant.
1012//
1013// Use the methods beginning with 'As' to cast the union to one of its variants.
1014type MessageContentUnion struct {
1015 // This field is from variant [ImageFileContentBlock].
1016 ImageFile ImageFile `json:"image_file"`
1017 // Any of "image_file", "image_url", "text", "refusal".
1018 Type string `json:"type"`
1019 // This field is from variant [ImageURLContentBlock].
1020 ImageURL ImageURL `json:"image_url"`
1021 // This field is from variant [TextContentBlock].
1022 Text Text `json:"text"`
1023 // This field is from variant [RefusalContentBlock].
1024 Refusal string `json:"refusal"`
1025 JSON struct {
1026 ImageFile respjson.Field
1027 Type respjson.Field
1028 ImageURL respjson.Field
1029 Text respjson.Field
1030 Refusal respjson.Field
1031 raw string
1032 } `json:"-"`
1033}
1034
1035// anyMessageContent is implemented by each variant of [MessageContentUnion] to add
1036// type safety for the return type of [MessageContentUnion.AsAny]
1037type anyMessageContent interface {
1038 implMessageContentUnion()
1039}
1040
1041func (ImageFileContentBlock) implMessageContentUnion() {}
1042func (ImageURLContentBlock) implMessageContentUnion() {}
1043func (TextContentBlock) implMessageContentUnion() {}
1044func (RefusalContentBlock) implMessageContentUnion() {}
1045
1046// Use the following switch statement to find the correct variant
1047//
1048// switch variant := MessageContentUnion.AsAny().(type) {
1049// case openai.ImageFileContentBlock:
1050// case openai.ImageURLContentBlock:
1051// case openai.TextContentBlock:
1052// case openai.RefusalContentBlock:
1053// default:
1054// fmt.Errorf("no variant present")
1055// }
1056func (u MessageContentUnion) AsAny() anyMessageContent {
1057 switch u.Type {
1058 case "image_file":
1059 return u.AsImageFile()
1060 case "image_url":
1061 return u.AsImageURL()
1062 case "text":
1063 return u.AsText()
1064 case "refusal":
1065 return u.AsRefusal()
1066 }
1067 return nil
1068}
1069
1070func (u MessageContentUnion) AsImageFile() (v ImageFileContentBlock) {
1071 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1072 return
1073}
1074
1075func (u MessageContentUnion) AsImageURL() (v ImageURLContentBlock) {
1076 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1077 return
1078}
1079
1080func (u MessageContentUnion) AsText() (v TextContentBlock) {
1081 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1082 return
1083}
1084
1085func (u MessageContentUnion) AsRefusal() (v RefusalContentBlock) {
1086 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1087 return
1088}
1089
1090// Returns the unmodified JSON received from the API
1091func (u MessageContentUnion) RawJSON() string { return u.JSON.raw }
1092
1093func (r *MessageContentUnion) UnmarshalJSON(data []byte) error {
1094 return apijson.UnmarshalRoot(data, r)
1095}
1096
1097// MessageContentDeltaUnion contains all possible properties and values from
1098// [ImageFileDeltaBlock], [TextDeltaBlock], [RefusalDeltaBlock],
1099// [ImageURLDeltaBlock].
1100//
1101// Use the [MessageContentDeltaUnion.AsAny] method to switch on the variant.
1102//
1103// Use the methods beginning with 'As' to cast the union to one of its variants.
1104type MessageContentDeltaUnion struct {
1105 Index int64 `json:"index"`
1106 // Any of "image_file", "text", "refusal", "image_url".
1107 Type string `json:"type"`
1108 // This field is from variant [ImageFileDeltaBlock].
1109 ImageFile ImageFileDelta `json:"image_file"`
1110 // This field is from variant [TextDeltaBlock].
1111 Text TextDelta `json:"text"`
1112 // This field is from variant [RefusalDeltaBlock].
1113 Refusal string `json:"refusal"`
1114 // This field is from variant [ImageURLDeltaBlock].
1115 ImageURL ImageURLDelta `json:"image_url"`
1116 JSON struct {
1117 Index respjson.Field
1118 Type respjson.Field
1119 ImageFile respjson.Field
1120 Text respjson.Field
1121 Refusal respjson.Field
1122 ImageURL respjson.Field
1123 raw string
1124 } `json:"-"`
1125}
1126
1127// anyMessageContentDelta is implemented by each variant of
1128// [MessageContentDeltaUnion] to add type safety for the return type of
1129// [MessageContentDeltaUnion.AsAny]
1130type anyMessageContentDelta interface {
1131 implMessageContentDeltaUnion()
1132}
1133
1134func (ImageFileDeltaBlock) implMessageContentDeltaUnion() {}
1135func (TextDeltaBlock) implMessageContentDeltaUnion() {}
1136func (RefusalDeltaBlock) implMessageContentDeltaUnion() {}
1137func (ImageURLDeltaBlock) implMessageContentDeltaUnion() {}
1138
1139// Use the following switch statement to find the correct variant
1140//
1141// switch variant := MessageContentDeltaUnion.AsAny().(type) {
1142// case openai.ImageFileDeltaBlock:
1143// case openai.TextDeltaBlock:
1144// case openai.RefusalDeltaBlock:
1145// case openai.ImageURLDeltaBlock:
1146// default:
1147// fmt.Errorf("no variant present")
1148// }
1149func (u MessageContentDeltaUnion) AsAny() anyMessageContentDelta {
1150 switch u.Type {
1151 case "image_file":
1152 return u.AsImageFile()
1153 case "text":
1154 return u.AsText()
1155 case "refusal":
1156 return u.AsRefusal()
1157 case "image_url":
1158 return u.AsImageURL()
1159 }
1160 return nil
1161}
1162
1163func (u MessageContentDeltaUnion) AsImageFile() (v ImageFileDeltaBlock) {
1164 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1165 return
1166}
1167
1168func (u MessageContentDeltaUnion) AsText() (v TextDeltaBlock) {
1169 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1170 return
1171}
1172
1173func (u MessageContentDeltaUnion) AsRefusal() (v RefusalDeltaBlock) {
1174 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1175 return
1176}
1177
1178func (u MessageContentDeltaUnion) AsImageURL() (v ImageURLDeltaBlock) {
1179 apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
1180 return
1181}
1182
1183// Returns the unmodified JSON received from the API
1184func (u MessageContentDeltaUnion) RawJSON() string { return u.JSON.raw }
1185
1186func (r *MessageContentDeltaUnion) UnmarshalJSON(data []byte) error {
1187 return apijson.UnmarshalRoot(data, r)
1188}
1189
1190func MessageContentPartParamOfImageFile(imageFile ImageFileParam) MessageContentPartParamUnion {
1191 var variant ImageFileContentBlockParam
1192 variant.ImageFile = imageFile
1193 return MessageContentPartParamUnion{OfImageFile: &variant}
1194}
1195
1196func MessageContentPartParamOfImageURL(imageURL ImageURLParam) MessageContentPartParamUnion {
1197 var variant ImageURLContentBlockParam
1198 variant.ImageURL = imageURL
1199 return MessageContentPartParamUnion{OfImageURL: &variant}
1200}
1201
1202func MessageContentPartParamOfText(text string) MessageContentPartParamUnion {
1203 var variant TextContentBlockParam
1204 variant.Text = text
1205 return MessageContentPartParamUnion{OfText: &variant}
1206}
1207
1208// Only one field can be non-zero.
1209//
1210// Use [param.IsOmitted] to confirm if a field is set.
1211type MessageContentPartParamUnion struct {
1212 OfImageFile *ImageFileContentBlockParam `json:",omitzero,inline"`
1213 OfImageURL *ImageURLContentBlockParam `json:",omitzero,inline"`
1214 OfText *TextContentBlockParam `json:",omitzero,inline"`
1215 paramUnion
1216}
1217
1218func (u MessageContentPartParamUnion) MarshalJSON() ([]byte, error) {
1219 return param.MarshalUnion(u, u.OfImageFile, u.OfImageURL, u.OfText)
1220}
1221func (u *MessageContentPartParamUnion) UnmarshalJSON(data []byte) error {
1222 return apijson.UnmarshalRoot(data, u)
1223}
1224
1225func (u *MessageContentPartParamUnion) asAny() any {
1226 if !param.IsOmitted(u.OfImageFile) {
1227 return u.OfImageFile
1228 } else if !param.IsOmitted(u.OfImageURL) {
1229 return u.OfImageURL
1230 } else if !param.IsOmitted(u.OfText) {
1231 return u.OfText
1232 }
1233 return nil
1234}
1235
1236// Returns a pointer to the underlying variant's property, if present.
1237func (u MessageContentPartParamUnion) GetImageFile() *ImageFileParam {
1238 if vt := u.OfImageFile; vt != nil {
1239 return &vt.ImageFile
1240 }
1241 return nil
1242}
1243
1244// Returns a pointer to the underlying variant's property, if present.
1245func (u MessageContentPartParamUnion) GetImageURL() *ImageURLParam {
1246 if vt := u.OfImageURL; vt != nil {
1247 return &vt.ImageURL
1248 }
1249 return nil
1250}
1251
1252// Returns a pointer to the underlying variant's property, if present.
1253func (u MessageContentPartParamUnion) GetText() *string {
1254 if vt := u.OfText; vt != nil {
1255 return &vt.Text
1256 }
1257 return nil
1258}
1259
1260// Returns a pointer to the underlying variant's property, if present.
1261func (u MessageContentPartParamUnion) GetType() *string {
1262 if vt := u.OfImageFile; vt != nil {
1263 return (*string)(&vt.Type)
1264 } else if vt := u.OfImageURL; vt != nil {
1265 return (*string)(&vt.Type)
1266 } else if vt := u.OfText; vt != nil {
1267 return (*string)(&vt.Type)
1268 }
1269 return nil
1270}
1271
1272func init() {
1273 apijson.RegisterUnion[MessageContentPartParamUnion](
1274 "type",
1275 apijson.Discriminator[ImageFileContentBlockParam]("image_file"),
1276 apijson.Discriminator[ImageURLContentBlockParam]("image_url"),
1277 apijson.Discriminator[TextContentBlockParam]("text"),
1278 )
1279}
1280
1281type MessageDeleted struct {
1282 ID string `json:"id,required"`
1283 Deleted bool `json:"deleted,required"`
1284 Object constant.ThreadMessageDeleted `json:"object,required"`
1285 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1286 JSON struct {
1287 ID respjson.Field
1288 Deleted respjson.Field
1289 Object respjson.Field
1290 ExtraFields map[string]respjson.Field
1291 raw string
1292 } `json:"-"`
1293}
1294
1295// Returns the unmodified JSON received from the API
1296func (r MessageDeleted) RawJSON() string { return r.JSON.raw }
1297func (r *MessageDeleted) UnmarshalJSON(data []byte) error {
1298 return apijson.UnmarshalRoot(data, r)
1299}
1300
1301// The delta containing the fields that have changed on the Message.
1302type MessageDelta struct {
1303 // The content of the message in array of text and/or images.
1304 Content []MessageContentDeltaUnion `json:"content"`
1305 // The entity that produced the message. One of `user` or `assistant`.
1306 //
1307 // Any of "user", "assistant".
1308 Role MessageDeltaRole `json:"role"`
1309 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1310 JSON struct {
1311 Content respjson.Field
1312 Role respjson.Field
1313 ExtraFields map[string]respjson.Field
1314 raw string
1315 } `json:"-"`
1316}
1317
1318// Returns the unmodified JSON received from the API
1319func (r MessageDelta) RawJSON() string { return r.JSON.raw }
1320func (r *MessageDelta) UnmarshalJSON(data []byte) error {
1321 return apijson.UnmarshalRoot(data, r)
1322}
1323
1324// The entity that produced the message. One of `user` or `assistant`.
1325type MessageDeltaRole string
1326
1327const (
1328 MessageDeltaRoleUser MessageDeltaRole = "user"
1329 MessageDeltaRoleAssistant MessageDeltaRole = "assistant"
1330)
1331
1332// Represents a message delta i.e. any changed fields on a message during
1333// streaming.
1334type MessageDeltaEvent struct {
1335 // The identifier of the message, which can be referenced in API endpoints.
1336 ID string `json:"id,required"`
1337 // The delta containing the fields that have changed on the Message.
1338 Delta MessageDelta `json:"delta,required"`
1339 // The object type, which is always `thread.message.delta`.
1340 Object constant.ThreadMessageDelta `json:"object,required"`
1341 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1342 JSON struct {
1343 ID respjson.Field
1344 Delta respjson.Field
1345 Object respjson.Field
1346 ExtraFields map[string]respjson.Field
1347 raw string
1348 } `json:"-"`
1349}
1350
1351// Returns the unmodified JSON received from the API
1352func (r MessageDeltaEvent) RawJSON() string { return r.JSON.raw }
1353func (r *MessageDeltaEvent) UnmarshalJSON(data []byte) error {
1354 return apijson.UnmarshalRoot(data, r)
1355}
1356
1357// The refusal content generated by the assistant.
1358type RefusalContentBlock struct {
1359 Refusal string `json:"refusal,required"`
1360 // Always `refusal`.
1361 Type constant.Refusal `json:"type,required"`
1362 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1363 JSON struct {
1364 Refusal respjson.Field
1365 Type respjson.Field
1366 ExtraFields map[string]respjson.Field
1367 raw string
1368 } `json:"-"`
1369}
1370
1371// Returns the unmodified JSON received from the API
1372func (r RefusalContentBlock) RawJSON() string { return r.JSON.raw }
1373func (r *RefusalContentBlock) UnmarshalJSON(data []byte) error {
1374 return apijson.UnmarshalRoot(data, r)
1375}
1376
1377// The refusal content that is part of a message.
1378type RefusalDeltaBlock struct {
1379 // The index of the refusal part in the message.
1380 Index int64 `json:"index,required"`
1381 // Always `refusal`.
1382 Type constant.Refusal `json:"type,required"`
1383 Refusal string `json:"refusal"`
1384 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1385 JSON struct {
1386 Index respjson.Field
1387 Type respjson.Field
1388 Refusal respjson.Field
1389 ExtraFields map[string]respjson.Field
1390 raw string
1391 } `json:"-"`
1392}
1393
1394// Returns the unmodified JSON received from the API
1395func (r RefusalDeltaBlock) RawJSON() string { return r.JSON.raw }
1396func (r *RefusalDeltaBlock) UnmarshalJSON(data []byte) error {
1397 return apijson.UnmarshalRoot(data, r)
1398}
1399
1400type Text struct {
1401 Annotations []AnnotationUnion `json:"annotations,required"`
1402 // The data that makes up the text.
1403 Value string `json:"value,required"`
1404 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1405 JSON struct {
1406 Annotations respjson.Field
1407 Value respjson.Field
1408 ExtraFields map[string]respjson.Field
1409 raw string
1410 } `json:"-"`
1411}
1412
1413// Returns the unmodified JSON received from the API
1414func (r Text) RawJSON() string { return r.JSON.raw }
1415func (r *Text) UnmarshalJSON(data []byte) error {
1416 return apijson.UnmarshalRoot(data, r)
1417}
1418
1419// The text content that is part of a message.
1420type TextContentBlock struct {
1421 Text Text `json:"text,required"`
1422 // Always `text`.
1423 Type constant.Text `json:"type,required"`
1424 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1425 JSON struct {
1426 Text respjson.Field
1427 Type respjson.Field
1428 ExtraFields map[string]respjson.Field
1429 raw string
1430 } `json:"-"`
1431}
1432
1433// Returns the unmodified JSON received from the API
1434func (r TextContentBlock) RawJSON() string { return r.JSON.raw }
1435func (r *TextContentBlock) UnmarshalJSON(data []byte) error {
1436 return apijson.UnmarshalRoot(data, r)
1437}
1438
1439// The text content that is part of a message.
1440//
1441// The properties Text, Type are required.
1442type TextContentBlockParam struct {
1443 // Text content to be sent to the model
1444 Text string `json:"text,required"`
1445 // Always `text`.
1446 //
1447 // This field can be elided, and will marshal its zero value as "text".
1448 Type constant.Text `json:"type,required"`
1449 paramObj
1450}
1451
1452func (r TextContentBlockParam) MarshalJSON() (data []byte, err error) {
1453 type shadow TextContentBlockParam
1454 return param.MarshalObject(r, (*shadow)(&r))
1455}
1456func (r *TextContentBlockParam) UnmarshalJSON(data []byte) error {
1457 return apijson.UnmarshalRoot(data, r)
1458}
1459
1460type TextDelta struct {
1461 Annotations []AnnotationDeltaUnion `json:"annotations"`
1462 // The data that makes up the text.
1463 Value string `json:"value"`
1464 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1465 JSON struct {
1466 Annotations respjson.Field
1467 Value respjson.Field
1468 ExtraFields map[string]respjson.Field
1469 raw string
1470 } `json:"-"`
1471}
1472
1473// Returns the unmodified JSON received from the API
1474func (r TextDelta) RawJSON() string { return r.JSON.raw }
1475func (r *TextDelta) UnmarshalJSON(data []byte) error {
1476 return apijson.UnmarshalRoot(data, r)
1477}
1478
1479// The text content that is part of a message.
1480type TextDeltaBlock struct {
1481 // The index of the content part in the message.
1482 Index int64 `json:"index,required"`
1483 // Always `text`.
1484 Type constant.Text `json:"type,required"`
1485 Text TextDelta `json:"text"`
1486 // JSON contains metadata for fields, check presence with [respjson.Field.Valid].
1487 JSON struct {
1488 Index respjson.Field
1489 Type respjson.Field
1490 Text respjson.Field
1491 ExtraFields map[string]respjson.Field
1492 raw string
1493 } `json:"-"`
1494}
1495
1496// Returns the unmodified JSON received from the API
1497func (r TextDeltaBlock) RawJSON() string { return r.JSON.raw }
1498func (r *TextDeltaBlock) UnmarshalJSON(data []byte) error {
1499 return apijson.UnmarshalRoot(data, r)
1500}
1501
1502type BetaThreadMessageNewParams struct {
1503 // The text contents of the message.
1504 Content BetaThreadMessageNewParamsContentUnion `json:"content,omitzero,required"`
1505 // The role of the entity that is creating the message. Allowed values include:
1506 //
1507 // - `user`: Indicates the message is sent by an actual user and should be used in
1508 // most cases to represent user-generated messages.
1509 // - `assistant`: Indicates the message is generated by the assistant. Use this
1510 // value to insert messages from the assistant into the conversation.
1511 //
1512 // Any of "user", "assistant".
1513 Role BetaThreadMessageNewParamsRole `json:"role,omitzero,required"`
1514 // A list of files attached to the message, and the tools they should be added to.
1515 Attachments []BetaThreadMessageNewParamsAttachment `json:"attachments,omitzero"`
1516 // Set of 16 key-value pairs that can be attached to an object. This can be useful
1517 // for storing additional information about the object in a structured format, and
1518 // querying for objects via API or the dashboard.
1519 //
1520 // Keys are strings with a maximum length of 64 characters. Values are strings with
1521 // a maximum length of 512 characters.
1522 Metadata shared.Metadata `json:"metadata,omitzero"`
1523 paramObj
1524}
1525
1526func (r BetaThreadMessageNewParams) MarshalJSON() (data []byte, err error) {
1527 type shadow BetaThreadMessageNewParams
1528 return param.MarshalObject(r, (*shadow)(&r))
1529}
1530func (r *BetaThreadMessageNewParams) UnmarshalJSON(data []byte) error {
1531 return apijson.UnmarshalRoot(data, r)
1532}
1533
1534// Only one field can be non-zero.
1535//
1536// Use [param.IsOmitted] to confirm if a field is set.
1537type BetaThreadMessageNewParamsContentUnion struct {
1538 OfString param.Opt[string] `json:",omitzero,inline"`
1539 OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
1540 paramUnion
1541}
1542
1543func (u BetaThreadMessageNewParamsContentUnion) MarshalJSON() ([]byte, error) {
1544 return param.MarshalUnion(u, u.OfString, u.OfArrayOfContentParts)
1545}
1546func (u *BetaThreadMessageNewParamsContentUnion) UnmarshalJSON(data []byte) error {
1547 return apijson.UnmarshalRoot(data, u)
1548}
1549
1550func (u *BetaThreadMessageNewParamsContentUnion) asAny() any {
1551 if !param.IsOmitted(u.OfString) {
1552 return &u.OfString.Value
1553 } else if !param.IsOmitted(u.OfArrayOfContentParts) {
1554 return &u.OfArrayOfContentParts
1555 }
1556 return nil
1557}
1558
1559// The role of the entity that is creating the message. Allowed values include:
1560//
1561// - `user`: Indicates the message is sent by an actual user and should be used in
1562// most cases to represent user-generated messages.
1563// - `assistant`: Indicates the message is generated by the assistant. Use this
1564// value to insert messages from the assistant into the conversation.
1565type BetaThreadMessageNewParamsRole string
1566
1567const (
1568 BetaThreadMessageNewParamsRoleUser BetaThreadMessageNewParamsRole = "user"
1569 BetaThreadMessageNewParamsRoleAssistant BetaThreadMessageNewParamsRole = "assistant"
1570)
1571
1572type BetaThreadMessageNewParamsAttachment struct {
1573 // The ID of the file to attach to the message.
1574 FileID param.Opt[string] `json:"file_id,omitzero"`
1575 // The tools to add this file to.
1576 Tools []BetaThreadMessageNewParamsAttachmentToolUnion `json:"tools,omitzero"`
1577 paramObj
1578}
1579
1580func (r BetaThreadMessageNewParamsAttachment) MarshalJSON() (data []byte, err error) {
1581 type shadow BetaThreadMessageNewParamsAttachment
1582 return param.MarshalObject(r, (*shadow)(&r))
1583}
1584func (r *BetaThreadMessageNewParamsAttachment) UnmarshalJSON(data []byte) error {
1585 return apijson.UnmarshalRoot(data, r)
1586}
1587
1588// Only one field can be non-zero.
1589//
1590// Use [param.IsOmitted] to confirm if a field is set.
1591type BetaThreadMessageNewParamsAttachmentToolUnion struct {
1592 OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
1593 OfFileSearch *BetaThreadMessageNewParamsAttachmentToolFileSearch `json:",omitzero,inline"`
1594 paramUnion
1595}
1596
1597func (u BetaThreadMessageNewParamsAttachmentToolUnion) MarshalJSON() ([]byte, error) {
1598 return param.MarshalUnion(u, u.OfCodeInterpreter, u.OfFileSearch)
1599}
1600func (u *BetaThreadMessageNewParamsAttachmentToolUnion) UnmarshalJSON(data []byte) error {
1601 return apijson.UnmarshalRoot(data, u)
1602}
1603
1604func (u *BetaThreadMessageNewParamsAttachmentToolUnion) asAny() any {
1605 if !param.IsOmitted(u.OfCodeInterpreter) {
1606 return u.OfCodeInterpreter
1607 } else if !param.IsOmitted(u.OfFileSearch) {
1608 return u.OfFileSearch
1609 }
1610 return nil
1611}
1612
1613// Returns a pointer to the underlying variant's property, if present.
1614func (u BetaThreadMessageNewParamsAttachmentToolUnion) GetType() *string {
1615 if vt := u.OfCodeInterpreter; vt != nil {
1616 return (*string)(&vt.Type)
1617 } else if vt := u.OfFileSearch; vt != nil {
1618 return (*string)(&vt.Type)
1619 }
1620 return nil
1621}
1622
1623func init() {
1624 apijson.RegisterUnion[BetaThreadMessageNewParamsAttachmentToolUnion](
1625 "type",
1626 apijson.Discriminator[CodeInterpreterToolParam]("code_interpreter"),
1627 apijson.Discriminator[BetaThreadMessageNewParamsAttachmentToolFileSearch]("file_search"),
1628 )
1629}
1630
1631func NewBetaThreadMessageNewParamsAttachmentToolFileSearch() BetaThreadMessageNewParamsAttachmentToolFileSearch {
1632 return BetaThreadMessageNewParamsAttachmentToolFileSearch{
1633 Type: "file_search",
1634 }
1635}
1636
1637// This struct has a constant value, construct it with
1638// [NewBetaThreadMessageNewParamsAttachmentToolFileSearch].
1639type BetaThreadMessageNewParamsAttachmentToolFileSearch struct {
1640 // The type of tool being defined: `file_search`
1641 Type constant.FileSearch `json:"type,required"`
1642 paramObj
1643}
1644
1645func (r BetaThreadMessageNewParamsAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
1646 type shadow BetaThreadMessageNewParamsAttachmentToolFileSearch
1647 return param.MarshalObject(r, (*shadow)(&r))
1648}
1649func (r *BetaThreadMessageNewParamsAttachmentToolFileSearch) UnmarshalJSON(data []byte) error {
1650 return apijson.UnmarshalRoot(data, r)
1651}
1652
1653type BetaThreadMessageUpdateParams struct {
1654 // Set of 16 key-value pairs that can be attached to an object. This can be useful
1655 // for storing additional information about the object in a structured format, and
1656 // querying for objects via API or the dashboard.
1657 //
1658 // Keys are strings with a maximum length of 64 characters. Values are strings with
1659 // a maximum length of 512 characters.
1660 Metadata shared.Metadata `json:"metadata,omitzero"`
1661 paramObj
1662}
1663
1664func (r BetaThreadMessageUpdateParams) MarshalJSON() (data []byte, err error) {
1665 type shadow BetaThreadMessageUpdateParams
1666 return param.MarshalObject(r, (*shadow)(&r))
1667}
1668func (r *BetaThreadMessageUpdateParams) UnmarshalJSON(data []byte) error {
1669 return apijson.UnmarshalRoot(data, r)
1670}
1671
1672type BetaThreadMessageListParams struct {
1673 // A cursor for use in pagination. `after` is an object ID that defines your place
1674 // in the list. For instance, if you make a list request and receive 100 objects,
1675 // ending with obj_foo, your subsequent call can include after=obj_foo in order to
1676 // fetch the next page of the list.
1677 After param.Opt[string] `query:"after,omitzero" json:"-"`
1678 // A cursor for use in pagination. `before` is an object ID that defines your place
1679 // in the list. For instance, if you make a list request and receive 100 objects,
1680 // starting with obj_foo, your subsequent call can include before=obj_foo in order
1681 // to fetch the previous page of the list.
1682 Before param.Opt[string] `query:"before,omitzero" json:"-"`
1683 // A limit on the number of objects to be returned. Limit can range between 1 and
1684 // 100, and the default is 20.
1685 Limit param.Opt[int64] `query:"limit,omitzero" json:"-"`
1686 // Filter messages by the run ID that generated them.
1687 RunID param.Opt[string] `query:"run_id,omitzero" json:"-"`
1688 // Sort order by the `created_at` timestamp of the objects. `asc` for ascending
1689 // order and `desc` for descending order.
1690 //
1691 // Any of "asc", "desc".
1692 Order BetaThreadMessageListParamsOrder `query:"order,omitzero" json:"-"`
1693 paramObj
1694}
1695
1696// URLQuery serializes [BetaThreadMessageListParams]'s query parameters as
1697// `url.Values`.
1698func (r BetaThreadMessageListParams) URLQuery() (v url.Values, err error) {
1699 return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
1700 ArrayFormat: apiquery.ArrayQueryFormatBrackets,
1701 NestedFormat: apiquery.NestedQueryFormatBrackets,
1702 })
1703}
1704
1705// Sort order by the `created_at` timestamp of the objects. `asc` for ascending
1706// order and `desc` for descending order.
1707type BetaThreadMessageListParamsOrder string
1708
1709const (
1710 BetaThreadMessageListParamsOrderAsc BetaThreadMessageListParamsOrder = "asc"
1711 BetaThreadMessageListParamsOrderDesc BetaThreadMessageListParamsOrder = "desc"
1712)