-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeinterpretersession.go
More file actions
138 lines (121 loc) · 5.03 KB
/
codeinterpretersession.go
File metadata and controls
138 lines (121 loc) · 5.03 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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package together
import (
"context"
"encoding/json"
"net/http"
"slices"
"time"
"github.com/togethercomputer/together-go/internal/apijson"
"github.com/togethercomputer/together-go/internal/requestconfig"
"github.com/togethercomputer/together-go/option"
"github.com/togethercomputer/together-go/packages/respjson"
)
// CodeInterpreterSessionService contains methods and other services that help with
// interacting with the together 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 [NewCodeInterpreterSessionService] method instead.
type CodeInterpreterSessionService struct {
Options []option.RequestOption
}
// NewCodeInterpreterSessionService 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 NewCodeInterpreterSessionService(opts ...option.RequestOption) (r CodeInterpreterSessionService) {
r = CodeInterpreterSessionService{}
r.Options = opts
return
}
// Lists all your currently active sessions.
func (r *CodeInterpreterSessionService) List(ctx context.Context, opts ...option.RequestOption) (res *SessionListResponse, err error) {
opts = slices.Concat(r.Options, opts)
path := "tci/sessions"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return res, err
}
type SessionListResponse struct {
Data SessionListResponseData `json:"data"`
Errors []SessionListResponseErrorUnion `json:"errors"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
Errors respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SessionListResponse) RawJSON() string { return r.JSON.raw }
func (r *SessionListResponse) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type SessionListResponseData struct {
Sessions []SessionListResponseDataSession `json:"sessions" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Sessions respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SessionListResponseData) RawJSON() string { return r.JSON.raw }
func (r *SessionListResponseData) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type SessionListResponseDataSession struct {
// Session Identifier. Used to make follow-up calls.
ID string `json:"id" api:"required"`
ExecuteCount int64 `json:"execute_count" api:"required"`
ExpiresAt time.Time `json:"expires_at" api:"required" format:"date-time"`
LastExecuteAt time.Time `json:"last_execute_at" api:"required" format:"date-time"`
StartedAt time.Time `json:"started_at" api:"required" format:"date-time"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ExecuteCount respjson.Field
ExpiresAt respjson.Field
LastExecuteAt respjson.Field
StartedAt respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r SessionListResponseDataSession) RawJSON() string { return r.JSON.raw }
func (r *SessionListResponseDataSession) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// SessionListResponseErrorUnion contains all possible properties and values from
// [string], [map[string]any].
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
//
// If the underlying value is not a json object, one of the following properties
// will be valid: OfString OfSessionListResponseErrorMapItem]
type SessionListResponseErrorUnion struct {
// This field will be present if the value is a [string] instead of an object.
OfString string `json:",inline"`
// This field will be present if the value is a [any] instead of an object.
OfSessionListResponseErrorMapItem any `json:",inline"`
JSON struct {
OfString respjson.Field
OfSessionListResponseErrorMapItem respjson.Field
raw string
} `json:"-"`
}
func (u SessionListResponseErrorUnion) AsString() (v string) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u SessionListResponseErrorUnion) AsAnyMap() (v map[string]any) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u SessionListResponseErrorUnion) RawJSON() string { return u.JSON.raw }
func (r *SessionListResponseErrorUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}