forked from openai/openai-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetachatkitthread.go
More file actions
1564 lines (1423 loc) · 60.5 KB
/
betachatkitthread.go
File metadata and controls
1564 lines (1423 loc) · 60.5 KB
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"
"slices"
"github.com/openai/openai-go/v3/internal/apijson"
"github.com/openai/openai-go/v3/internal/apiquery"
"github.com/openai/openai-go/v3/internal/requestconfig"
"github.com/openai/openai-go/v3/option"
"github.com/openai/openai-go/v3/packages/pagination"
"github.com/openai/openai-go/v3/packages/param"
"github.com/openai/openai-go/v3/packages/respjson"
"github.com/openai/openai-go/v3/shared/constant"
)
// BetaChatKitThreadService 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 [NewBetaChatKitThreadService] method instead.
type BetaChatKitThreadService struct {
Options []option.RequestOption
}
// NewBetaChatKitThreadService 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 NewBetaChatKitThreadService(opts ...option.RequestOption) (r BetaChatKitThreadService) {
r = BetaChatKitThreadService{}
r.Options = opts
return
}
// Retrieve a ChatKit thread by its identifier.
func (r *BetaChatKitThreadService) Get(ctx context.Context, threadID string, opts ...option.RequestOption) (res *ChatKitThread, err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "chatkit_beta=v1")}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return nil, err
}
path := fmt.Sprintf("chatkit/threads/%s", threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
// List ChatKit threads with optional pagination and user filters.
func (r *BetaChatKitThreadService) List(ctx context.Context, query BetaChatKitThreadListParams, opts ...option.RequestOption) (res *pagination.ConversationCursorPage[ChatKitThread], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "chatkit_beta=v1"), option.WithResponseInto(&raw)}, opts...)
path := "chatkit/threads"
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
}
// List ChatKit threads with optional pagination and user filters.
func (r *BetaChatKitThreadService) ListAutoPaging(ctx context.Context, query BetaChatKitThreadListParams, opts ...option.RequestOption) *pagination.ConversationCursorPageAutoPager[ChatKitThread] {
return pagination.NewConversationCursorPageAutoPager(r.List(ctx, query, opts...))
}
// Delete a ChatKit thread along with its items and stored attachments.
func (r *BetaChatKitThreadService) Delete(ctx context.Context, threadID string, opts ...option.RequestOption) (res *BetaChatKitThreadDeleteResponse, err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "chatkit_beta=v1")}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return nil, err
}
path := fmt.Sprintf("chatkit/threads/%s", threadID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodDelete, path, nil, &res, opts...)
return res, err
}
// List items that belong to a ChatKit thread.
func (r *BetaChatKitThreadService) ListItems(ctx context.Context, threadID string, query BetaChatKitThreadListItemsParams, opts ...option.RequestOption) (res *pagination.ConversationCursorPage[ChatKitThreadItemListDataUnion], err error) {
var raw *http.Response
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "chatkit_beta=v1"), option.WithResponseInto(&raw)}, opts...)
if threadID == "" {
err = errors.New("missing required thread_id parameter")
return nil, err
}
path := fmt.Sprintf("chatkit/threads/%s/items", threadID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, query, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List items that belong to a ChatKit thread.
func (r *BetaChatKitThreadService) ListItemsAutoPaging(ctx context.Context, threadID string, query BetaChatKitThreadListItemsParams, opts ...option.RequestOption) *pagination.ConversationCursorPageAutoPager[ChatKitThreadItemListDataUnion] {
return pagination.NewConversationCursorPageAutoPager(r.ListItems(ctx, threadID, query, opts...))
}
// Represents a ChatKit session and its resolved configuration.
type ChatSession struct {
// Identifier for the ChatKit session.
ID string `json:"id" api:"required"`
// Resolved ChatKit feature configuration for the session.
ChatKitConfiguration ChatSessionChatKitConfiguration `json:"chatkit_configuration" api:"required"`
// Ephemeral client secret that authenticates session requests.
ClientSecret string `json:"client_secret" api:"required"`
// Unix timestamp (in seconds) for when the session expires.
ExpiresAt int64 `json:"expires_at" api:"required"`
// Convenience copy of the per-minute request limit.
MaxRequestsPer1Minute int64 `json:"max_requests_per_1_minute" api:"required"`
// Type discriminator that is always `chatkit.session`.
Object constant.ChatKitSession `json:"object" api:"required"`
// Resolved rate limit values.
RateLimits ChatSessionRateLimits `json:"rate_limits" api:"required"`
// Current lifecycle state of the session.
//
// Any of "active", "expired", "cancelled".
Status ChatSessionStatus `json:"status" api:"required"`
// User identifier associated with the session.
User string `json:"user" api:"required"`
// Workflow metadata for the session.
Workflow ChatKitWorkflow `json:"workflow" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ChatKitConfiguration respjson.Field
ClientSecret respjson.Field
ExpiresAt respjson.Field
MaxRequestsPer1Minute respjson.Field
Object respjson.Field
RateLimits respjson.Field
Status respjson.Field
User respjson.Field
Workflow respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatSession) RawJSON() string { return r.JSON.raw }
func (r *ChatSession) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Automatic thread title preferences for the session.
type ChatSessionAutomaticThreadTitling struct {
// Whether automatic thread titling is enabled.
Enabled bool `json:"enabled" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Enabled respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatSessionAutomaticThreadTitling) RawJSON() string { return r.JSON.raw }
func (r *ChatSessionAutomaticThreadTitling) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ChatKit configuration for the session.
type ChatSessionChatKitConfiguration struct {
// Automatic thread titling preferences.
AutomaticThreadTitling ChatSessionAutomaticThreadTitling `json:"automatic_thread_titling" api:"required"`
// Upload settings for the session.
FileUpload ChatSessionFileUpload `json:"file_upload" api:"required"`
// History retention configuration.
History ChatSessionHistory `json:"history" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
AutomaticThreadTitling respjson.Field
FileUpload respjson.Field
History respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatSessionChatKitConfiguration) RawJSON() string { return r.JSON.raw }
func (r *ChatSessionChatKitConfiguration) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Optional per-session configuration settings for ChatKit behavior.
type ChatSessionChatKitConfigurationParam struct {
// Configuration for automatic thread titling. When omitted, automatic thread
// titling is enabled by default.
AutomaticThreadTitling ChatSessionChatKitConfigurationParamAutomaticThreadTitling `json:"automatic_thread_titling,omitzero"`
// Configuration for upload enablement and limits. When omitted, uploads are
// disabled by default (max_files 10, max_file_size 512 MB).
FileUpload ChatSessionChatKitConfigurationParamFileUpload `json:"file_upload,omitzero"`
// Configuration for chat history retention. When omitted, history is enabled by
// default with no limit on recent_threads (null).
History ChatSessionChatKitConfigurationParamHistory `json:"history,omitzero"`
paramObj
}
func (r ChatSessionChatKitConfigurationParam) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionChatKitConfigurationParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionChatKitConfigurationParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Configuration for automatic thread titling. When omitted, automatic thread
// titling is enabled by default.
type ChatSessionChatKitConfigurationParamAutomaticThreadTitling struct {
// Enable automatic thread title generation. Defaults to true.
Enabled param.Opt[bool] `json:"enabled,omitzero"`
paramObj
}
func (r ChatSessionChatKitConfigurationParamAutomaticThreadTitling) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionChatKitConfigurationParamAutomaticThreadTitling
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionChatKitConfigurationParamAutomaticThreadTitling) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Configuration for upload enablement and limits. When omitted, uploads are
// disabled by default (max_files 10, max_file_size 512 MB).
type ChatSessionChatKitConfigurationParamFileUpload struct {
// Enable uploads for this session. Defaults to false.
Enabled param.Opt[bool] `json:"enabled,omitzero"`
// Maximum size in megabytes for each uploaded file. Defaults to 512 MB, which is
// the maximum allowable size.
MaxFileSize param.Opt[int64] `json:"max_file_size,omitzero"`
// Maximum number of files that can be uploaded to the session. Defaults to 10.
MaxFiles param.Opt[int64] `json:"max_files,omitzero"`
paramObj
}
func (r ChatSessionChatKitConfigurationParamFileUpload) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionChatKitConfigurationParamFileUpload
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionChatKitConfigurationParamFileUpload) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Configuration for chat history retention. When omitted, history is enabled by
// default with no limit on recent_threads (null).
type ChatSessionChatKitConfigurationParamHistory struct {
// Enables chat users to access previous ChatKit threads. Defaults to true.
Enabled param.Opt[bool] `json:"enabled,omitzero"`
// Number of recent ChatKit threads users have access to. Defaults to unlimited
// when unset.
RecentThreads param.Opt[int64] `json:"recent_threads,omitzero"`
paramObj
}
func (r ChatSessionChatKitConfigurationParamHistory) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionChatKitConfigurationParamHistory
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionChatKitConfigurationParamHistory) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Controls when the session expires relative to an anchor timestamp.
//
// The properties Anchor, Seconds are required.
type ChatSessionExpiresAfterParam struct {
// Number of seconds after the anchor when the session expires.
Seconds int64 `json:"seconds" api:"required"`
// Base timestamp used to calculate expiration. Currently fixed to `created_at`.
//
// This field can be elided, and will marshal its zero value as "created_at".
Anchor constant.CreatedAt `json:"anchor" api:"required"`
paramObj
}
func (r ChatSessionExpiresAfterParam) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionExpiresAfterParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionExpiresAfterParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Upload permissions and limits applied to the session.
type ChatSessionFileUpload struct {
// Indicates if uploads are enabled for the session.
Enabled bool `json:"enabled" api:"required"`
// Maximum upload size in megabytes.
MaxFileSize int64 `json:"max_file_size" api:"required"`
// Maximum number of uploads allowed during the session.
MaxFiles int64 `json:"max_files" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Enabled respjson.Field
MaxFileSize respjson.Field
MaxFiles respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatSessionFileUpload) RawJSON() string { return r.JSON.raw }
func (r *ChatSessionFileUpload) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// History retention preferences returned for the session.
type ChatSessionHistory struct {
// Indicates if chat history is persisted for the session.
Enabled bool `json:"enabled" api:"required"`
// Number of prior threads surfaced in history views. Defaults to null when all
// history is retained.
RecentThreads int64 `json:"recent_threads" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Enabled respjson.Field
RecentThreads respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatSessionHistory) RawJSON() string { return r.JSON.raw }
func (r *ChatSessionHistory) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Active per-minute request limit for the session.
type ChatSessionRateLimits struct {
// Maximum allowed requests per one-minute window.
MaxRequestsPer1Minute int64 `json:"max_requests_per_1_minute" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
MaxRequestsPer1Minute respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatSessionRateLimits) RawJSON() string { return r.JSON.raw }
func (r *ChatSessionRateLimits) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Controls request rate limits for the session.
type ChatSessionRateLimitsParam struct {
// Maximum number of requests allowed per minute for the session. Defaults to 10.
MaxRequestsPer1Minute param.Opt[int64] `json:"max_requests_per_1_minute,omitzero"`
paramObj
}
func (r ChatSessionRateLimitsParam) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionRateLimitsParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionRateLimitsParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type ChatSessionStatus string
const (
ChatSessionStatusActive ChatSessionStatus = "active"
ChatSessionStatusExpired ChatSessionStatus = "expired"
ChatSessionStatusCancelled ChatSessionStatus = "cancelled"
)
// Workflow reference and overrides applied to the chat session.
//
// The property ID is required.
type ChatSessionWorkflowParam struct {
// Identifier for the workflow invoked by the session.
ID string `json:"id" api:"required"`
// Specific workflow version to run. Defaults to the latest deployed version.
Version param.Opt[string] `json:"version,omitzero"`
// State variables forwarded to the workflow. Keys may be up to 64 characters,
// values must be primitive types, and the map defaults to an empty object.
StateVariables map[string]ChatSessionWorkflowParamStateVariableUnion `json:"state_variables,omitzero"`
// Optional tracing overrides for the workflow invocation. When omitted, tracing is
// enabled by default.
Tracing ChatSessionWorkflowParamTracing `json:"tracing,omitzero"`
paramObj
}
func (r ChatSessionWorkflowParam) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionWorkflowParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionWorkflowParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Only one field can be non-zero.
//
// Use [param.IsOmitted] to confirm if a field is set.
type ChatSessionWorkflowParamStateVariableUnion struct {
OfString param.Opt[string] `json:",omitzero,inline"`
OfBool param.Opt[bool] `json:",omitzero,inline"`
OfFloat param.Opt[float64] `json:",omitzero,inline"`
paramUnion
}
func (u ChatSessionWorkflowParamStateVariableUnion) MarshalJSON() ([]byte, error) {
return param.MarshalUnion(u, u.OfString, u.OfBool, u.OfFloat)
}
func (u *ChatSessionWorkflowParamStateVariableUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, u)
}
func (u *ChatSessionWorkflowParamStateVariableUnion) asAny() any {
if !param.IsOmitted(u.OfString) {
return &u.OfString.Value
} else if !param.IsOmitted(u.OfBool) {
return &u.OfBool.Value
} else if !param.IsOmitted(u.OfFloat) {
return &u.OfFloat.Value
}
return nil
}
// Optional tracing overrides for the workflow invocation. When omitted, tracing is
// enabled by default.
type ChatSessionWorkflowParamTracing struct {
// Whether tracing is enabled during the session. Defaults to true.
Enabled param.Opt[bool] `json:"enabled,omitzero"`
paramObj
}
func (r ChatSessionWorkflowParamTracing) MarshalJSON() (data []byte, err error) {
type shadow ChatSessionWorkflowParamTracing
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *ChatSessionWorkflowParamTracing) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Attachment metadata included on thread items.
type ChatKitAttachment struct {
// Identifier for the attachment.
ID string `json:"id" api:"required"`
// MIME type of the attachment.
MimeType string `json:"mime_type" api:"required"`
// Original display name for the attachment.
Name string `json:"name" api:"required"`
// Preview URL for rendering the attachment inline.
PreviewURL string `json:"preview_url" api:"required"`
// Attachment discriminator.
//
// Any of "image", "file".
Type ChatKitAttachmentType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
MimeType respjson.Field
Name respjson.Field
PreviewURL respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitAttachment) RawJSON() string { return r.JSON.raw }
func (r *ChatKitAttachment) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Attachment discriminator.
type ChatKitAttachmentType string
const (
ChatKitAttachmentTypeImage ChatKitAttachmentType = "image"
ChatKitAttachmentTypeFile ChatKitAttachmentType = "file"
)
// Assistant response text accompanied by optional annotations.
type ChatKitResponseOutputText struct {
// Ordered list of annotations attached to the response text.
Annotations []ChatKitResponseOutputTextAnnotationUnion `json:"annotations" api:"required"`
// Assistant generated text.
Text string `json:"text" api:"required"`
// Type discriminator that is always `output_text`.
Type constant.OutputText `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Annotations respjson.Field
Text respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitResponseOutputText) RawJSON() string { return r.JSON.raw }
func (r *ChatKitResponseOutputText) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ChatKitResponseOutputTextAnnotationUnion contains all possible properties and
// values from [ChatKitResponseOutputTextAnnotationFile],
// [ChatKitResponseOutputTextAnnotationURL].
//
// Use the [ChatKitResponseOutputTextAnnotationUnion.AsAny] method to switch on the
// variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatKitResponseOutputTextAnnotationUnion struct {
// This field is a union of [ChatKitResponseOutputTextAnnotationFileSource],
// [ChatKitResponseOutputTextAnnotationURLSource]
Source ChatKitResponseOutputTextAnnotationUnionSource `json:"source"`
// Any of "file", "url".
Type string `json:"type"`
JSON struct {
Source respjson.Field
Type respjson.Field
raw string
} `json:"-"`
}
// anyChatKitResponseOutputTextAnnotation is implemented by each variant of
// [ChatKitResponseOutputTextAnnotationUnion] to add type safety for the return
// type of [ChatKitResponseOutputTextAnnotationUnion.AsAny]
type anyChatKitResponseOutputTextAnnotation interface {
implChatKitResponseOutputTextAnnotationUnion()
}
func (ChatKitResponseOutputTextAnnotationFile) implChatKitResponseOutputTextAnnotationUnion() {}
func (ChatKitResponseOutputTextAnnotationURL) implChatKitResponseOutputTextAnnotationUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := ChatKitResponseOutputTextAnnotationUnion.AsAny().(type) {
// case openai.ChatKitResponseOutputTextAnnotationFile:
// case openai.ChatKitResponseOutputTextAnnotationURL:
// default:
// fmt.Errorf("no variant present")
// }
func (u ChatKitResponseOutputTextAnnotationUnion) AsAny() anyChatKitResponseOutputTextAnnotation {
switch u.Type {
case "file":
return u.AsFile()
case "url":
return u.AsURL()
}
return nil
}
func (u ChatKitResponseOutputTextAnnotationUnion) AsFile() (v ChatKitResponseOutputTextAnnotationFile) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ChatKitResponseOutputTextAnnotationUnion) AsURL() (v ChatKitResponseOutputTextAnnotationURL) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ChatKitResponseOutputTextAnnotationUnion) RawJSON() string { return u.JSON.raw }
func (r *ChatKitResponseOutputTextAnnotationUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ChatKitResponseOutputTextAnnotationUnionSource is an implicit subunion of
// [ChatKitResponseOutputTextAnnotationUnion].
// ChatKitResponseOutputTextAnnotationUnionSource provides convenient access to the
// sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [ChatKitResponseOutputTextAnnotationUnion].
type ChatKitResponseOutputTextAnnotationUnionSource struct {
// This field is from variant [ChatKitResponseOutputTextAnnotationFileSource].
Filename string `json:"filename"`
Type string `json:"type"`
// This field is from variant [ChatKitResponseOutputTextAnnotationURLSource].
URL string `json:"url"`
JSON struct {
Filename respjson.Field
Type respjson.Field
URL respjson.Field
raw string
} `json:"-"`
}
func (r *ChatKitResponseOutputTextAnnotationUnionSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Annotation that references an uploaded file.
type ChatKitResponseOutputTextAnnotationFile struct {
// File attachment referenced by the annotation.
Source ChatKitResponseOutputTextAnnotationFileSource `json:"source" api:"required"`
// Type discriminator that is always `file` for this annotation.
Type constant.File `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Source respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitResponseOutputTextAnnotationFile) RawJSON() string { return r.JSON.raw }
func (r *ChatKitResponseOutputTextAnnotationFile) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// File attachment referenced by the annotation.
type ChatKitResponseOutputTextAnnotationFileSource struct {
// Filename referenced by the annotation.
Filename string `json:"filename" api:"required"`
// Type discriminator that is always `file`.
Type constant.File `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Filename respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitResponseOutputTextAnnotationFileSource) RawJSON() string { return r.JSON.raw }
func (r *ChatKitResponseOutputTextAnnotationFileSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Annotation that references a URL.
type ChatKitResponseOutputTextAnnotationURL struct {
// URL referenced by the annotation.
Source ChatKitResponseOutputTextAnnotationURLSource `json:"source" api:"required"`
// Type discriminator that is always `url` for this annotation.
Type constant.URL `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Source respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitResponseOutputTextAnnotationURL) RawJSON() string { return r.JSON.raw }
func (r *ChatKitResponseOutputTextAnnotationURL) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// URL referenced by the annotation.
type ChatKitResponseOutputTextAnnotationURLSource struct {
// Type discriminator that is always `url`.
Type constant.URL `json:"type" api:"required"`
// URL referenced by the annotation.
URL string `json:"url" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Type respjson.Field
URL respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitResponseOutputTextAnnotationURLSource) RawJSON() string { return r.JSON.raw }
func (r *ChatKitResponseOutputTextAnnotationURLSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Represents a ChatKit thread and its current status.
type ChatKitThread struct {
// Identifier of the thread.
ID string `json:"id" api:"required"`
// Unix timestamp (in seconds) for when the thread was created.
CreatedAt int64 `json:"created_at" api:"required"`
// Type discriminator that is always `chatkit.thread`.
Object constant.ChatKitThread `json:"object" api:"required"`
// Current status for the thread. Defaults to `active` for newly created threads.
Status ChatKitThreadStatusUnion `json:"status" api:"required"`
// Optional human-readable title for the thread. Defaults to null when no title has
// been generated.
Title string `json:"title" api:"required"`
// Free-form string that identifies your end user who owns the thread.
User string `json:"user" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
CreatedAt respjson.Field
Object respjson.Field
Status respjson.Field
Title respjson.Field
User respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitThread) RawJSON() string { return r.JSON.raw }
func (r *ChatKitThread) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ChatKitThreadStatusUnion contains all possible properties and values from
// [ChatKitThreadStatusActive], [ChatKitThreadStatusLocked],
// [ChatKitThreadStatusClosed].
//
// Use the [ChatKitThreadStatusUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatKitThreadStatusUnion struct {
// Any of "active", "locked", "closed".
Type string `json:"type"`
Reason string `json:"reason"`
JSON struct {
Type respjson.Field
Reason respjson.Field
raw string
} `json:"-"`
}
// anyChatKitThreadStatus is implemented by each variant of
// [ChatKitThreadStatusUnion] to add type safety for the return type of
// [ChatKitThreadStatusUnion.AsAny]
type anyChatKitThreadStatus interface {
implChatKitThreadStatusUnion()
}
func (ChatKitThreadStatusActive) implChatKitThreadStatusUnion() {}
func (ChatKitThreadStatusLocked) implChatKitThreadStatusUnion() {}
func (ChatKitThreadStatusClosed) implChatKitThreadStatusUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := ChatKitThreadStatusUnion.AsAny().(type) {
// case openai.ChatKitThreadStatusActive:
// case openai.ChatKitThreadStatusLocked:
// case openai.ChatKitThreadStatusClosed:
// default:
// fmt.Errorf("no variant present")
// }
func (u ChatKitThreadStatusUnion) AsAny() anyChatKitThreadStatus {
switch u.Type {
case "active":
return u.AsActive()
case "locked":
return u.AsLocked()
case "closed":
return u.AsClosed()
}
return nil
}
func (u ChatKitThreadStatusUnion) AsActive() (v ChatKitThreadStatusActive) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ChatKitThreadStatusUnion) AsLocked() (v ChatKitThreadStatusLocked) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u ChatKitThreadStatusUnion) AsClosed() (v ChatKitThreadStatusClosed) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u ChatKitThreadStatusUnion) RawJSON() string { return u.JSON.raw }
func (r *ChatKitThreadStatusUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Indicates that a thread is active.
type ChatKitThreadStatusActive struct {
// Status discriminator that is always `active`.
Type constant.Active `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitThreadStatusActive) RawJSON() string { return r.JSON.raw }
func (r *ChatKitThreadStatusActive) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Indicates that a thread is locked and cannot accept new input.
type ChatKitThreadStatusLocked struct {
// Reason that the thread was locked. Defaults to null when no reason is recorded.
Reason string `json:"reason" api:"required"`
// Status discriminator that is always `locked`.
Type constant.Locked `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Reason respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitThreadStatusLocked) RawJSON() string { return r.JSON.raw }
func (r *ChatKitThreadStatusLocked) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Indicates that a thread has been closed.
type ChatKitThreadStatusClosed struct {
// Reason that the thread was closed. Defaults to null when no reason is recorded.
Reason string `json:"reason" api:"required"`
// Status discriminator that is always `closed`.
Type constant.Closed `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Reason respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitThreadStatusClosed) RawJSON() string { return r.JSON.raw }
func (r *ChatKitThreadStatusClosed) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Assistant-authored message within a thread.
type ChatKitThreadAssistantMessageItem struct {
// Identifier of the thread item.
ID string `json:"id" api:"required"`
// Ordered assistant response segments.
Content []ChatKitResponseOutputText `json:"content" api:"required"`
// Unix timestamp (in seconds) for when the item was created.
CreatedAt int64 `json:"created_at" api:"required"`
// Type discriminator that is always `chatkit.thread_item`.
Object constant.ChatKitThreadItem `json:"object" api:"required"`
// Identifier of the parent thread.
ThreadID string `json:"thread_id" api:"required"`
// Type discriminator that is always `chatkit.assistant_message`.
Type constant.ChatKitAssistantMessage `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Content respjson.Field
CreatedAt respjson.Field
Object respjson.Field
ThreadID respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitThreadAssistantMessageItem) RawJSON() string { return r.JSON.raw }
func (r *ChatKitThreadAssistantMessageItem) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// A paginated list of thread items rendered for the ChatKit API.
type ChatKitThreadItemList struct {
// A list of items
Data []ChatKitThreadItemListDataUnion `json:"data" api:"required"`
// The ID of the first item in the list.
FirstID string `json:"first_id" api:"required"`
// Whether there are more items available.
HasMore bool `json:"has_more" api:"required"`
// The ID of the last item in the list.
LastID string `json:"last_id" api:"required"`
// The type of object returned, must be `list`.
Object constant.List `json:"object" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
FirstID respjson.Field
HasMore respjson.Field
LastID respjson.Field
Object respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r ChatKitThreadItemList) RawJSON() string { return r.JSON.raw }
func (r *ChatKitThreadItemList) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ChatKitThreadItemListDataUnion contains all possible properties and values from
// [ChatKitThreadUserMessageItem], [ChatKitThreadAssistantMessageItem],
// [ChatKitWidgetItem], [ChatKitThreadItemListDataChatKitClientToolCall],
// [ChatKitThreadItemListDataChatKitTask],
// [ChatKitThreadItemListDataChatKitTaskGroup].
//
// Use the [ChatKitThreadItemListDataUnion.AsAny] method to switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type ChatKitThreadItemListDataUnion struct {
ID string `json:"id"`
// This field is from variant [ChatKitThreadUserMessageItem].
Attachments []ChatKitAttachment `json:"attachments"`
// This field is a union of [[]ChatKitThreadUserMessageItemContentUnion],
// [[]ChatKitResponseOutputText]
Content ChatKitThreadItemListDataUnionContent `json:"content"`
CreatedAt int64 `json:"created_at"`
// This field is from variant [ChatKitThreadUserMessageItem].
InferenceOptions ChatKitThreadUserMessageItemInferenceOptions `json:"inference_options"`
// This field is from variant [ChatKitThreadUserMessageItem].
Object constant.ChatKitThreadItem `json:"object"`
ThreadID string `json:"thread_id"`
// Any of "chatkit.user_message", "chatkit.assistant_message", "chatkit.widget",
// "chatkit.client_tool_call", "chatkit.task", "chatkit.task_group".
Type string `json:"type"`
// This field is from variant [ChatKitWidgetItem].
Widget string `json:"widget"`
// This field is from variant [ChatKitThreadItemListDataChatKitClientToolCall].
Arguments string `json:"arguments"`
// This field is from variant [ChatKitThreadItemListDataChatKitClientToolCall].
CallID string `json:"call_id"`
// This field is from variant [ChatKitThreadItemListDataChatKitClientToolCall].
Name string `json:"name"`
// This field is from variant [ChatKitThreadItemListDataChatKitClientToolCall].
Output string `json:"output"`
// This field is from variant [ChatKitThreadItemListDataChatKitClientToolCall].
Status string `json:"status"`
// This field is from variant [ChatKitThreadItemListDataChatKitTask].
Heading string `json:"heading"`
// This field is from variant [ChatKitThreadItemListDataChatKitTask].
Summary string `json:"summary"`
// This field is from variant [ChatKitThreadItemListDataChatKitTask].
TaskType string `json:"task_type"`
// This field is from variant [ChatKitThreadItemListDataChatKitTaskGroup].
Tasks []ChatKitThreadItemListDataChatKitTaskGroupTask `json:"tasks"`
JSON struct {
ID respjson.Field
Attachments respjson.Field
Content respjson.Field
CreatedAt respjson.Field
InferenceOptions respjson.Field
Object respjson.Field
ThreadID respjson.Field
Type respjson.Field
Widget respjson.Field
Arguments respjson.Field
CallID respjson.Field
Name respjson.Field
Output respjson.Field
Status respjson.Field
Heading respjson.Field
Summary respjson.Field
TaskType respjson.Field
Tasks respjson.Field
raw string
} `json:"-"`
}
// anyChatKitThreadItemListData is implemented by each variant of
// [ChatKitThreadItemListDataUnion] to add type safety for the return type of