@@ -10,46 +10,43 @@ import (
10
10
const (
11
11
assistantsSuffix = "/assistants"
12
12
assistantsFilesSuffix = "/files"
13
+ openaiAssistantsV1 = "assistants=v1"
13
14
)
14
15
15
16
type Assistant struct {
16
- ID string `json:"id"`
17
- Object string `json:"object"`
18
- CreatedAt int64 `json:"created_at"`
19
- Name * string `json:"name,omitempty"`
20
- Description * string `json:"description,omitempty"`
21
- Model string `json:"model"`
22
- Instructions * string `json:"instructions,omitempty"`
23
- Tools []any `json:"tools,omitempty"`
17
+ ID string `json:"id"`
18
+ Object string `json:"object"`
19
+ CreatedAt int64 `json:"created_at"`
20
+ Name * string `json:"name,omitempty"`
21
+ Description * string `json:"description,omitempty"`
22
+ Model string `json:"model"`
23
+ Instructions * string `json:"instructions,omitempty"`
24
+ Tools []AssistantTool `json:"tools,omitempty"`
24
25
25
26
httpHeader
26
27
}
27
28
28
- type AssistantTool struct {
29
- Type string `json:"type"`
30
- }
31
-
32
- type AssistantToolCodeInterpreter struct {
33
- AssistantTool
34
- }
29
+ type AssistantToolType string
35
30
36
- type AssistantToolRetrieval struct {
37
- AssistantTool
38
- }
31
+ const (
32
+ AssistantToolTypeCodeInterpreter AssistantToolType = "code_interpreter"
33
+ AssistantToolTypeRetrieval AssistantToolType = "retrieval"
34
+ AssistantToolTypeFunction AssistantToolType = "function"
35
+ )
39
36
40
- type AssistantToolFunction struct {
41
- AssistantTool
42
- Function FunctionDefinition `json:"function"`
37
+ type AssistantTool struct {
38
+ Type AssistantToolType `json:"type"`
39
+ Function * FunctionDefinition `json:"function,omitempty "`
43
40
}
44
41
45
42
type AssistantRequest struct {
46
- Model string `json:"model"`
47
- Name * string `json:"name,omitempty"`
48
- Description * string `json:"description,omitempty"`
49
- Instructions * string `json:"instructions,omitempty"`
50
- Tools []any `json:"tools,omitempty"`
51
- FileIDs []string `json:"file_ids,omitempty"`
52
- Metadata map [string ]any `json:"metadata,omitempty"`
43
+ Model string `json:"model"`
44
+ Name * string `json:"name,omitempty"`
45
+ Description * string `json:"description,omitempty"`
46
+ Instructions * string `json:"instructions,omitempty"`
47
+ Tools []AssistantTool `json:"tools,omitempty"`
48
+ FileIDs []string `json:"file_ids,omitempty"`
49
+ Metadata map [string ]any `json:"metadata,omitempty"`
53
50
}
54
51
55
52
// AssistantsList is a list of assistants.
@@ -59,6 +56,14 @@ type AssistantsList struct {
59
56
httpHeader
60
57
}
61
58
59
+ type AssistantDeleteResponse struct {
60
+ ID string `json:"id"`
61
+ Object string `json:"object"`
62
+ Deleted bool `json:"deleted"`
63
+
64
+ httpHeader
65
+ }
66
+
62
67
type AssistantFile struct {
63
68
ID string `json:"id"`
64
69
Object string `json:"object"`
@@ -80,7 +85,8 @@ type AssistantFilesList struct {
80
85
81
86
// CreateAssistant creates a new assistant.
82
87
func (c * Client ) CreateAssistant (ctx context.Context , request AssistantRequest ) (response Assistant , err error ) {
83
- req , err := c .newRequest (ctx , http .MethodPost , c .fullURL (assistantsSuffix ), withBody (request ))
88
+ req , err := c .newRequest (ctx , http .MethodPost , c .fullURL (assistantsSuffix ), withBody (request ),
89
+ withBetaAssistantV1 ())
84
90
if err != nil {
85
91
return
86
92
}
@@ -95,7 +101,8 @@ func (c *Client) RetrieveAssistant(
95
101
assistantID string ,
96
102
) (response Assistant , err error ) {
97
103
urlSuffix := fmt .Sprintf ("%s/%s" , assistantsSuffix , assistantID )
98
- req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ))
104
+ req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ),
105
+ withBetaAssistantV1 ())
99
106
if err != nil {
100
107
return
101
108
}
@@ -111,7 +118,8 @@ func (c *Client) ModifyAssistant(
111
118
request AssistantRequest ,
112
119
) (response Assistant , err error ) {
113
120
urlSuffix := fmt .Sprintf ("%s/%s" , assistantsSuffix , assistantID )
114
- req , err := c .newRequest (ctx , http .MethodPost , c .fullURL (urlSuffix ), withBody (request ))
121
+ req , err := c .newRequest (ctx , http .MethodPost , c .fullURL (urlSuffix ), withBody (request ),
122
+ withBetaAssistantV1 ())
115
123
if err != nil {
116
124
return
117
125
}
@@ -124,9 +132,10 @@ func (c *Client) ModifyAssistant(
124
132
func (c * Client ) DeleteAssistant (
125
133
ctx context.Context ,
126
134
assistantID string ,
127
- ) (response Assistant , err error ) {
135
+ ) (response AssistantDeleteResponse , err error ) {
128
136
urlSuffix := fmt .Sprintf ("%s/%s" , assistantsSuffix , assistantID )
129
- req , err := c .newRequest (ctx , http .MethodDelete , c .fullURL (urlSuffix ))
137
+ req , err := c .newRequest (ctx , http .MethodDelete , c .fullURL (urlSuffix ),
138
+ withBetaAssistantV1 ())
130
139
if err != nil {
131
140
return
132
141
}
@@ -163,7 +172,8 @@ func (c *Client) ListAssistants(
163
172
}
164
173
165
174
urlSuffix := fmt .Sprintf ("%s%s" , assistantsSuffix , encodedValues )
166
- req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ))
175
+ req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ),
176
+ withBetaAssistantV1 ())
167
177
if err != nil {
168
178
return
169
179
}
@@ -180,7 +190,8 @@ func (c *Client) CreateAssistantFile(
180
190
) (response AssistantFile , err error ) {
181
191
urlSuffix := fmt .Sprintf ("%s/%s%s" , assistantsSuffix , assistantID , assistantsFilesSuffix )
182
192
req , err := c .newRequest (ctx , http .MethodPost , c .fullURL (urlSuffix ),
183
- withBody (request ))
193
+ withBody (request ),
194
+ withBetaAssistantV1 ())
184
195
if err != nil {
185
196
return
186
197
}
@@ -196,7 +207,8 @@ func (c *Client) RetrieveAssistantFile(
196
207
fileID string ,
197
208
) (response AssistantFile , err error ) {
198
209
urlSuffix := fmt .Sprintf ("%s/%s%s/%s" , assistantsSuffix , assistantID , assistantsFilesSuffix , fileID )
199
- req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ))
210
+ req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ),
211
+ withBetaAssistantV1 ())
200
212
if err != nil {
201
213
return
202
214
}
@@ -212,7 +224,8 @@ func (c *Client) DeleteAssistantFile(
212
224
fileID string ,
213
225
) (err error ) {
214
226
urlSuffix := fmt .Sprintf ("%s/%s%s/%s" , assistantsSuffix , assistantID , assistantsFilesSuffix , fileID )
215
- req , err := c .newRequest (ctx , http .MethodDelete , c .fullURL (urlSuffix ))
227
+ req , err := c .newRequest (ctx , http .MethodDelete , c .fullURL (urlSuffix ),
228
+ withBetaAssistantV1 ())
216
229
if err != nil {
217
230
return
218
231
}
@@ -250,7 +263,8 @@ func (c *Client) ListAssistantFiles(
250
263
}
251
264
252
265
urlSuffix := fmt .Sprintf ("%s/%s%s%s" , assistantsSuffix , assistantID , assistantsFilesSuffix , encodedValues )
253
- req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ))
266
+ req , err := c .newRequest (ctx , http .MethodGet , c .fullURL (urlSuffix ),
267
+ withBetaAssistantV1 ())
254
268
if err != nil {
255
269
return
256
270
}
0 commit comments