-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathbetathread.go
1710 lines (1547 loc) · 72.7 KB
/
betathread.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"
"reflect"
"github.com/openai/openai-go/internal/apijson"
"github.com/openai/openai-go/internal/requestconfig"
"github.com/openai/openai-go/option"
"github.com/openai/openai-go/packages/param"
"github.com/openai/openai-go/packages/resp"
"github.com/openai/openai-go/packages/ssestream"
"github.com/openai/openai-go/shared"
"github.com/openai/openai-go/shared/constant"
"github.com/tidwall/gjson"
)
// BetaThreadService 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 [NewBetaThreadService] method instead.
type BetaThreadService struct {
Options []option.RequestOption
Runs BetaThreadRunService
Messages BetaThreadMessageService
}
// NewBetaThreadService 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 NewBetaThreadService(opts ...option.RequestOption) (r BetaThreadService) {
r = BetaThreadService{}
r.Options = opts
r.Runs = NewBetaThreadRunService(opts...)
r.Messages = NewBetaThreadMessageService(opts...)
return
}
// Create a thread.
func (r *BetaThreadService) New(ctx context.Context, body BetaThreadNewParams, opts ...option.RequestOption) (res *Thread, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
path := "threads"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Create a thread and run it in one request. Poll the API until the run is complete.
func (r *BetaThreadService) NewAndRunPoll(ctx context.Context, body BetaThreadNewAndRunParams, pollIntervalMs int, opts ...option.RequestOption) (res *Run, err error) {
run, err := r.NewAndRun(ctx, body, opts...)
if err != nil {
return nil, err
}
return r.Runs.PollStatus(ctx, run.ThreadID, run.ID, pollIntervalMs, opts...)
}
// Retrieves a thread.
func (r *BetaThreadService) Get(ctx context.Context, threadID string, opts ...option.RequestOption) (res *Thread, 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", threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Modifies a thread.
func (r *BetaThreadService) Update(ctx context.Context, threadID string, body BetaThreadUpdateParams, opts ...option.RequestOption) (res *Thread, 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", threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Delete a thread.
func (r *BetaThreadService) Delete(ctx context.Context, threadID string, opts ...option.RequestOption) (res *ThreadDeleted, 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", threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Create a thread and run it in one request.
func (r *BetaThreadService) NewAndRun(ctx context.Context, body BetaThreadNewAndRunParams, opts ...option.RequestOption) (res *Run, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
path := "threads/runs"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Create a thread and run it in one request.
func (r *BetaThreadService) NewAndRunStreaming(ctx context.Context, body BetaThreadNewAndRunParams, opts ...option.RequestOption) (stream *ssestream.Stream[AssistantStreamEventUnion]) {
var (
raw *http.Response
err error
)
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2"), option.WithJSONSet("stream", true)}, opts...)
path := "threads/runs"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &raw, opts...)
return ssestream.NewStream[AssistantStreamEventUnion](ssestream.NewDecoder(raw), err)
}
// AssistantResponseFormatOptionUnion contains all possible properties and values
// from [constant.Auto], [shared.ResponseFormatText],
// [shared.ResponseFormatJSONObject], [shared.ResponseFormatJSONSchema].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto]
type AssistantResponseFormatOptionUnion struct {
// This field will be present if the value is a [constant.Auto] instead of an
// object.
OfAuto constant.Auto `json:",inline"`
Type string `json:"type"`
// This field is from variant [shared.ResponseFormatJSONSchema].
JSONSchema shared.ResponseFormatJSONSchemaJSONSchema `json:"json_schema"`
JSON struct {
OfAuto resp.Field
Type resp.Field
JSONSchema resp.Field
raw string
} `json:"-"`
}
func (u AssistantResponseFormatOptionUnion) AsAuto() (v constant.Auto) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantResponseFormatOptionUnion) AsText() (v shared.ResponseFormatText) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantResponseFormatOptionUnion) AsJSONObject() (v shared.ResponseFormatJSONObject) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantResponseFormatOptionUnion) AsJSONSchema() (v shared.ResponseFormatJSONSchema) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u AssistantResponseFormatOptionUnion) RawJSON() string { return u.JSON.raw }
func (r *AssistantResponseFormatOptionUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this AssistantResponseFormatOptionUnion to a
// AssistantResponseFormatOptionUnionParam.
//
// 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
// AssistantResponseFormatOptionUnionParam.IsOverridden()
func (r AssistantResponseFormatOptionUnion) ToParam() AssistantResponseFormatOptionUnionParam {
return param.OverrideObj[AssistantResponseFormatOptionUnionParam](r.RawJSON())
}
func AssistantResponseFormatOptionParamOfAuto() AssistantResponseFormatOptionUnionParam {
return AssistantResponseFormatOptionUnionParam{OfAuto: constant.ValueOf[constant.Auto]()}
}
func AssistantResponseFormatOptionParamOfJSONSchema(jsonSchema shared.ResponseFormatJSONSchemaJSONSchemaParam) AssistantResponseFormatOptionUnionParam {
var variant shared.ResponseFormatJSONSchemaParam
variant.JSONSchema = jsonSchema
return AssistantResponseFormatOptionUnionParam{OfJSONSchema: &variant}
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type AssistantResponseFormatOptionUnionParam struct {
// Construct this variant with constant.New[constant.Auto]() Check if union is this
// variant with !param.IsOmitted(union.OfAuto)
OfAuto constant.Auto `json:",omitzero,inline"`
OfText *shared.ResponseFormatTextParam `json:",omitzero,inline"`
OfJSONObject *shared.ResponseFormatJSONObjectParam `json:",omitzero,inline"`
OfJSONSchema *shared.ResponseFormatJSONSchemaParam `json:",omitzero,inline"`
paramUnion
}
// 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 (u AssistantResponseFormatOptionUnionParam) IsPresent() bool {
return !param.IsOmitted(u) && !u.IsNull()
}
func (u AssistantResponseFormatOptionUnionParam) MarshalJSON() ([]byte, error) {
return param.MarshalUnion[AssistantResponseFormatOptionUnionParam](u.OfAuto, u.OfText, u.OfJSONObject, u.OfJSONSchema)
}
func (u *AssistantResponseFormatOptionUnionParam) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfText) {
return u.OfText
} else if !param.IsOmitted(u.OfJSONObject) {
return u.OfJSONObject
} else if !param.IsOmitted(u.OfJSONSchema) {
return u.OfJSONSchema
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u AssistantResponseFormatOptionUnionParam) GetJSONSchema() *shared.ResponseFormatJSONSchemaJSONSchemaParam {
if vt := u.OfJSONSchema; vt != nil {
return &vt.JSONSchema
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u AssistantResponseFormatOptionUnionParam) GetType() *string {
if vt := u.OfText; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfJSONObject; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfJSONSchema; vt != nil {
return (*string)(&vt.Type)
}
return nil
}
// Specifies a tool the model should use. Use to force the model to call a specific
// tool.
type AssistantToolChoice struct {
// The type of the tool. If type is `function`, the function name must be set
//
// Any of "function", "code_interpreter", "file_search".
Type AssistantToolChoiceType `json:"type,required"`
Function AssistantToolChoiceFunction `json:"function"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Type resp.Field
Function resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantToolChoice) RawJSON() string { return r.JSON.raw }
func (r *AssistantToolChoice) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this AssistantToolChoice to a AssistantToolChoiceParam.
//
// 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
// AssistantToolChoiceParam.IsOverridden()
func (r AssistantToolChoice) ToParam() AssistantToolChoiceParam {
return param.OverrideObj[AssistantToolChoiceParam](r.RawJSON())
}
// The type of the tool. If type is `function`, the function name must be set
type AssistantToolChoiceType string
const (
AssistantToolChoiceTypeFunction AssistantToolChoiceType = "function"
AssistantToolChoiceTypeCodeInterpreter AssistantToolChoiceType = "code_interpreter"
AssistantToolChoiceTypeFileSearch AssistantToolChoiceType = "file_search"
)
// Specifies a tool the model should use. Use to force the model to call a specific
// tool.
//
// The property Type is required.
type AssistantToolChoiceParam struct {
// The type of the tool. If type is `function`, the function name must be set
//
// Any of "function", "code_interpreter", "file_search".
Type AssistantToolChoiceType `json:"type,omitzero,required"`
Function AssistantToolChoiceFunctionParam `json:"function,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 AssistantToolChoiceParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r AssistantToolChoiceParam) MarshalJSON() (data []byte, err error) {
type shadow AssistantToolChoiceParam
return param.MarshalObject(r, (*shadow)(&r))
}
type AssistantToolChoiceFunction struct {
// The name of the function to call.
Name string `json:"name,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Name resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantToolChoiceFunction) RawJSON() string { return r.JSON.raw }
func (r *AssistantToolChoiceFunction) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this AssistantToolChoiceFunction to a
// AssistantToolChoiceFunctionParam.
//
// 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
// AssistantToolChoiceFunctionParam.IsOverridden()
func (r AssistantToolChoiceFunction) ToParam() AssistantToolChoiceFunctionParam {
return param.OverrideObj[AssistantToolChoiceFunctionParam](r.RawJSON())
}
// The property Name is required.
type AssistantToolChoiceFunctionParam struct {
// The name of the function to call.
Name string `json:"name,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 AssistantToolChoiceFunctionParam) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r AssistantToolChoiceFunctionParam) MarshalJSON() (data []byte, err error) {
type shadow AssistantToolChoiceFunctionParam
return param.MarshalObject(r, (*shadow)(&r))
}
// AssistantToolChoiceOptionUnion contains all possible properties and values from
// [string], [AssistantToolChoice].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfAuto]
type AssistantToolChoiceOptionUnion struct {
// This field will be present if the value is a [string] instead of an object.
OfAuto string `json:",inline"`
// This field is from variant [AssistantToolChoice].
Type AssistantToolChoiceType `json:"type"`
// This field is from variant [AssistantToolChoice].
Function AssistantToolChoiceFunction `json:"function"`
JSON struct {
OfAuto resp.Field
Type resp.Field
Function resp.Field
raw string
} `json:"-"`
}
func (u AssistantToolChoiceOptionUnion) AsAuto() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantToolChoiceOptionUnion) AsAssistantToolChoice() (v AssistantToolChoice) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u AssistantToolChoiceOptionUnion) RawJSON() string { return u.JSON.raw }
func (r *AssistantToolChoiceOptionUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this AssistantToolChoiceOptionUnion to a
// AssistantToolChoiceOptionUnionParam.
//
// 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
// AssistantToolChoiceOptionUnionParam.IsOverridden()
func (r AssistantToolChoiceOptionUnion) ToParam() AssistantToolChoiceOptionUnionParam {
return param.OverrideObj[AssistantToolChoiceOptionUnionParam](r.RawJSON())
}
func AssistantToolChoiceOptionParamOfAssistantToolChoice(type_ AssistantToolChoiceType) AssistantToolChoiceOptionUnionParam {
var variant AssistantToolChoiceParam
variant.Type = type_
return AssistantToolChoiceOptionUnionParam{OfAssistantToolChoice: &variant}
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type AssistantToolChoiceOptionUnionParam struct {
// Check if union is this variant with !param.IsOmitted(union.OfAuto)
OfAuto param.Opt[string] `json:",omitzero,inline"`
OfAssistantToolChoice *AssistantToolChoiceParam `json:",omitzero,inline"`
paramUnion
}
// 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 (u AssistantToolChoiceOptionUnionParam) IsPresent() bool {
return !param.IsOmitted(u) && !u.IsNull()
}
func (u AssistantToolChoiceOptionUnionParam) MarshalJSON() ([]byte, error) {
return param.MarshalUnion[AssistantToolChoiceOptionUnionParam](u.OfAuto, u.OfAssistantToolChoice)
}
func (u *AssistantToolChoiceOptionUnionParam) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return &u.OfAuto
} else if !param.IsOmitted(u.OfAssistantToolChoice) {
return u.OfAssistantToolChoice
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u AssistantToolChoiceOptionUnionParam) GetType() *string {
if vt := u.OfAssistantToolChoice; vt != nil {
return (*string)(&vt.Type)
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u AssistantToolChoiceOptionUnionParam) GetFunction() *AssistantToolChoiceFunctionParam {
if vt := u.OfAssistantToolChoice; vt != nil {
return &vt.Function
}
return nil
}
// Represents a thread that contains
// [messages](https://platform.openai.com/docs/api-reference/messages).
type Thread struct {
// The identifier, which can be referenced in API endpoints.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the thread was created.
CreatedAt int64 `json:"created_at,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`.
Object constant.Thread `json:"object,required"`
// A set of resources that are made available to the assistant's tools in this
// thread. The resources are specific to the type of tool. For example, the
// `code_interpreter` tool requires a list of file IDs, while the `file_search`
// tool requires a list of vector store IDs.
ToolResources ThreadToolResources `json:"tool_resources,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
CreatedAt resp.Field
Metadata resp.Field
Object resp.Field
ToolResources resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r Thread) RawJSON() string { return r.JSON.raw }
func (r *Thread) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A set of resources that are made available to the assistant's tools in this
// thread. The resources are specific to the type of tool. For example, the
// `code_interpreter` tool requires a list of file IDs, while the `file_search`
// tool requires a list of vector store IDs.
type ThreadToolResources struct {
CodeInterpreter ThreadToolResourcesCodeInterpreter `json:"code_interpreter"`
FileSearch ThreadToolResourcesFileSearch `json:"file_search"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
CodeInterpreter resp.Field
FileSearch resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ThreadToolResources) RawJSON() string { return r.JSON.raw }
func (r *ThreadToolResources) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ThreadToolResourcesCodeInterpreter struct {
// A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
// available to the `code_interpreter` tool. There can be a maximum of 20 files
// associated with the tool.
FileIDs []string `json:"file_ids"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
FileIDs resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ThreadToolResourcesCodeInterpreter) RawJSON() string { return r.JSON.raw }
func (r *ThreadToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ThreadToolResourcesFileSearch struct {
// The
// [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
// attached to this thread. There can be a maximum of 1 vector store attached to
// the thread.
VectorStoreIDs []string `json:"vector_store_ids"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
VectorStoreIDs resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ThreadToolResourcesFileSearch) RawJSON() string { return r.JSON.raw }
func (r *ThreadToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ThreadDeleted struct {
ID string `json:"id,required"`
Deleted bool `json:"deleted,required"`
Object constant.ThreadDeleted `json:"object,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
Deleted resp.Field
Object resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ThreadDeleted) RawJSON() string { return r.JSON.raw }
func (r *ThreadDeleted) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaThreadNewParams struct {
// 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.MetadataParam `json:"metadata,omitzero"`
// A set of resources that are made available to the assistant's tools in this
// thread. The resources are specific to the type of tool. For example, the
// `code_interpreter` tool requires a list of file IDs, while the `file_search`
// tool requires a list of vector store IDs.
ToolResources BetaThreadNewParamsToolResources `json:"tool_resources,omitzero"`
// A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
// start the thread with.
Messages []BetaThreadNewParamsMessage `json:"messages,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 BetaThreadNewParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r BetaThreadNewParams) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
// The properties Content, Role are required.
type BetaThreadNewParamsMessage struct {
// The text contents of the message.
Content BetaThreadNewParamsMessageContentUnion `json:"content,omitzero,required"`
// The role of the entity that is creating the message. Allowed values include:
//
// - `user`: Indicates the message is sent by an actual user and should be used in
// most cases to represent user-generated messages.
// - `assistant`: Indicates the message is generated by the assistant. Use this
// value to insert messages from the assistant into the conversation.
//
// Any of "user", "assistant".
Role string `json:"role,omitzero,required"`
// A list of files attached to the message, and the tools they should be added to.
Attachments []BetaThreadNewParamsMessageAttachment `json:"attachments,omitzero"`
// 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.MetadataParam `json:"metadata,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 BetaThreadNewParamsMessage) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r BetaThreadNewParamsMessage) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsMessage
return param.MarshalObject(r, (*shadow)(&r))
}
func init() {
apijson.RegisterFieldValidator[BetaThreadNewParamsMessage](
"Role", false, "user", "assistant",
)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type BetaThreadNewParamsMessageContentUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfArrayOfContentParts []MessageContentPartParamUnion `json:",omitzero,inline"`
paramUnion
}
// 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 (u BetaThreadNewParamsMessageContentUnion) IsPresent() bool {
return !param.IsOmitted(u) && !u.IsNull()
}
func (u BetaThreadNewParamsMessageContentUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion[BetaThreadNewParamsMessageContentUnion](u.OfString, u.OfArrayOfContentParts)
}
func (u *BetaThreadNewParamsMessageContentUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfArrayOfContentParts) {
return &u.OfArrayOfContentParts
}
return nil
}
type BetaThreadNewParamsMessageAttachment struct {
// The ID of the file to attach to the message.
FileID param.Opt[string] `json:"file_id,omitzero"`
// The tools to add this file to.
Tools []BetaThreadNewParamsMessageAttachmentToolUnion `json:"tools,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 BetaThreadNewParamsMessageAttachment) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsMessageAttachment) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsMessageAttachment
return param.MarshalObject(r, (*shadow)(&r))
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type BetaThreadNewParamsMessageAttachmentToolUnion struct {
OfCodeInterpreter *CodeInterpreterToolParam `json:",omitzero,inline"`
OfFileSearch *BetaThreadNewParamsMessageAttachmentToolFileSearch `json:",omitzero,inline"`
paramUnion
}
// 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 (u BetaThreadNewParamsMessageAttachmentToolUnion) IsPresent() bool {
return !param.IsOmitted(u) && !u.IsNull()
}
func (u BetaThreadNewParamsMessageAttachmentToolUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion[BetaThreadNewParamsMessageAttachmentToolUnion](u.OfCodeInterpreter, u.OfFileSearch)
}
func (u *BetaThreadNewParamsMessageAttachmentToolUnion) asAny() any {
if !param.IsOmitted(u.OfCodeInterpreter) {
return u.OfCodeInterpreter
} else if !param.IsOmitted(u.OfFileSearch) {
return u.OfFileSearch
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaThreadNewParamsMessageAttachmentToolUnion) GetType() *string {
if vt := u.OfCodeInterpreter; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfFileSearch; vt != nil {
return (*string)(&vt.Type)
}
return nil
}
func init() {
apijson.RegisterUnion[BetaThreadNewParamsMessageAttachmentToolUnion](
"type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(CodeInterpreterToolParam{}),
DiscriminatorValue: "code_interpreter",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaThreadNewParamsMessageAttachmentToolFileSearch{}),
DiscriminatorValue: "file_search",
},
)
}
// The property Type is required.
type BetaThreadNewParamsMessageAttachmentToolFileSearch struct {
// The type of tool being defined: `file_search`
//
// This field can be elided, and will marshal its zero value as "file_search".
Type constant.FileSearch `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 BetaThreadNewParamsMessageAttachmentToolFileSearch) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsMessageAttachmentToolFileSearch) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsMessageAttachmentToolFileSearch
return param.MarshalObject(r, (*shadow)(&r))
}
// A set of resources that are made available to the assistant's tools in this
// thread. The resources are specific to the type of tool. For example, the
// `code_interpreter` tool requires a list of file IDs, while the `file_search`
// tool requires a list of vector store IDs.
type BetaThreadNewParamsToolResources struct {
CodeInterpreter BetaThreadNewParamsToolResourcesCodeInterpreter `json:"code_interpreter,omitzero"`
FileSearch BetaThreadNewParamsToolResourcesFileSearch `json:"file_search,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 BetaThreadNewParamsToolResources) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r BetaThreadNewParamsToolResources) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsToolResources
return param.MarshalObject(r, (*shadow)(&r))
}
type BetaThreadNewParamsToolResourcesCodeInterpreter struct {
// A list of [file](https://platform.openai.com/docs/api-reference/files) IDs made
// available to the `code_interpreter` tool. There can be a maximum of 20 files
// associated with the tool.
FileIDs []string `json:"file_ids,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 BetaThreadNewParamsToolResourcesCodeInterpreter) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsToolResourcesCodeInterpreter
return param.MarshalObject(r, (*shadow)(&r))
}
type BetaThreadNewParamsToolResourcesFileSearch struct {
// The
// [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
// attached to this thread. There can be a maximum of 1 vector store attached to
// the thread.
VectorStoreIDs []string `json:"vector_store_ids,omitzero"`
// A helper to create a
// [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
// with file_ids and attach it to this thread. There can be a maximum of 1 vector
// store attached to the thread.
VectorStores []BetaThreadNewParamsToolResourcesFileSearchVectorStore `json:"vector_stores,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 BetaThreadNewParamsToolResourcesFileSearch) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsToolResourcesFileSearch
return param.MarshalObject(r, (*shadow)(&r))
}
type BetaThreadNewParamsToolResourcesFileSearchVectorStore struct {
// 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.MetadataParam `json:"metadata,omitzero"`
// The chunking strategy used to chunk the file(s). If not set, will use the `auto`
// strategy.
ChunkingStrategy BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion `json:"chunking_strategy,omitzero"`
// A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
// add to the vector store. There can be a maximum of 10000 files in a vector
// store.
FileIDs []string `json:"file_ids,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 BetaThreadNewParamsToolResourcesFileSearchVectorStore) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStore
return param.MarshalObject(r, (*shadow)(&r))
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion struct {
OfAuto *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto `json:",omitzero,inline"`
OfStatic *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic `json:",omitzero,inline"`
paramUnion
}
// 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 (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) IsPresent() bool {
return !param.IsOmitted(u) && !u.IsNull()
}
func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](u.OfAuto, u.OfStatic)
}
func (u *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) asAny() any {
if !param.IsOmitted(u.OfAuto) {
return u.OfAuto
} else if !param.IsOmitted(u.OfStatic) {
return u.OfStatic
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetStatic() *BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic {
if vt := u.OfStatic; vt != nil {
return &vt.Static
}
return nil
}
// Returns a pointer to the underlying variant's property, if present.
func (u BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion) GetType() *string {
if vt := u.OfAuto; vt != nil {
return (*string)(&vt.Type)
} else if vt := u.OfStatic; vt != nil {
return (*string)(&vt.Type)
}
return nil
}
func init() {
apijson.RegisterUnion[BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyUnion](
"type",
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto{}),
DiscriminatorValue: "auto",
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic{}),
DiscriminatorValue: "static",
},
)
}
// The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
// `800` and `chunk_overlap_tokens` of `400`.
//
// The property Type is required.
type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto struct {
// Always `auto`.
//
// This field can be elided, and will marshal its zero value as "auto".
Type constant.Auto `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 BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyAuto
return param.MarshalObject(r, (*shadow)(&r))
}
// The properties Static, Type are required.
type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic struct {
Static BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic `json:"static,omitzero,required"`
// Always `static`.
//
// This field can be elided, and will marshal its zero value as "static".
Type constant.Static `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 BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStatic
return param.MarshalObject(r, (*shadow)(&r))
}
// The properties ChunkOverlapTokens, MaxChunkSizeTokens are required.
type BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic struct {
// The number of tokens that overlap between chunks. The default value is `400`.
//
// Note that the overlap must not exceed half of `max_chunk_size_tokens`.
ChunkOverlapTokens int64 `json:"chunk_overlap_tokens,required"`
// The maximum number of tokens in each chunk. The default value is `800`. The
// minimum value is `100` and the maximum value is `4096`.
MaxChunkSizeTokens int64 `json:"max_chunk_size_tokens,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 BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) IsPresent() bool {
return !param.IsOmitted(f) && !f.IsNull()
}
func (r BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadNewParamsToolResourcesFileSearchVectorStoreChunkingStrategyStaticStatic
return param.MarshalObject(r, (*shadow)(&r))
}
type BetaThreadUpdateParams struct {
// 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.MetadataParam `json:"metadata,omitzero"`
// A set of resources that are made available to the assistant's tools in this
// thread. The resources are specific to the type of tool. For example, the
// `code_interpreter` tool requires a list of file IDs, while the `file_search`
// tool requires a list of vector store IDs.
ToolResources BetaThreadUpdateParamsToolResources `json:"tool_resources,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 BetaThreadUpdateParams) IsPresent() bool { return !param.IsOmitted(f) && !f.IsNull() }
func (r BetaThreadUpdateParams) MarshalJSON() (data []byte, err error) {
type shadow BetaThreadUpdateParams
return param.MarshalObject(r, (*shadow)(&r))