forked from openai/openai-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetachatkitsession.go
More file actions
83 lines (74 loc) · 3.38 KB
/
betachatkitsession.go
File metadata and controls
83 lines (74 loc) · 3.38 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package openai
import (
"context"
"errors"
"fmt"
"net/http"
"slices"
"github.com/openai/openai-go/v3/internal/apijson"
"github.com/openai/openai-go/v3/internal/requestconfig"
"github.com/openai/openai-go/v3/option"
"github.com/openai/openai-go/v3/packages/param"
)
// BetaChatKitSessionService 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 [NewBetaChatKitSessionService] method instead.
type BetaChatKitSessionService struct {
Options []option.RequestOption
}
// NewBetaChatKitSessionService 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 NewBetaChatKitSessionService(opts ...option.RequestOption) (r BetaChatKitSessionService) {
r = BetaChatKitSessionService{}
r.Options = opts
return
}
// Create a ChatKit session.
func (r *BetaChatKitSessionService) New(ctx context.Context, body BetaChatKitSessionNewParams, opts ...option.RequestOption) (res *ChatSession, err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "chatkit_beta=v1")}, opts...)
path := "chatkit/sessions"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, body, &res, opts...)
return res, err
}
// Cancel an active ChatKit session and return its most recent metadata.
//
// Cancelling prevents new requests from using the issued client secret.
func (r *BetaChatKitSessionService) Cancel(ctx context.Context, sessionID string, opts ...option.RequestOption) (res *ChatSession, err error) {
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("OpenAI-Beta", "chatkit_beta=v1")}, opts...)
if sessionID == "" {
err = errors.New("missing required session_id parameter")
return nil, err
}
path := fmt.Sprintf("chatkit/sessions/%s/cancel", sessionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return res, err
}
type BetaChatKitSessionNewParams struct {
// A free-form string that identifies your end user; ensures this Session can
// access other objects that have the same `user` scope.
User string `json:"user" api:"required"`
// Workflow that powers the session.
Workflow ChatSessionWorkflowParam `json:"workflow,omitzero" api:"required"`
// Optional overrides for ChatKit runtime configuration features
ChatKitConfiguration ChatSessionChatKitConfigurationParam `json:"chatkit_configuration,omitzero"`
// Optional override for session expiration timing in seconds from creation.
// Defaults to 10 minutes.
ExpiresAfter ChatSessionExpiresAfterParam `json:"expires_after,omitzero"`
// Optional override for per-minute request limits. When omitted, defaults to 10.
RateLimits ChatSessionRateLimitsParam `json:"rate_limits,omitzero"`
paramObj
}
func (r BetaChatKitSessionNewParams) MarshalJSON() (data []byte, err error) {
type shadow BetaChatKitSessionNewParams
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaChatKitSessionNewParams) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}