forked from openai/openai-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreads.ts
315 lines (277 loc) · 9.75 KB
/
threads.ts
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
// File generated from our OpenAPI spec by Stainless.
import * as Core from 'openai/core';
import { APIResource } from 'openai/resource';
import { isRequestOptions } from 'openai/core';
import * as ThreadsAPI from 'openai/resources/beta/threads/threads';
import * as Shared from 'openai/resources/shared';
import * as MessagesAPI from 'openai/resources/beta/threads/messages/messages';
import * as RunsAPI from 'openai/resources/beta/threads/runs/runs';
export class Threads extends APIResource {
runs: RunsAPI.Runs = new RunsAPI.Runs(this.client);
messages: MessagesAPI.Messages = new MessagesAPI.Messages(this.client);
/**
* Create a thread.
*/
create(body?: ThreadCreateParams, options?: Core.RequestOptions): Core.APIPromise<Thread>;
create(options?: Core.RequestOptions): Core.APIPromise<Thread>;
create(
body: ThreadCreateParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.APIPromise<Thread> {
if (isRequestOptions(body)) {
return this.create({}, body);
}
return this.post('/threads', {
body,
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
/**
* Retrieves a thread.
*/
retrieve(threadId: string, options?: Core.RequestOptions): Core.APIPromise<Thread> {
return this.get(`/threads/${threadId}`, {
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
/**
* Modifies a thread.
*/
update(threadId: string, body: ThreadUpdateParams, options?: Core.RequestOptions): Core.APIPromise<Thread> {
return this.post(`/threads/${threadId}`, {
body,
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
/**
* Delete a thread.
*/
del(threadId: string, options?: Core.RequestOptions): Core.APIPromise<ThreadDeleted> {
return this.delete(`/threads/${threadId}`, {
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
/**
* Create a thread and run it in one request.
*/
createAndRun(body: ThreadCreateAndRunParams, options?: Core.RequestOptions): Core.APIPromise<RunsAPI.Run> {
return this.post('/threads/runs', {
body,
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
}
/**
* Represents a thread that contains
* [messages](https://platform.openai.com/docs/api-reference/messages).
*/
export interface Thread {
/**
* The identifier, which can be referenced in API endpoints.
*/
id: string;
/**
* The Unix timestamp (in seconds) for when the thread was created.
*/
created_at: number;
/**
* 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. Keys
* can be a maximum of 64 characters long and values can be a maxium of 512
* characters long.
*/
metadata: unknown | null;
/**
* The object type, which is always `thread`.
*/
object: 'thread';
}
export interface ThreadDeleted {
id: string;
deleted: boolean;
object: 'thread.deleted';
}
export interface ThreadCreateParams {
/**
* A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
* start the thread with.
*/
messages?: Array<ThreadCreateParams.Message>;
/**
* 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. Keys
* can be a maximum of 64 characters long and values can be a maxium of 512
* characters long.
*/
metadata?: unknown | null;
}
export namespace ThreadCreateParams {
export interface Message {
/**
* The content of the message.
*/
content: string;
/**
* The role of the entity that is creating the message. Currently only `user` is
* supported.
*/
role: 'user';
/**
* A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
* the message should use. There can be a maximum of 10 files attached to a
* message. Useful for tools like `retrieval` and `code_interpreter` that can
* access and use files.
*/
file_ids?: Array<string>;
/**
* 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. Keys
* can be a maximum of 64 characters long and values can be a maxium of 512
* characters long.
*/
metadata?: unknown | null;
}
}
export interface ThreadUpdateParams {
/**
* 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. Keys
* can be a maximum of 64 characters long and values can be a maxium of 512
* characters long.
*/
metadata?: unknown | null;
}
export interface ThreadCreateAndRunParams {
/**
* The ID of the
* [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
* execute this run.
*/
assistant_id: string;
/**
* Override the default system message of the assistant. This is useful for
* modifying the behavior on a per-run basis.
*/
instructions?: string | null;
/**
* 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. Keys
* can be a maximum of 64 characters long and values can be a maxium of 512
* characters long.
*/
metadata?: unknown | null;
/**
* The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
* be used to execute this run. If a value is provided here, it will override the
* model associated with the assistant. If not, the model associated with the
* assistant will be used.
*/
model?: string | null;
/**
* If no thread is provided, an empty thread will be created.
*/
thread?: ThreadCreateAndRunParams.Thread;
/**
* Override the tools the assistant can use for this run. This is useful for
* modifying the behavior on a per-run basis.
*/
tools?: Array<
| ThreadCreateAndRunParams.AssistantToolsCode
| ThreadCreateAndRunParams.AssistantToolsRetrieval
| ThreadCreateAndRunParams.AssistantToolsFunction
> | null;
}
export namespace ThreadCreateAndRunParams {
/**
* If no thread is provided, an empty thread will be created.
*/
export interface Thread {
/**
* A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
* start the thread with.
*/
messages?: Array<Thread.Message>;
/**
* 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. Keys
* can be a maximum of 64 characters long and values can be a maxium of 512
* characters long.
*/
metadata?: unknown | null;
}
export namespace Thread {
export interface Message {
/**
* The content of the message.
*/
content: string;
/**
* The role of the entity that is creating the message. Currently only `user` is
* supported.
*/
role: 'user';
/**
* A list of [File](https://platform.openai.com/docs/api-reference/files) IDs that
* the message should use. There can be a maximum of 10 files attached to a
* message. Useful for tools like `retrieval` and `code_interpreter` that can
* access and use files.
*/
file_ids?: Array<string>;
/**
* 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. Keys
* can be a maximum of 64 characters long and values can be a maxium of 512
* characters long.
*/
metadata?: unknown | null;
}
}
export interface AssistantToolsCode {
/**
* The type of tool being defined: `code_interpreter`
*/
type: 'code_interpreter';
}
export interface AssistantToolsRetrieval {
/**
* The type of tool being defined: `retrieval`
*/
type: 'retrieval';
}
export interface AssistantToolsFunction {
function: Shared.FunctionDefinition;
/**
* The type of tool being defined: `function`
*/
type: 'function';
}
}
export namespace Threads {
export import Thread = ThreadsAPI.Thread;
export import ThreadDeleted = ThreadsAPI.ThreadDeleted;
export import ThreadCreateParams = ThreadsAPI.ThreadCreateParams;
export import ThreadUpdateParams = ThreadsAPI.ThreadUpdateParams;
export import ThreadCreateAndRunParams = ThreadsAPI.ThreadCreateAndRunParams;
export import Runs = RunsAPI.Runs;
export import RequiredActionFunctionToolCall = RunsAPI.RequiredActionFunctionToolCall;
export import Run = RunsAPI.Run;
export import RunsPage = RunsAPI.RunsPage;
export import RunCreateParams = RunsAPI.RunCreateParams;
export import RunUpdateParams = RunsAPI.RunUpdateParams;
export import RunListParams = RunsAPI.RunListParams;
export import RunSubmitToolOutputsParams = RunsAPI.RunSubmitToolOutputsParams;
export import Messages = MessagesAPI.Messages;
export import MessageContentImageFile = MessagesAPI.MessageContentImageFile;
export import MessageContentText = MessagesAPI.MessageContentText;
export import ThreadMessage = MessagesAPI.ThreadMessage;
export import ThreadMessageDeleted = MessagesAPI.ThreadMessageDeleted;
export import ThreadMessagesPage = MessagesAPI.ThreadMessagesPage;
export import MessageCreateParams = MessagesAPI.MessageCreateParams;
export import MessageUpdateParams = MessagesAPI.MessageUpdateParams;
export import MessageListParams = MessagesAPI.MessageListParams;
}