-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathbetaassistant.go
2234 lines (2050 loc) · 89.2 KB
/
betaassistant.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"
)
// BetaAssistantService 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 [NewBetaAssistantService] method instead.
type BetaAssistantService struct {
Options []option.RequestOption
}
// NewBetaAssistantService 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 NewBetaAssistantService(opts ...option.RequestOption) (r BetaAssistantService) {
r = BetaAssistantService{}
r.Options = opts
return
}
// Create an assistant with a model and instructions.
func (r *BetaAssistantService) New(ctx context.Context, body BetaAssistantNewParams, opts ...option.RequestOption) (res *Assistant, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
path := "assistants"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Retrieves an assistant.
func (r *BetaAssistantService) Get(ctx context.Context, assistantID string, opts ...option.RequestOption) (res *Assistant, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
if assistantID == "" {
err = errors.New("missing required assistant_id parameter")
return
}
path := fmt.Sprintf("assistants/%s", assistantID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
// Modifies an assistant.
func (r *BetaAssistantService) Update(ctx context.Context, assistantID string, body BetaAssistantUpdateParams, opts ...option.RequestOption) (res *Assistant, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
if assistantID == "" {
err = errors.New("missing required assistant_id parameter")
return
}
path := fmt.Sprintf("assistants/%s", assistantID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return
}
// Returns a list of assistants.
func (r *BetaAssistantService) List(ctx context.Context, query BetaAssistantListParams, opts ...option.RequestOption) (res *pagination.CursorPage[Assistant], 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...)
path := "assistants"
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 assistants.
func (r *BetaAssistantService) ListAutoPaging(ctx context.Context, query BetaAssistantListParams, opts ...option.RequestOption) *pagination.CursorPageAutoPager[Assistant] {
return pagination.NewCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Delete an assistant.
func (r *BetaAssistantService) Delete(ctx context.Context, assistantID string, opts ...option.RequestOption) (res *AssistantDeleted, err error) {
opts = append(r.Options[:], opts...)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "assistants=v2")}, opts...)
if assistantID == "" {
err = errors.New("missing required assistant_id parameter")
return
}
path := fmt.Sprintf("assistants/%s", assistantID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return
}
// Represents an `assistant` that can call the model and use tools.
type Assistant struct {
// The identifier, which can be referenced in API endpoints.
ID string `json:"id,required"`
// The Unix timestamp (in seconds) for when the assistant was created.
CreatedAt int64 `json:"created_at,required"`
// The description of the assistant. The maximum length is 512 characters.
Description string `json:"description,required"`
// The system instructions that the assistant uses. The maximum length is 256,000
// characters.
Instructions string `json:"instructions,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"`
// ID of the model to use. You can use the
// [List models](https://platform.openai.com/docs/api-reference/models/list) API to
// see all of your available models, or see our
// [Model overview](https://platform.openai.com/docs/models) for descriptions of
// them.
Model string `json:"model,required"`
// The name of the assistant. The maximum length is 256 characters.
Name string `json:"name,required"`
// The object type, which is always `assistant`.
Object constant.Assistant `json:"object,required"`
// A list of tool enabled on the assistant. There can be a maximum of 128 tools per
// assistant. Tools can be of types `code_interpreter`, `file_search`, or
// `function`.
Tools []AssistantToolUnion `json:"tools,required"`
// Specifies the format that the model must output. Compatible with
// [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
// [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
// and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.
//
// Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
// Outputs which ensures the model will match your supplied JSON schema. Learn more
// in the
// [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).
//
// Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
// message the model generates is valid JSON.
//
// **Important:** when using JSON mode, you **must** also instruct the model to
// produce JSON yourself via a system or user message. Without this, the model may
// generate an unending stream of whitespace until the generation reaches the token
// limit, resulting in a long-running and seemingly "stuck" request. Also note that
// the message content may be partially cut off if `finish_reason="length"`, which
// indicates the generation exceeded `max_tokens` or the conversation exceeded the
// max context length.
ResponseFormat AssistantResponseFormatOptionUnion `json:"response_format,nullable"`
// 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 float64 `json:"temperature,nullable"`
// 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 AssistantToolResources `json:"tool_resources,nullable"`
// 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 float64 `json:"top_p,nullable"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
ID resp.Field
CreatedAt resp.Field
Description resp.Field
Instructions resp.Field
Metadata resp.Field
Model resp.Field
Name resp.Field
Object resp.Field
Tools resp.Field
ResponseFormat resp.Field
Temperature resp.Field
ToolResources resp.Field
TopP resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r Assistant) RawJSON() string { return r.JSON.raw }
func (r *Assistant) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, 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 AssistantToolResources struct {
CodeInterpreter AssistantToolResourcesCodeInterpreter `json:"code_interpreter"`
FileSearch AssistantToolResourcesFileSearch `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 AssistantToolResources) RawJSON() string { return r.JSON.raw }
func (r *AssistantToolResources) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AssistantToolResourcesCodeInterpreter 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 AssistantToolResourcesCodeInterpreter) RawJSON() string { return r.JSON.raw }
func (r *AssistantToolResourcesCodeInterpreter) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AssistantToolResourcesFileSearch 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
// the assistant.
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 AssistantToolResourcesFileSearch) RawJSON() string { return r.JSON.raw }
func (r *AssistantToolResourcesFileSearch) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type AssistantDeleted struct {
ID string `json:"id,required"`
Deleted bool `json:"deleted,required"`
Object constant.AssistantDeleted `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 AssistantDeleted) RawJSON() string { return r.JSON.raw }
func (r *AssistantDeleted) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// AssistantStreamEventUnion contains all possible properties and values from
// [AssistantStreamEventThreadCreated], [AssistantStreamEventThreadRunCreated],
// [AssistantStreamEventThreadRunQueued],
// [AssistantStreamEventThreadRunInProgress],
// [AssistantStreamEventThreadRunRequiresAction],
// [AssistantStreamEventThreadRunCompleted],
// [AssistantStreamEventThreadRunIncomplete],
// [AssistantStreamEventThreadRunFailed],
// [AssistantStreamEventThreadRunCancelling],
// [AssistantStreamEventThreadRunCancelled],
// [AssistantStreamEventThreadRunExpired],
// [AssistantStreamEventThreadRunStepCreated],
// [AssistantStreamEventThreadRunStepInProgress],
// [AssistantStreamEventThreadRunStepDelta],
// [AssistantStreamEventThreadRunStepCompleted],
// [AssistantStreamEventThreadRunStepFailed],
// [AssistantStreamEventThreadRunStepCancelled],
// [AssistantStreamEventThreadRunStepExpired],
// [AssistantStreamEventThreadMessageCreated],
// [AssistantStreamEventThreadMessageInProgress],
// [AssistantStreamEventThreadMessageDelta],
// [AssistantStreamEventThreadMessageCompleted],
// [AssistantStreamEventThreadMessageIncomplete], [AssistantStreamEventErrorEvent].
//
// Use the [AssistantStreamEventUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type AssistantStreamEventUnion struct {
// This field is a union of [Thread], [Run], [RunStep], [RunStepDeltaEvent],
// [Message], [MessageDeltaEvent], [shared.ErrorObject]
Data AssistantStreamEventUnionData `json:"data"`
// Any of "thread.created", "thread.run.created", "thread.run.queued",
// "thread.run.in_progress", "thread.run.requires_action", "thread.run.completed",
// "thread.run.incomplete", "thread.run.failed", "thread.run.cancelling",
// "thread.run.cancelled", "thread.run.expired", "thread.run.step.created",
// "thread.run.step.in_progress", "thread.run.step.delta",
// "thread.run.step.completed", "thread.run.step.failed",
// "thread.run.step.cancelled", "thread.run.step.expired",
// "thread.message.created", "thread.message.in_progress", "thread.message.delta",
// "thread.message.completed", "thread.message.incomplete", "error".
Event string `json:"event"`
// This field is from variant [AssistantStreamEventThreadCreated].
Enabled bool `json:"enabled"`
JSON struct {
Data resp.Field
Event resp.Field
Enabled resp.Field
raw string
} `json:"-"`
}
// Use the following switch statement to find the correct variant
//
// switch variant := AssistantStreamEventUnion.AsAny().(type) {
// case AssistantStreamEventThreadCreated:
// case AssistantStreamEventThreadRunCreated:
// case AssistantStreamEventThreadRunQueued:
// case AssistantStreamEventThreadRunInProgress:
// case AssistantStreamEventThreadRunRequiresAction:
// case AssistantStreamEventThreadRunCompleted:
// case AssistantStreamEventThreadRunIncomplete:
// case AssistantStreamEventThreadRunFailed:
// case AssistantStreamEventThreadRunCancelling:
// case AssistantStreamEventThreadRunCancelled:
// case AssistantStreamEventThreadRunExpired:
// case AssistantStreamEventThreadRunStepCreated:
// case AssistantStreamEventThreadRunStepInProgress:
// case AssistantStreamEventThreadRunStepDelta:
// case AssistantStreamEventThreadRunStepCompleted:
// case AssistantStreamEventThreadRunStepFailed:
// case AssistantStreamEventThreadRunStepCancelled:
// case AssistantStreamEventThreadRunStepExpired:
// case AssistantStreamEventThreadMessageCreated:
// case AssistantStreamEventThreadMessageInProgress:
// case AssistantStreamEventThreadMessageDelta:
// case AssistantStreamEventThreadMessageCompleted:
// case AssistantStreamEventThreadMessageIncomplete:
// case AssistantStreamEventErrorEvent:
// default:
// fmt.Errorf("no variant present")
// }
func (u AssistantStreamEventUnion) AsAny() any {
switch u.Event {
case "thread.created":
return u.AsThreadCreated()
case "thread.run.created":
return u.AsThreadRunCreated()
case "thread.run.queued":
return u.AsThreadRunQueued()
case "thread.run.in_progress":
return u.AsThreadRunInProgress()
case "thread.run.requires_action":
return u.AsThreadRunRequiresAction()
case "thread.run.completed":
return u.AsThreadRunCompleted()
case "thread.run.incomplete":
return u.AsThreadRunIncomplete()
case "thread.run.failed":
return u.AsThreadRunFailed()
case "thread.run.cancelling":
return u.AsThreadRunCancelling()
case "thread.run.cancelled":
return u.AsThreadRunCancelled()
case "thread.run.expired":
return u.AsThreadRunExpired()
case "thread.run.step.created":
return u.AsThreadRunStepCreated()
case "thread.run.step.in_progress":
return u.AsThreadRunStepInProgress()
case "thread.run.step.delta":
return u.AsThreadRunStepDelta()
case "thread.run.step.completed":
return u.AsThreadRunStepCompleted()
case "thread.run.step.failed":
return u.AsThreadRunStepFailed()
case "thread.run.step.cancelled":
return u.AsThreadRunStepCancelled()
case "thread.run.step.expired":
return u.AsThreadRunStepExpired()
case "thread.message.created":
return u.AsThreadMessageCreated()
case "thread.message.in_progress":
return u.AsThreadMessageInProgress()
case "thread.message.delta":
return u.AsThreadMessageDelta()
case "thread.message.completed":
return u.AsThreadMessageCompleted()
case "thread.message.incomplete":
return u.AsThreadMessageIncomplete()
case "error":
return u.AsErrorEvent()
}
return nil
}
func (u AssistantStreamEventUnion) AsThreadCreated() (v AssistantStreamEventThreadCreated) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunCreated() (v AssistantStreamEventThreadRunCreated) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunQueued() (v AssistantStreamEventThreadRunQueued) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunInProgress() (v AssistantStreamEventThreadRunInProgress) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunRequiresAction() (v AssistantStreamEventThreadRunRequiresAction) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunCompleted() (v AssistantStreamEventThreadRunCompleted) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunIncomplete() (v AssistantStreamEventThreadRunIncomplete) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunFailed() (v AssistantStreamEventThreadRunFailed) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunCancelling() (v AssistantStreamEventThreadRunCancelling) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunCancelled() (v AssistantStreamEventThreadRunCancelled) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunExpired() (v AssistantStreamEventThreadRunExpired) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunStepCreated() (v AssistantStreamEventThreadRunStepCreated) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunStepInProgress() (v AssistantStreamEventThreadRunStepInProgress) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunStepDelta() (v AssistantStreamEventThreadRunStepDelta) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunStepCompleted() (v AssistantStreamEventThreadRunStepCompleted) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunStepFailed() (v AssistantStreamEventThreadRunStepFailed) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunStepCancelled() (v AssistantStreamEventThreadRunStepCancelled) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadRunStepExpired() (v AssistantStreamEventThreadRunStepExpired) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadMessageCreated() (v AssistantStreamEventThreadMessageCreated) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadMessageInProgress() (v AssistantStreamEventThreadMessageInProgress) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadMessageDelta() (v AssistantStreamEventThreadMessageDelta) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadMessageCompleted() (v AssistantStreamEventThreadMessageCompleted) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsThreadMessageIncomplete() (v AssistantStreamEventThreadMessageIncomplete) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u AssistantStreamEventUnion) AsErrorEvent() (v AssistantStreamEventErrorEvent) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u AssistantStreamEventUnion) RawJSON() string { return u.JSON.raw }
func (r *AssistantStreamEventUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// AssistantStreamEventUnionData is an implicit subunion of
// [AssistantStreamEventUnion]. AssistantStreamEventUnionData provides convenient
// access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [AssistantStreamEventUnion].
type AssistantStreamEventUnionData struct {
ID string `json:"id"`
CreatedAt int64 `json:"created_at"`
// This field is from variant [Thread].
Metadata shared.Metadata `json:"metadata"`
Object string `json:"object"`
// This field is from variant [Thread].
ToolResources ThreadToolResources `json:"tool_resources"`
AssistantID string `json:"assistant_id"`
CancelledAt int64 `json:"cancelled_at"`
CompletedAt int64 `json:"completed_at"`
// This field is from variant [Run].
ExpiresAt int64 `json:"expires_at"`
FailedAt int64 `json:"failed_at"`
// This field is a union of [RunIncompleteDetails], [MessageIncompleteDetails]
IncompleteDetails AssistantStreamEventUnionDataIncompleteDetails `json:"incomplete_details"`
// This field is from variant [Run].
Instructions string `json:"instructions"`
// This field is a union of [RunLastError], [RunStepLastError]
LastError AssistantStreamEventUnionDataLastError `json:"last_error"`
// This field is from variant [Run].
MaxCompletionTokens int64 `json:"max_completion_tokens"`
// This field is from variant [Run].
MaxPromptTokens int64 `json:"max_prompt_tokens"`
// This field is from variant [Run].
Model string `json:"model"`
// This field is from variant [Run].
ParallelToolCalls bool `json:"parallel_tool_calls"`
// This field is from variant [Run].
RequiredAction RunRequiredAction `json:"required_action"`
// This field is from variant [Run].
ResponseFormat AssistantResponseFormatOptionUnion `json:"response_format"`
// This field is from variant [Run].
StartedAt int64 `json:"started_at"`
Status string `json:"status"`
ThreadID string `json:"thread_id"`
// This field is from variant [Run].
ToolChoice AssistantToolChoiceOptionUnion `json:"tool_choice"`
// This field is from variant [Run].
Tools []AssistantToolUnion `json:"tools"`
// This field is from variant [Run].
TruncationStrategy RunTruncationStrategy `json:"truncation_strategy"`
// This field is a union of [RunUsage], [RunStepUsage]
Usage AssistantStreamEventUnionDataUsage `json:"usage"`
// This field is from variant [Run].
Temperature float64 `json:"temperature"`
// This field is from variant [Run].
TopP float64 `json:"top_p"`
// This field is from variant [RunStep].
ExpiredAt int64 `json:"expired_at"`
RunID string `json:"run_id"`
// This field is from variant [RunStep].
StepDetails RunStepStepDetailsUnion `json:"step_details"`
Type string `json:"type"`
// This field is a union of [RunStepDelta], [MessageDelta]
Delta AssistantStreamEventUnionDataDelta `json:"delta"`
// This field is from variant [Message].
Attachments []MessageAttachment `json:"attachments"`
// This field is from variant [Message].
Content []MessageContentUnion `json:"content"`
// This field is from variant [Message].
IncompleteAt int64 `json:"incomplete_at"`
// This field is from variant [Message].
Role MessageRole `json:"role"`
// This field is from variant [shared.ErrorObject].
Code string `json:"code"`
// This field is from variant [shared.ErrorObject].
Message string `json:"message"`
// This field is from variant [shared.ErrorObject].
Param string `json:"param"`
JSON struct {
ID resp.Field
CreatedAt resp.Field
Metadata resp.Field
Object resp.Field
ToolResources resp.Field
AssistantID resp.Field
CancelledAt resp.Field
CompletedAt resp.Field
ExpiresAt resp.Field
FailedAt resp.Field
IncompleteDetails resp.Field
Instructions resp.Field
LastError resp.Field
MaxCompletionTokens resp.Field
MaxPromptTokens resp.Field
Model resp.Field
ParallelToolCalls resp.Field
RequiredAction resp.Field
ResponseFormat resp.Field
StartedAt resp.Field
Status resp.Field
ThreadID resp.Field
ToolChoice resp.Field
Tools resp.Field
TruncationStrategy resp.Field
Usage resp.Field
Temperature resp.Field
TopP resp.Field
ExpiredAt resp.Field
RunID resp.Field
StepDetails resp.Field
Type resp.Field
Delta resp.Field
Attachments resp.Field
Content resp.Field
IncompleteAt resp.Field
Role resp.Field
Code resp.Field
Message resp.Field
Param resp.Field
raw string
} `json:"-"`
}
func (r *AssistantStreamEventUnionData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// AssistantStreamEventUnionDataIncompleteDetails is an implicit subunion of
// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataIncompleteDetails
// provides convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [AssistantStreamEventUnion].
type AssistantStreamEventUnionDataIncompleteDetails struct {
Reason string `json:"reason"`
JSON struct {
Reason resp.Field
raw string
} `json:"-"`
}
func (r *AssistantStreamEventUnionDataIncompleteDetails) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// AssistantStreamEventUnionDataLastError is an implicit subunion of
// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataLastError provides
// convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [AssistantStreamEventUnion].
type AssistantStreamEventUnionDataLastError struct {
Code string `json:"code"`
Message string `json:"message"`
JSON struct {
Code resp.Field
Message resp.Field
raw string
} `json:"-"`
}
func (r *AssistantStreamEventUnionDataLastError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// AssistantStreamEventUnionDataUsage is an implicit subunion of
// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataUsage provides
// convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [AssistantStreamEventUnion].
type AssistantStreamEventUnionDataUsage struct {
CompletionTokens int64 `json:"completion_tokens"`
PromptTokens int64 `json:"prompt_tokens"`
TotalTokens int64 `json:"total_tokens"`
JSON struct {
CompletionTokens resp.Field
PromptTokens resp.Field
TotalTokens resp.Field
raw string
} `json:"-"`
}
func (r *AssistantStreamEventUnionDataUsage) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// AssistantStreamEventUnionDataDelta is an implicit subunion of
// [AssistantStreamEventUnion]. AssistantStreamEventUnionDataDelta provides
// convenient access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [AssistantStreamEventUnion].
type AssistantStreamEventUnionDataDelta struct {
// This field is from variant [RunStepDelta].
StepDetails RunStepDeltaStepDetailsUnion `json:"step_details"`
// This field is from variant [MessageDelta].
Content []MessageContentDeltaUnion `json:"content"`
// This field is from variant [MessageDelta].
Role MessageDeltaRole `json:"role"`
JSON struct {
StepDetails resp.Field
Content resp.Field
Role resp.Field
raw string
} `json:"-"`
}
func (r *AssistantStreamEventUnionDataDelta) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a new
// [thread](https://platform.openai.com/docs/api-reference/threads/object) is
// created.
type AssistantStreamEventThreadCreated struct {
// Represents a thread that contains
// [messages](https://platform.openai.com/docs/api-reference/messages).
Data Thread `json:"data,required"`
Event constant.ThreadCreated `json:"event,required"`
// Whether to enable input audio transcription.
Enabled bool `json:"enabled"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
Enabled resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadCreated) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadCreated) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a new
// [run](https://platform.openai.com/docs/api-reference/runs/object) is created.
type AssistantStreamEventThreadRunCreated struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunCreated `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunCreated) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunCreated) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// moves to a `queued` status.
type AssistantStreamEventThreadRunQueued struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunQueued `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunQueued) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunQueued) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// moves to an `in_progress` status.
type AssistantStreamEventThreadRunInProgress struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunInProgress `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunInProgress) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunInProgress) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// moves to a `requires_action` status.
type AssistantStreamEventThreadRunRequiresAction struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunRequiresAction `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunRequiresAction) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunRequiresAction) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// is completed.
type AssistantStreamEventThreadRunCompleted struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunCompleted `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunCompleted) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunCompleted) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// ends with status `incomplete`.
type AssistantStreamEventThreadRunIncomplete struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunIncomplete `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunIncomplete) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunIncomplete) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// fails.
type AssistantStreamEventThreadRunFailed struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunFailed `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunFailed) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunFailed) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// moves to a `cancelling` status.
type AssistantStreamEventThreadRunCancelling struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunCancelling `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunCancelling) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunCancelling) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Occurs when a [run](https://platform.openai.com/docs/api-reference/runs/object)
// is cancelled.
type AssistantStreamEventThreadRunCancelled struct {
// Represents an execution run on a
// [thread](https://platform.openai.com/docs/api-reference/threads).
Data Run `json:"data,required"`
Event constant.ThreadRunCancelled `json:"event,required"`
// Metadata for the response, check the presence of optional fields with the
// [resp.Field.IsPresent] method.
JSON struct {
Data resp.Field
Event resp.Field
ExtraFields map[string]resp.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r AssistantStreamEventThreadRunCancelled) RawJSON() string { return r.JSON.raw }
func (r *AssistantStreamEventThreadRunCancelled) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}