-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathbetathreadmessage.go
1717 lines (1551 loc) · 60.2 KB
/
betathreadmessage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"github.com/openai/openai-go/internal/apijson"
"github.com/openai/openai-go/internal/apiquery"
"github.com/openai/openai-go/internal/requestconfig"
"github.com/openai/openai-go/option"
"github.com/openai/openai-go/packages/pagination"
"github.com/openai/openai-go/packages/param"
"github.com/openai/openai-go/packages/resp"
"github.com/openai/openai-go/shared"
"github.com/openai/openai-go/shared/constant"
"github.com/tidwall/gjson"
)
// BetaThreadMessageService contains methods and other services that help with
// interacting with the openai API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewBetaThreadMessageService] method instead.
type BetaThreadMessageService struct {
Options []option.RequestOption
}
// NewBetaThreadMessageService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewBetaThreadMessageService(opts ...option.RequestOption) (r BetaThreadMessageService) {
r = BetaThreadMessageService{}
r.Options = opts
return
}
// Create a message.
func (r *BetaThreadMessageService) New(ctx context.Context, threadID string, body BetaThreadMessageNewParams, opts ...option.RequestOption) (res *Message, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return
}
path := fmt.Sprintf("threads/%s/messages", threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieve a message.
func (r *BetaThreadMessageService) Get(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *Message, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return
}
if messageID == "" {
err = errors.New("missing required message_id parameter")
return
}
path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Modifies a message.
func (r *BetaThreadMessageService) Update(ctx context.Context, threadID string, messageID string, body BetaThreadMessageUpdateParams, opts ...option.RequestOption) (res *Message, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return
}
if messageID == "" {
err = errors.New("missing required message_id parameter")
return
}
path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Returns a list of messages for a given thread.
func (r *BetaThreadMessageService) List(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Message], err error) {
var raw *http.Response
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithResponseInto(&raw)}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return
}
path := fmt.Sprintf("threads/%s/messages", threadID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// Returns a list of messages for a given thread.
func (r *BetaThreadMessageService) ListAutoPaging(ctx context.Context, threadID string, query BetaThreadMessageListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Message] {
return pagination.NewCursorPageAutoPager(r.List(ctx, threadID, query, opts...))
}
// Deletes a message.
func (r *BetaThreadMessageService) Delete(ctx context.Context, threadID string, messageID string, opts ...option.RequestOption) (res *MessageDeleted, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return
}
if messageID == "" {
err = errors.New("missing required message_id parameter")
return
}
path := fmt.Sprintf("threads/%s/messages/%s", threadID, messageID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// AnnotationUnion contains all possible properties and values from
// [FileCitationAnnotation], [FilePathAnnotation].
//
// Use the [AnnotationUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type AnnotationUnion struct {
EndIndex int64 `json:"end_index"`
// This field is from variant [FileCitationAnnotation].
FileCitation FileCitationAnnotationFileCitation `json:"file_citation"`
StartIndex int64 `json:"start_index"`
Text string `json:"text"`
// Any of "file_citation", "file_path".
Type string `json:"type"`
// This field is from variant [FilePathAnnotation].
FilePath FilePathAnnotationFilePath `json:"file_path"`
JSON struct {
EndIndex resp.Field
FileCitation resp.Field
StartIndex resp.Field
Text resp.Field
Type resp.Field
FilePath resp.Field
raw string
} `json:"-"`
}
// Use the following switch statement to find the correct variant
//
// switch variant := AnnotationUnion.AsAny().(type) {
// case FileCitationAnnotation:
// case FilePathAnnotation:
// default:
// fmt.Errorf("no variant present")
// }
func (u AnnotationUnion) AsAny() any {
switch u.Type {
case "file_citation":
return u.AsFileCitation()
case "file_path":
return u.AsFilePath()
}
return nil
}
func (u AnnotationUnion) AsFileCitation() (v FileCitationAnnotation) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AnnotationUnion) AsFilePath() (v FilePathAnnotation) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u AnnotationUnion) RawJSON() string { return u.JSON.raw }
func (r *AnnotationUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// AnnotationDeltaUnion contains all possible properties and values from
// [FileCitationDeltaAnnotation], [FilePathDeltaAnnotation].
//
// Use the [AnnotationDeltaUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type AnnotationDeltaUnion struct {
Index int64 `json:"index"`
// Any of "file_citation", "file_path".
Type string `json:"type"`
EndIndex int64 `json:"end_index"`
// This field is from variant [FileCitationDeltaAnnotation].
FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
StartIndex int64 `json:"start_index"`
Text string `json:"text"`
// This field is from variant [FilePathDeltaAnnotation].
FilePath FilePathDeltaAnnotationFilePath `json:"file_path"`
JSON struct {
Index resp.Field
Type resp.Field
EndIndex resp.Field
FileCitation resp.Field
StartIndex resp.Field
Text resp.Field
FilePath resp.Field
raw string
} `json:"-"`
}
// Use the following switch statement to find the correct variant
//
// switch variant := AnnotationDeltaUnion.AsAny().(type) {
// case FileCitationDeltaAnnotation:
// case FilePathDeltaAnnotation:
// default:
// fmt.Errorf("no variant present")
// }
func (u AnnotationDeltaUnion) AsAny() any {
switch u.Type {
case "file_citation":
return u.AsFileCitation()
case "file_path":
return u.AsFilePath()
}
return nil
}
func (u AnnotationDeltaUnion) AsFileCitation() (v FileCitationDeltaAnnotation) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AnnotationDeltaUnion) AsFilePath() (v FilePathDeltaAnnotation) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u AnnotationDeltaUnion) RawJSON() string { return u.JSON.raw }
func (r *AnnotationDeltaUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A citation within the message that points to a specific quote from a specific
// File associated with the assistant or the message. Generated when the assistant
// uses the "file_search" tool to search files.
type FileCitationAnnotation struct {
EndIndex int64 `json:"end_index,required"`
FileCitation FileCitationAnnotationFileCitation `json:"file_citation,required"`
StartIndex int64 `json:"start_index,required"`
// The text in the message content that needs to be replaced.
Text string `json:"text,required"`
// Always `file_citation`.
Type constant.FileCitation `json:"type,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
EndIndex resp.Field
FileCitation resp.Field
StartIndex resp.Field
Text resp.Field
Type resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FileCitationAnnotation) RawJSON() string { return r.JSON.raw }
func (r *FileCitationAnnotation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FileCitationAnnotationFileCitation struct {
// The ID of the specific File the citation is from.
FileID string `json:"file_id,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
FileID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FileCitationAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
func (r *FileCitationAnnotationFileCitation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A citation within the message that points to a specific quote from a specific
// File associated with the assistant or the message. Generated when the assistant
// uses the "file_search" tool to search files.
type FileCitationDeltaAnnotation struct {
// The index of the annotation in the text content part.
Index int64 `json:"index,required"`
// Always `file_citation`.
Type constant.FileCitation `json:"type,required"`
EndIndex int64 `json:"end_index"`
FileCitation FileCitationDeltaAnnotationFileCitation `json:"file_citation"`
StartIndex int64 `json:"start_index"`
// The text in the message content that needs to be replaced.
Text string `json:"text"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Index resp.Field
Type resp.Field
EndIndex resp.Field
FileCitation resp.Field
StartIndex resp.Field
Text resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FileCitationDeltaAnnotation) RawJSON() string { return r.JSON.raw }
func (r *FileCitationDeltaAnnotation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FileCitationDeltaAnnotationFileCitation struct {
// The ID of the specific File the citation is from.
FileID string `json:"file_id"`
// The specific quote in the file.
Quote string `json:"quote"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
FileID resp.Field
Quote resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FileCitationDeltaAnnotationFileCitation) RawJSON() string { return r.JSON.raw }
func (r *FileCitationDeltaAnnotationFileCitation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A URL for the file that's generated when the assistant used the
// `code_interpreter` tool to generate a file.
type FilePathAnnotation struct {
EndIndex int64 `json:"end_index,required"`
FilePath FilePathAnnotationFilePath `json:"file_path,required"`
StartIndex int64 `json:"start_index,required"`
// The text in the message content that needs to be replaced.
Text string `json:"text,required"`
// Always `file_path`.
Type constant.FilePath `json:"type,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
EndIndex resp.Field
FilePath resp.Field
StartIndex resp.Field
Text resp.Field
Type resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FilePathAnnotation) RawJSON() string { return r.JSON.raw }
func (r *FilePathAnnotation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FilePathAnnotationFilePath struct {
// The ID of the file that was generated.
FileID string `json:"file_id,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
FileID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FilePathAnnotationFilePath) RawJSON() string { return r.JSON.raw }
func (r *FilePathAnnotationFilePath) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A URL for the file that's generated when the assistant used the
// `code_interpreter` tool to generate a file.
type FilePathDeltaAnnotation struct {
// The index of the annotation in the text content part.
Index int64 `json:"index,required"`
// Always `file_path`.
Type constant.FilePath `json:"type,required"`
EndIndex int64 `json:"end_index"`
FilePath FilePathDeltaAnnotationFilePath `json:"file_path"`
StartIndex int64 `json:"start_index"`
// The text in the message content that needs to be replaced.
Text string `json:"text"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Index resp.Field
Type resp.Field
EndIndex resp.Field
FilePath resp.Field
StartIndex resp.Field
Text resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FilePathDeltaAnnotation) RawJSON() string { return r.JSON.raw }
func (r *FilePathDeltaAnnotation) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type FilePathDeltaAnnotationFilePath struct {
// The ID of the file that was generated.
FileID string `json:"file_id"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
FileID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r FilePathDeltaAnnotationFilePath) RawJSON() string { return r.JSON.raw }
func (r *FilePathDeltaAnnotationFilePath) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ImageFile struct {
// The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
// in the message content. Set `purpose="vision"` when uploading the File if you
// need to later display the file content.
FileID string `json:"file_id,required"`
// Specifies the detail level of the image if specified by the user. `low` uses
// fewer tokens, you can opt in to high resolution using `high`.
//
// Any of "auto", "low", "high".
Detail ImageFileDetail `json:"detail"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
FileID resp.Field
Detail resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageFile) RawJSON() string { return r.JSON.raw }
func (r *ImageFile) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this ImageFile to a ImageFileParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ImageFileParam.IsOverridden()
func (r ImageFile) ToParam() ImageFileParam {
return param.OverrideObj[ImageFileParam](r.RawJSON())
}
// Specifies the detail level of the image if specified by the user. `low` uses
// fewer tokens, you can opt in to high resolution using `high`.
type ImageFileDetail string
const (
ImageFileDetailAuto ImageFileDetail = "auto"
ImageFileDetailLow ImageFileDetail = "low"
ImageFileDetailHigh ImageFileDetail = "high"
)
// The property FileID is required.
type ImageFileParam struct {
// The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
// in the message content. Set `purpose="vision"` when uploading the File if you
// need to later display the file content.
FileID string `json:"file_id,required"`
// Specifies the detail level of the image if specified by the user. `low` uses
// fewer tokens, you can opt in to high resolution using `high`.
//
// Any of "auto", "low", "high".
Detail ImageFileDetail `json:"detail,omitzero"`
paramObj
}
// IsPresent returns true if the field's value is not omitted and not the JSON
// "null". To check if this field is omitted, use [param.IsOmitted].
func (f ImageFileParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r ImageFileParam) MarshalJSON() (data []byte, err error) {
type shadow ImageFileParam
return param.MarshalObject(r, (*shadow)(&r))
}
// References an image [File](https://platform.openai.com/docs/api-reference/files)
// in the content of a message.
type ImageFileContentBlock struct {
ImageFile ImageFile `json:"image_file,required"`
// Always `image_file`.
Type constant.ImageFile `json:"type,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ImageFile resp.Field
Type resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageFileContentBlock) RawJSON() string { return r.JSON.raw }
func (r *ImageFileContentBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this ImageFileContentBlock to a ImageFileContentBlockParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ImageFileContentBlockParam.IsOverridden()
func (r ImageFileContentBlock) ToParam() ImageFileContentBlockParam {
return param.OverrideObj[ImageFileContentBlockParam](r.RawJSON())
}
// References an image [File](https://platform.openai.com/docs/api-reference/files)
// in the content of a message.
//
// The properties ImageFile, Type are required.
type ImageFileContentBlockParam struct {
ImageFile ImageFileParam `json:"image_file,omitzero,required"`
// Always `image_file`.
//
// This field can be elided, and will marshal its zero value as "image_file".
Type constant.ImageFile `json:"type,required"`
paramObj
}
// IsPresent returns true if the field's value is not omitted and not the JSON
// "null". To check if this field is omitted, use [param.IsOmitted].
func (f ImageFileContentBlockParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r ImageFileContentBlockParam) MarshalJSON() (data []byte, err error) {
type shadow ImageFileContentBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
type ImageFileDelta struct {
// Specifies the detail level of the image if specified by the user. `low` uses
// fewer tokens, you can opt in to high resolution using `high`.
//
// Any of "auto", "low", "high".
Detail ImageFileDeltaDetail `json:"detail"`
// The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
// in the message content. Set `purpose="vision"` when uploading the File if you
// need to later display the file content.
FileID string `json:"file_id"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Detail resp.Field
FileID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageFileDelta) RawJSON() string { return r.JSON.raw }
func (r *ImageFileDelta) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Specifies the detail level of the image if specified by the user. `low` uses
// fewer tokens, you can opt in to high resolution using `high`.
type ImageFileDeltaDetail string
const (
ImageFileDeltaDetailAuto ImageFileDeltaDetail = "auto"
ImageFileDeltaDetailLow ImageFileDeltaDetail = "low"
ImageFileDeltaDetailHigh ImageFileDeltaDetail = "high"
)
// References an image [File](https://platform.openai.com/docs/api-reference/files)
// in the content of a message.
type ImageFileDeltaBlock struct {
// The index of the content part in the message.
Index int64 `json:"index,required"`
// Always `image_file`.
Type constant.ImageFile `json:"type,required"`
ImageFile ImageFileDelta `json:"image_file"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Index resp.Field
Type resp.Field
ImageFile resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageFileDeltaBlock) RawJSON() string { return r.JSON.raw }
func (r *ImageFileDeltaBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ImageURL struct {
// The external URL of the image, must be a supported image types: jpeg, jpg, png,
// gif, webp.
URL string `json:"url,required" format:"uri"`
// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
// to high resolution using `high`. Default value is `auto`
//
// Any of "auto", "low", "high".
Detail ImageURLDetail `json:"detail"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
URL resp.Field
Detail resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageURL) RawJSON() string { return r.JSON.raw }
func (r *ImageURL) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this ImageURL to a ImageURLParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ImageURLParam.IsOverridden()
func (r ImageURL) ToParam() ImageURLParam {
return param.OverrideObj[ImageURLParam](r.RawJSON())
}
// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
// to high resolution using `high`. Default value is `auto`
type ImageURLDetail string
const (
ImageURLDetailAuto ImageURLDetail = "auto"
ImageURLDetailLow ImageURLDetail = "low"
ImageURLDetailHigh ImageURLDetail = "high"
)
// The property URL is required.
type ImageURLParam struct {
// The external URL of the image, must be a supported image types: jpeg, jpg, png,
// gif, webp.
URL string `json:"url,required" format:"uri"`
// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
// to high resolution using `high`. Default value is `auto`
//
// Any of "auto", "low", "high".
Detail ImageURLDetail `json:"detail,omitzero"`
paramObj
}
// IsPresent returns true if the field's value is not omitted and not the JSON
// "null". To check if this field is omitted, use [param.IsOmitted].
func (f ImageURLParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r ImageURLParam) MarshalJSON() (data []byte, err error) {
type shadow ImageURLParam
return param.MarshalObject(r, (*shadow)(&r))
}
// References an image URL in the content of a message.
type ImageURLContentBlock struct {
ImageURL ImageURL `json:"image_url,required"`
// The type of the content part.
Type constant.ImageURL `json:"type,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ImageURL resp.Field
Type resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageURLContentBlock) RawJSON() string { return r.JSON.raw }
func (r *ImageURLContentBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this ImageURLContentBlock to a ImageURLContentBlockParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// ImageURLContentBlockParam.IsOverridden()
func (r ImageURLContentBlock) ToParam() ImageURLContentBlockParam {
return param.OverrideObj[ImageURLContentBlockParam](r.RawJSON())
}
// References an image URL in the content of a message.
//
// The properties ImageURL, Type are required.
type ImageURLContentBlockParam struct {
ImageURL ImageURLParam `json:"image_url,omitzero,required"`
// The type of the content part.
//
// This field can be elided, and will marshal its zero value as "image_url".
Type constant.ImageURL `json:"type,required"`
paramObj
}
// IsPresent returns true if the field's value is not omitted and not the JSON
// "null". To check if this field is omitted, use [param.IsOmitted].
func (f ImageURLContentBlockParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r ImageURLContentBlockParam) MarshalJSON() (data []byte, err error) {
type shadow ImageURLContentBlockParam
return param.MarshalObject(r, (*shadow)(&r))
}
type ImageURLDelta struct {
// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
// to high resolution using `high`.
//
// Any of "auto", "low", "high".
Detail ImageURLDeltaDetail `json:"detail"`
// The URL of the image, must be a supported image types: jpeg, jpg, png, gif,
// webp.
URL string `json:"url"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Detail resp.Field
URL resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageURLDelta) RawJSON() string { return r.JSON.raw }
func (r *ImageURLDelta) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Specifies the detail level of the image. `low` uses fewer tokens, you can opt in
// to high resolution using `high`.
type ImageURLDeltaDetail string
const (
ImageURLDeltaDetailAuto ImageURLDeltaDetail = "auto"
ImageURLDeltaDetailLow ImageURLDeltaDetail = "low"
ImageURLDeltaDetailHigh ImageURLDeltaDetail = "high"
)
// References an image URL in the content of a message.
type ImageURLDeltaBlock struct {
// The index of the content part in the message.
Index int64 `json:"index,required"`
// Always `image_url`.
Type constant.ImageURL `json:"type,required"`
ImageURL ImageURLDelta `json:"image_url"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Index resp.Field
Type resp.Field
ImageURL resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ImageURLDeltaBlock) RawJSON() string { return r.JSON.raw }
func (r *ImageURLDeltaBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Represents a message within a
// [thread](https://platform.openai.com/docs/api-reference/threads).
type Message struct {
// The identifier, which can be referenced in API endpoints.
ID string `json:"id,required"`
// If applicable, the ID of the
// [assistant](https://platform.openai.com/docs/api-reference/assistants) that
// authored this message.
AssistantID string `json:"assistant_id,required"`
// A list of files attached to the message, and the tools they were added to.
Attachments []MessageAttachment `json:"attachments,required"`
// The Unix timestamp (in seconds) for when the message was completed.
CompletedAt int64 `json:"completed_at,required"`
// The content of the message in array of text and/or images.
Content []MessageContentUnion `json:"content,required"`
// The Unix timestamp (in seconds) for when the message was created.
CreatedAt int64 `json:"created_at,required"`
// The Unix timestamp (in seconds) for when the message was marked as incomplete.
IncompleteAt int64 `json:"incomplete_at,required"`
// On an incomplete message, details about why the message is incomplete.
IncompleteDetails MessageIncompleteDetails `json:"incomplete_details,required"`
// Set of 16 key-value pairs that can be attached to an object. This can be useful
// for storing additional information about the object in a structured format, and
// querying for objects via API or the dashboard.
//
// Keys are strings with a maximum length of 64 characters. Values are strings with
// a maximum length of 512 characters.
Metadata shared.Metadata `json:"metadata,required"`
// The object type, which is always `thread.message`.
Object constant.ThreadMessage `json:"object,required"`
// The entity that produced the message. One of `user` or `assistant`.
//
// Any of "user", "assistant".
Role MessageRole `json:"role,required"`
// The ID of the [run](https://platform.openai.com/docs/api-reference/runs)
// associated with the creation of this message. Value is `null` when messages are
// created manually using the create message or create thread endpoints.
RunID string `json:"run_id,required"`
// The status of the message, which can be either `in_progress`, `incomplete`, or
// `completed`.
//
// Any of "in_progress", "incomplete", "completed".
Status MessageStatus `json:"status,required"`
// The [thread](https://platform.openai.com/docs/api-reference/threads) ID that
// this message belongs to.
ThreadID string `json:"thread_id,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
AssistantID resp.Field
Attachments resp.Field
CompletedAt resp.Field
Content resp.Field
CreatedAt resp.Field
IncompleteAt resp.Field
IncompleteDetails resp.Field
Metadata resp.Field
Object resp.Field
Role resp.Field
RunID resp.Field
Status resp.Field
ThreadID resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r Message) RawJSON() string { return r.JSON.raw }
func (r *Message) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type MessageAttachment struct {
// The ID of the file to attach to the message.
FileID string `json:"file_id"`
// The tools to add this file to.
Tools []MessageAttachmentToolUnion `json:"tools"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
FileID resp.Field
Tools resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r MessageAttachment) RawJSON() string { return r.JSON.raw }
func (r *MessageAttachment) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// MessageAttachmentToolUnion contains all possible properties and values from
// [CodeInterpreterTool], [MessageAttachmentToolAssistantToolsFileSearchTypeOnly].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type MessageAttachmentToolUnion struct {
Type string `json:"type"`
JSON struct {
Type resp.Field
raw string
} `json:"-"`
}
func (u MessageAttachmentToolUnion) AsCodeInterpreterTool() (v CodeInterpreterTool) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u MessageAttachmentToolUnion) AsFileSearchTool() (v MessageAttachmentToolAssistantToolsFileSearchTypeOnly) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u MessageAttachmentToolUnion) RawJSON() string { return u.JSON.raw }
func (r *MessageAttachmentToolUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type MessageAttachmentToolAssistantToolsFileSearchTypeOnly struct {
// The type of tool being defined: `file_search`
Type constant.FileSearch `json:"type,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Type resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r MessageAttachmentToolAssistantToolsFileSearchTypeOnly) RawJSON() string { return r.JSON.raw }
func (r *MessageAttachmentToolAssistantToolsFileSearchTypeOnly) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// On an incomplete message, details about why the message is incomplete.
type MessageIncompleteDetails struct {
// The reason the message is incomplete.
//
// Any of "content_filter", "max_tokens", "run_cancelled", "run_expired",
// "run_failed".
Reason string `json:"reason,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Reason resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r MessageIncompleteDetails) RawJSON() string { return r.JSON.raw }
func (r *MessageIncompleteDetails) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The entity that produced the message. One of `user` or `assistant`.
type MessageRole string
const (
MessageRoleUser MessageRole = "user"
MessageRoleAssistant MessageRole = "assistant"
)
// The status of the message, which can be either `in_progress`, `incomplete`, or
// `completed`.
type MessageStatus string
const (
MessageStatusInProgress MessageStatus = "in_progress"
MessageStatusIncomplete MessageStatus = "incomplete"
MessageStatusCompleted MessageStatus = "completed"
)
// MessageContentUnion contains all possible properties and values from
// [ImageFileContentBlock], [ImageURLContentBlock], [TextContentBlock],
// [RefusalContentBlock].
//