-
Notifications
You must be signed in to change notification settings - Fork 35
/
betathread.go
1079 lines (928 loc) · 44.9 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"
"errors"
"fmt"
"net/http"
"reflect"
"github.com/openai/openai-go/internal/apijson"
"github.com/openai/openai-go/internal/param"
"github.com/openai/openai-go/internal/requestconfig"
"github.com/openai/openai-go/option"
"github.com/openai/openai-go/packages/ssestream"
"github.com/openai/openai-go/shared"
"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
}
// 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. 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...)
}
// Create a thread and run it in one request.
func (r *BetaThreadService) NewAndRunStreaming(ctx context.Context, body BetaThreadNewAndRunParams, opts ...option.RequestOption) (stream *ssestream.Stream[AssistantStreamEvent]) {
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[AssistantStreamEvent](ssestream.NewDecoder(raw), err)
}
// 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
Type AssistantToolChoiceType `json:"type,required"`
Function AssistantToolChoiceFunction `json:"function"`
JSON assistantToolChoiceJSON `json:"-"`
}
// assistantToolChoiceJSON contains the JSON metadata for the struct
// [AssistantToolChoice]
type assistantToolChoiceJSON struct {
Type apijson.Field
Function apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AssistantToolChoice) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r assistantToolChoiceJSON) RawJSON() string {
return r.raw
}
func (r AssistantToolChoice) implementsAssistantToolChoiceOptionUnion() {}
// 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"
)
func (r AssistantToolChoiceType) IsKnown() bool {
switch r {
case AssistantToolChoiceTypeFunction, AssistantToolChoiceTypeCodeInterpreter, AssistantToolChoiceTypeFileSearch:
return true
}
return false
}
// Specifies a tool the model should use. Use to force the model to call a specific
// tool.
type AssistantToolChoiceParam struct {
// The type of the tool. If type is `function`, the function name must be set
Type param.Field[AssistantToolChoiceType] `json:"type,required"`
Function param.Field[AssistantToolChoiceFunctionParam] `json:"function"`
}
func (r AssistantToolChoiceParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r AssistantToolChoiceParam) implementsAssistantToolChoiceOptionUnionParam() {}
type AssistantToolChoiceFunction struct {
// The name of the function to call.
Name string `json:"name,required"`
JSON assistantToolChoiceFunctionJSON `json:"-"`
}
// assistantToolChoiceFunctionJSON contains the JSON metadata for the struct
// [AssistantToolChoiceFunction]
type assistantToolChoiceFunctionJSON struct {
Name apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AssistantToolChoiceFunction) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r assistantToolChoiceFunctionJSON) RawJSON() string {
return r.raw
}
type AssistantToolChoiceFunctionParam struct {
// The name of the function to call.
Name param.Field[string] `json:"name,required"`
}
func (r AssistantToolChoiceFunctionParam) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// Controls which (if any) tool is called by the model. `none` means the model will
// not call any tools and instead generates a message. `auto` is the default value
// and means the model can pick between generating a message or calling one or more
// tools. `required` means the model must call one or more tools before responding
// to the user. Specifying a particular tool like `{"type": "file_search"}` or
// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
// call that tool.
//
// Union satisfied by [AssistantToolChoiceOptionBehavior] or [AssistantToolChoice].
type AssistantToolChoiceOptionUnion interface {
implementsAssistantToolChoiceOptionUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AssistantToolChoiceOptionUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(AssistantToolChoiceOptionBehavior("")),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(AssistantToolChoice{}),
},
)
}
// `none` means the model will not call any tools and instead generates a message.
// `auto` means the model can pick between generating a message or calling one or
// more tools. `required` means the model must call one or more tools before
// responding to the user.
type AssistantToolChoiceOptionBehavior string
const (
AssistantToolChoiceOptionBehaviorNone AssistantToolChoiceOptionBehavior = "none"
AssistantToolChoiceOptionBehaviorAuto AssistantToolChoiceOptionBehavior = "auto"
AssistantToolChoiceOptionBehaviorRequired AssistantToolChoiceOptionBehavior = "required"
)
func (r AssistantToolChoiceOptionBehavior) IsKnown() bool {
switch r {
case AssistantToolChoiceOptionBehaviorNone, AssistantToolChoiceOptionBehaviorAuto, AssistantToolChoiceOptionBehaviorRequired:
return true
}
return false
}
func (r AssistantToolChoiceOptionBehavior) implementsAssistantToolChoiceOptionUnion() {}
func (r AssistantToolChoiceOptionBehavior) implementsAssistantToolChoiceOptionUnionParam() {}
// Controls which (if any) tool is called by the model. `none` means the model will
// not call any tools and instead generates a message. `auto` is the default value
// and means the model can pick between generating a message or calling one or more
// tools. `required` means the model must call one or more tools before responding
// to the user. Specifying a particular tool like `{"type": "file_search"}` or
// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
// call that tool.
//
// Satisfied by [AssistantToolChoiceOptionBehavior], [AssistantToolChoiceParam].
type AssistantToolChoiceOptionUnionParam interface {
implementsAssistantToolChoiceOptionUnionParam()
}
// 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. Keys
// can be a maximum of 64 characters long and values can be a maximum of 512
// characters long.
Metadata interface{} `json:"metadata,required,nullable"`
// The object type, which is always `thread`.
Object ThreadObject `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,nullable"`
JSON threadJSON `json:"-"`
}
// threadJSON contains the JSON metadata for the struct [Thread]
type threadJSON struct {
ID apijson.Field
CreatedAt apijson.Field
Metadata apijson.Field
Object apijson.Field
ToolResources apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Thread) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r threadJSON) RawJSON() string {
return r.raw
}
// The object type, which is always `thread`.
type ThreadObject string
const (
ThreadObjectThread ThreadObject = "thread"
)
func (r ThreadObject) IsKnown() bool {
switch r {
case ThreadObjectThread:
return true
}
return false
}
// 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"`
JSON threadToolResourcesJSON `json:"-"`
}
// threadToolResourcesJSON contains the JSON metadata for the struct
// [ThreadToolResources]
type threadToolResourcesJSON struct {
CodeInterpreter apijson.Field
FileSearch apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ThreadToolResources) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r threadToolResourcesJSON) RawJSON() string {
return r.raw
}
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"`
JSON threadToolResourcesCodeInterpreterJSON `json:"-"`
}
// threadToolResourcesCodeInterpreterJSON contains the JSON metadata for the struct
// [ThreadToolResourcesCodeInterpreter]
type threadToolResourcesCodeInterpreterJSON struct {
FileIDs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ThreadToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r threadToolResourcesCodeInterpreterJSON) RawJSON() string {
return r.raw
}
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"`
JSON threadToolResourcesFileSearchJSON `json:"-"`
}
// threadToolResourcesFileSearchJSON contains the JSON metadata for the struct
// [ThreadToolResourcesFileSearch]
type threadToolResourcesFileSearchJSON struct {
VectorStoreIDs apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ThreadToolResourcesFileSearch) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r threadToolResourcesFileSearchJSON) RawJSON() string {
return r.raw
}
type ThreadDeleted struct {
ID string `json:"id,required"`
Deleted bool `json:"deleted,required"`
Object ThreadDeletedObject `json:"object,required"`
JSON threadDeletedJSON `json:"-"`
}
// threadDeletedJSON contains the JSON metadata for the struct [ThreadDeleted]
type threadDeletedJSON struct {
ID apijson.Field
Deleted apijson.Field
Object apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *ThreadDeleted) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r threadDeletedJSON) RawJSON() string {
return r.raw
}
type ThreadDeletedObject string
const (
ThreadDeletedObjectThreadDeleted ThreadDeletedObject = "thread.deleted"
)
func (r ThreadDeletedObject) IsKnown() bool {
switch r {
case ThreadDeletedObjectThreadDeleted:
return true
}
return false
}
type BetaThreadNewParams struct {
// A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
// start the thread with.
Messages param.Field[[]BetaThreadNewParamsMessage] `json:"messages"`
// 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. Keys
// can be a maximum of 64 characters long and values can be a maximum of 512
// characters long.
Metadata param.Field[interface{}] `json:"metadata"`
// 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 param.Field[BetaThreadNewParamsToolResources] `json:"tool_resources"`
}
func (r BetaThreadNewParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewParamsMessage struct {
// An array of content parts with a defined type, each can be of type `text` or
// images can be passed with `image_url` or `image_file`. Image types are only
// supported on
// [Vision-compatible models](https://platform.openai.com/docs/models).
Content param.Field[[]MessageContentPartParamUnion] `json:"content,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.
Role param.Field[BetaThreadNewParamsMessagesRole] `json:"role,required"`
// A list of files attached to the message, and the tools they should be added to.
Attachments param.Field[[]BetaThreadNewParamsMessagesAttachment] `json:"attachments"`
// 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. Keys
// can be a maximum of 64 characters long and values can be a maximum of 512
// characters long.
Metadata param.Field[interface{}] `json:"metadata"`
}
func (r BetaThreadNewParamsMessage) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// 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.
type BetaThreadNewParamsMessagesRole string
const (
BetaThreadNewParamsMessagesRoleUser BetaThreadNewParamsMessagesRole = "user"
BetaThreadNewParamsMessagesRoleAssistant BetaThreadNewParamsMessagesRole = "assistant"
)
func (r BetaThreadNewParamsMessagesRole) IsKnown() bool {
switch r {
case BetaThreadNewParamsMessagesRoleUser, BetaThreadNewParamsMessagesRoleAssistant:
return true
}
return false
}
type BetaThreadNewParamsMessagesAttachment struct {
// The ID of the file to attach to the message.
FileID param.Field[string] `json:"file_id"`
// The tools to add this file to.
Tools param.Field[[]BetaThreadNewParamsMessagesAttachmentsToolUnion] `json:"tools"`
}
func (r BetaThreadNewParamsMessagesAttachment) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewParamsMessagesAttachmentsTool struct {
// The type of tool being defined: `code_interpreter`
Type param.Field[BetaThreadNewParamsMessagesAttachmentsToolsType] `json:"type,required"`
}
func (r BetaThreadNewParamsMessagesAttachmentsTool) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r BetaThreadNewParamsMessagesAttachmentsTool) implementsBetaThreadNewParamsMessagesAttachmentsToolUnion() {
}
// Satisfied by [CodeInterpreterToolParam],
// [BetaThreadNewParamsMessagesAttachmentsToolsFileSearch],
// [BetaThreadNewParamsMessagesAttachmentsTool].
type BetaThreadNewParamsMessagesAttachmentsToolUnion interface {
implementsBetaThreadNewParamsMessagesAttachmentsToolUnion()
}
type BetaThreadNewParamsMessagesAttachmentsToolsFileSearch struct {
// The type of tool being defined: `file_search`
Type param.Field[BetaThreadNewParamsMessagesAttachmentsToolsFileSearchType] `json:"type,required"`
}
func (r BetaThreadNewParamsMessagesAttachmentsToolsFileSearch) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r BetaThreadNewParamsMessagesAttachmentsToolsFileSearch) implementsBetaThreadNewParamsMessagesAttachmentsToolUnion() {
}
// The type of tool being defined: `file_search`
type BetaThreadNewParamsMessagesAttachmentsToolsFileSearchType string
const (
BetaThreadNewParamsMessagesAttachmentsToolsFileSearchTypeFileSearch BetaThreadNewParamsMessagesAttachmentsToolsFileSearchType = "file_search"
)
func (r BetaThreadNewParamsMessagesAttachmentsToolsFileSearchType) IsKnown() bool {
switch r {
case BetaThreadNewParamsMessagesAttachmentsToolsFileSearchTypeFileSearch:
return true
}
return false
}
// The type of tool being defined: `code_interpreter`
type BetaThreadNewParamsMessagesAttachmentsToolsType string
const (
BetaThreadNewParamsMessagesAttachmentsToolsTypeCodeInterpreter BetaThreadNewParamsMessagesAttachmentsToolsType = "code_interpreter"
BetaThreadNewParamsMessagesAttachmentsToolsTypeFileSearch BetaThreadNewParamsMessagesAttachmentsToolsType = "file_search"
)
func (r BetaThreadNewParamsMessagesAttachmentsToolsType) IsKnown() bool {
switch r {
case BetaThreadNewParamsMessagesAttachmentsToolsTypeCodeInterpreter, BetaThreadNewParamsMessagesAttachmentsToolsTypeFileSearch:
return true
}
return false
}
// 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 param.Field[BetaThreadNewParamsToolResourcesCodeInterpreter] `json:"code_interpreter"`
FileSearch param.Field[BetaThreadNewParamsToolResourcesFileSearch] `json:"file_search"`
}
func (r BetaThreadNewParamsToolResources) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(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 param.Field[[]string] `json:"file_ids"`
}
func (r BetaThreadNewParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(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 param.Field[[]string] `json:"vector_store_ids"`
// 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 param.Field[[]BetaThreadNewParamsToolResourcesFileSearchVectorStore] `json:"vector_stores"`
}
func (r BetaThreadNewParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewParamsToolResourcesFileSearchVectorStore struct {
// The chunking strategy used to chunk the file(s). If not set, will use the `auto`
// strategy. Only applicable if `file_ids` is non-empty.
ChunkingStrategy param.Field[FileChunkingStrategyParamUnion] `json:"chunking_strategy"`
// 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 param.Field[[]string] `json:"file_ids"`
// Set of 16 key-value pairs that can be attached to a vector store. This can be
// useful for storing additional information about the vector store in a structured
// format. Keys can be a maximum of 64 characters long and values can be a maximum
// of 512 characters long.
Metadata param.Field[interface{}] `json:"metadata"`
}
func (r BetaThreadNewParamsToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(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. Keys
// can be a maximum of 64 characters long and values can be a maximum of 512
// characters long.
Metadata param.Field[interface{}] `json:"metadata"`
// 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 param.Field[BetaThreadUpdateParamsToolResources] `json:"tool_resources"`
}
func (r BetaThreadUpdateParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(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 BetaThreadUpdateParamsToolResources struct {
CodeInterpreter param.Field[BetaThreadUpdateParamsToolResourcesCodeInterpreter] `json:"code_interpreter"`
FileSearch param.Field[BetaThreadUpdateParamsToolResourcesFileSearch] `json:"file_search"`
}
func (r BetaThreadUpdateParamsToolResources) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadUpdateParamsToolResourcesCodeInterpreter 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 param.Field[[]string] `json:"file_ids"`
}
func (r BetaThreadUpdateParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadUpdateParamsToolResourcesFileSearch 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 param.Field[[]string] `json:"vector_store_ids"`
}
func (r BetaThreadUpdateParamsToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParams struct {
// The ID of the
// [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
// execute this run.
AssistantID param.Field[string] `json:"assistant_id,required"`
// Override the default system message of the assistant. This is useful for
// modifying the behavior on a per-run basis.
Instructions param.Field[string] `json:"instructions"`
// The maximum number of completion tokens that may be used over the course of the
// run. The run will make a best effort to use only the number of completion tokens
// specified, across multiple turns of the run. If the run exceeds the number of
// completion tokens specified, the run will end with status `incomplete`. See
// `incomplete_details` for more info.
MaxCompletionTokens param.Field[int64] `json:"max_completion_tokens"`
// The maximum number of prompt tokens that may be used over the course of the run.
// The run will make a best effort to use only the number of prompt tokens
// specified, across multiple turns of the run. If the run exceeds the number of
// prompt tokens specified, the run will end with status `incomplete`. See
// `incomplete_details` for more info.
MaxPromptTokens param.Field[int64] `json:"max_prompt_tokens"`
// 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. Keys
// can be a maximum of 64 characters long and values can be a maximum of 512
// characters long.
Metadata param.Field[interface{}] `json:"metadata"`
// The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
// be used to execute this run. If a value is provided here, it will override the
// model associated with the assistant. If not, the model associated with the
// assistant will be used.
Model param.Field[ChatModel] `json:"model"`
// Whether to enable
// [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
// during tool use.
ParallelToolCalls param.Field[bool] `json:"parallel_tool_calls"`
// What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
// make the output more random, while lower values like 0.2 will make it more
// focused and deterministic.
Temperature param.Field[float64] `json:"temperature"`
// If no thread is provided, an empty thread will be created.
Thread param.Field[BetaThreadNewAndRunParamsThread] `json:"thread"`
// Controls which (if any) tool is called by the model. `none` means the model will
// not call any tools and instead generates a message. `auto` is the default value
// and means the model can pick between generating a message or calling one or more
// tools. `required` means the model must call one or more tools before responding
// to the user. Specifying a particular tool like `{"type": "file_search"}` or
// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
// call that tool.
ToolChoice param.Field[AssistantToolChoiceOptionUnionParam] `json:"tool_choice"`
// A set of resources that are used by the assistant's tools. 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 param.Field[BetaThreadNewAndRunParamsToolResources] `json:"tool_resources"`
// Override the tools the assistant can use for this run. This is useful for
// modifying the behavior on a per-run basis.
Tools param.Field[[]BetaThreadNewAndRunParamsToolUnion] `json:"tools"`
// An alternative to sampling with temperature, called nucleus sampling, where the
// model considers the results of the tokens with top_p probability mass. So 0.1
// means only the tokens comprising the top 10% probability mass are considered.
//
// We generally recommend altering this or temperature but not both.
TopP param.Field[float64] `json:"top_p"`
// Controls for how a thread will be truncated prior to the run. Use this to
// control the intial context window of the run.
TruncationStrategy param.Field[BetaThreadNewAndRunParamsTruncationStrategy] `json:"truncation_strategy"`
}
func (r BetaThreadNewAndRunParams) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// If no thread is provided, an empty thread will be created.
type BetaThreadNewAndRunParamsThread struct {
// A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
// start the thread with.
Messages param.Field[[]BetaThreadNewAndRunParamsThreadMessage] `json:"messages"`
// 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. Keys
// can be a maximum of 64 characters long and values can be a maximum of 512
// characters long.
Metadata param.Field[interface{}] `json:"metadata"`
// 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 param.Field[BetaThreadNewAndRunParamsThreadToolResources] `json:"tool_resources"`
}
func (r BetaThreadNewAndRunParamsThread) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParamsThreadMessage struct {
// An array of content parts with a defined type, each can be of type `text` or
// images can be passed with `image_url` or `image_file`. Image types are only
// supported on
// [Vision-compatible models](https://platform.openai.com/docs/models).
Content param.Field[[]MessageContentPartParamUnion] `json:"content,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.
Role param.Field[BetaThreadNewAndRunParamsThreadMessagesRole] `json:"role,required"`
// A list of files attached to the message, and the tools they should be added to.
Attachments param.Field[[]BetaThreadNewAndRunParamsThreadMessagesAttachment] `json:"attachments"`
// 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. Keys
// can be a maximum of 64 characters long and values can be a maximum of 512
// characters long.
Metadata param.Field[interface{}] `json:"metadata"`
}
func (r BetaThreadNewAndRunParamsThreadMessage) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// 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.
type BetaThreadNewAndRunParamsThreadMessagesRole string
const (
BetaThreadNewAndRunParamsThreadMessagesRoleUser BetaThreadNewAndRunParamsThreadMessagesRole = "user"
BetaThreadNewAndRunParamsThreadMessagesRoleAssistant BetaThreadNewAndRunParamsThreadMessagesRole = "assistant"
)
func (r BetaThreadNewAndRunParamsThreadMessagesRole) IsKnown() bool {
switch r {
case BetaThreadNewAndRunParamsThreadMessagesRoleUser, BetaThreadNewAndRunParamsThreadMessagesRoleAssistant:
return true
}
return false
}
type BetaThreadNewAndRunParamsThreadMessagesAttachment struct {
// The ID of the file to attach to the message.
FileID param.Field[string] `json:"file_id"`
// The tools to add this file to.
Tools param.Field[[]BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolUnion] `json:"tools"`
}
func (r BetaThreadNewAndRunParamsThreadMessagesAttachment) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParamsThreadMessagesAttachmentsTool struct {
// The type of tool being defined: `code_interpreter`
Type param.Field[BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsType] `json:"type,required"`
}
func (r BetaThreadNewAndRunParamsThreadMessagesAttachmentsTool) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r BetaThreadNewAndRunParamsThreadMessagesAttachmentsTool) implementsBetaThreadNewAndRunParamsThreadMessagesAttachmentsToolUnion() {
}
// Satisfied by [CodeInterpreterToolParam],
// [BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearch],
// [BetaThreadNewAndRunParamsThreadMessagesAttachmentsTool].
type BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolUnion interface {
implementsBetaThreadNewAndRunParamsThreadMessagesAttachmentsToolUnion()
}
type BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearch struct {
// The type of tool being defined: `file_search`
Type param.Field[BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearchType] `json:"type,required"`
}
func (r BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearch) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
func (r BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearch) implementsBetaThreadNewAndRunParamsThreadMessagesAttachmentsToolUnion() {
}
// The type of tool being defined: `file_search`
type BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearchType string
const (
BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearchTypeFileSearch BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearchType = "file_search"
)
func (r BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearchType) IsKnown() bool {
switch r {
case BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsFileSearchTypeFileSearch:
return true
}
return false
}
// The type of tool being defined: `code_interpreter`
type BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsType string
const (
BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsTypeCodeInterpreter BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsType = "code_interpreter"
BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsTypeFileSearch BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsType = "file_search"
)
func (r BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsType) IsKnown() bool {
switch r {
case BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsTypeCodeInterpreter, BetaThreadNewAndRunParamsThreadMessagesAttachmentsToolsTypeFileSearch:
return true
}
return false
}
// 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 BetaThreadNewAndRunParamsThreadToolResources struct {
CodeInterpreter param.Field[BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter] `json:"code_interpreter"`
FileSearch param.Field[BetaThreadNewAndRunParamsThreadToolResourcesFileSearch] `json:"file_search"`
}
func (r BetaThreadNewAndRunParamsThreadToolResources) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter 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 param.Field[[]string] `json:"file_ids"`
}
func (r BetaThreadNewAndRunParamsThreadToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParamsThreadToolResourcesFileSearch 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 param.Field[[]string] `json:"vector_store_ids"`
// 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 param.Field[[]BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore] `json:"vector_stores"`
}
func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearch) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore struct {
// The chunking strategy used to chunk the file(s). If not set, will use the `auto`
// strategy. Only applicable if `file_ids` is non-empty.
ChunkingStrategy param.Field[FileChunkingStrategyParamUnion] `json:"chunking_strategy"`
// 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 param.Field[[]string] `json:"file_ids"`
// Set of 16 key-value pairs that can be attached to a vector store. This can be
// useful for storing additional information about the vector store in a structured
// format. Keys can be a maximum of 64 characters long and values can be a maximum
// of 512 characters long.
Metadata param.Field[interface{}] `json:"metadata"`
}
func (r BetaThreadNewAndRunParamsThreadToolResourcesFileSearchVectorStore) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
// A set of resources that are used by the assistant's tools. 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 BetaThreadNewAndRunParamsToolResources struct {
CodeInterpreter param.Field[BetaThreadNewAndRunParamsToolResourcesCodeInterpreter] `json:"code_interpreter"`
FileSearch param.Field[BetaThreadNewAndRunParamsToolResourcesFileSearch] `json:"file_search"`
}
func (r BetaThreadNewAndRunParamsToolResources) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParamsToolResourcesCodeInterpreter 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 param.Field[[]string] `json:"file_ids"`
}
func (r BetaThreadNewAndRunParamsToolResourcesCodeInterpreter) MarshalJSON() (data []byte, err error) {
return apijson.MarshalRoot(r)
}
type BetaThreadNewAndRunParamsToolResourcesFileSearch struct {
// The ID of the
// [vector store](https://platform.openai.com/docs/api-reference/vector-stores/object)
// attached to this assistant. There can be a maximum of 1 vector store attached to