forked from openai/openai-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages.ts
343 lines (295 loc) · 9.15 KB
/
messages.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
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
// 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 MessagesAPI from 'openai/resources/beta/threads/messages/messages';
import * as FilesAPI from 'openai/resources/beta/threads/messages/files';
import { CursorPage, type CursorPageParams } from 'openai/pagination';
export class Messages extends APIResource {
files: FilesAPI.Files = new FilesAPI.Files(this.client);
/**
* Create a message.
*/
create(
threadId: string,
body: MessageCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<ThreadMessage> {
return this.post(`/threads/${threadId}/messages`, {
body,
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
/**
* Retrieve a message.
*/
retrieve(
threadId: string,
messageId: string,
options?: Core.RequestOptions,
): Core.APIPromise<ThreadMessage> {
return this.get(`/threads/${threadId}/messages/${messageId}`, {
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
/**
* Modifies a message.
*/
update(
threadId: string,
messageId: string,
body: MessageUpdateParams,
options?: Core.RequestOptions,
): Core.APIPromise<ThreadMessage> {
return this.post(`/threads/${threadId}/messages/${messageId}`, {
body,
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
/**
* Returns a list of messages for a given thread.
*/
list(
threadId: string,
query?: MessageListParams,
options?: Core.RequestOptions,
): Core.PagePromise<ThreadMessagesPage, ThreadMessage>;
list(threadId: string, options?: Core.RequestOptions): Core.PagePromise<ThreadMessagesPage, ThreadMessage>;
list(
threadId: string,
query: MessageListParams | Core.RequestOptions = {},
options?: Core.RequestOptions,
): Core.PagePromise<ThreadMessagesPage, ThreadMessage> {
if (isRequestOptions(query)) {
return this.list(threadId, {}, query);
}
return this.getAPIList(`/threads/${threadId}/messages`, ThreadMessagesPage, {
query,
...options,
headers: { 'OpenAI-Beta': 'assistants=v1', ...options?.headers },
});
}
}
export class ThreadMessagesPage extends CursorPage<ThreadMessage> {}
/**
* References an image [File](https://platform.openai.com/docs/api-reference/files)
* in the content of a message.
*/
export interface MessageContentImageFile {
image_file: MessageContentImageFile.ImageFile;
/**
* Always `image_file`.
*/
type: 'image_file';
}
export namespace MessageContentImageFile {
export interface ImageFile {
/**
* The [File](https://platform.openai.com/docs/api-reference/files) ID of the image
* in the message content.
*/
file_id: string;
}
}
/**
* The text content that is part of a message.
*/
export interface MessageContentText {
text: MessageContentText.Text;
/**
* Always `text`.
*/
type: 'text';
}
export namespace MessageContentText {
export interface Text {
annotations: Array<Text.FileCitation | Text.FilePath>;
/**
* The data that makes up the text.
*/
value: string;
}
export namespace Text {
/**
* A citation within the message that points to a specific quote from a specific
* File associated with the assistant or the message. Generated when the assistant
* uses the "retrieval" tool to search files.
*/
export interface FileCitation {
end_index: number;
file_citation: FileCitation.FileCitation;
start_index: number;
/**
* The text in the message content that needs to be replaced.
*/
text: string;
/**
* Always `file_citation`.
*/
type: 'file_citation';
}
export namespace FileCitation {
export interface FileCitation {
/**
* The ID of the specific File the citation is from.
*/
file_id: string;
/**
* The specific quote in the file.
*/
quote: string;
}
}
/**
* A URL for the file that's generated when the assistant used the
* `code_interpreter` tool to generate a file.
*/
export interface FilePath {
end_index: number;
file_path: FilePath.FilePath;
start_index: number;
/**
* The text in the message content that needs to be replaced.
*/
text: string;
/**
* Always `file_path`.
*/
type: 'file_path';
}
export namespace FilePath {
export interface FilePath {
/**
* The ID of the file that was generated.
*/
file_id: string;
}
}
}
}
/**
* Represents a message within a
* [thread](https://platform.openai.com/docs/api-reference/threads).
*/
export interface ThreadMessage {
/**
* The identifier, which can be referenced in API endpoints.
*/
id: string;
/**
* If applicable, the ID of the
* [assistant](https://platform.openai.com/docs/api-reference/assistants) that
* authored this message.
*/
assistant_id: string | null;
/**
* The content of the message in array of text and/or images.
*/
content: Array<MessageContentImageFile | MessageContentText>;
/**
* The Unix timestamp (in seconds) for when the message was created.
*/
created_at: number;
/**
* A list of [file](https://platform.openai.com/docs/api-reference/files) IDs that
* the assistant should use. Useful for tools like retrieval and code_interpreter
* that can access files. A maximum of 10 files can be attached to a message.
*/
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;
/**
* The object type, which is always `thread.message`.
*/
object: 'thread.message';
/**
* The entity that produced the message. One of `user` or `assistant`.
*/
role: 'user' | 'assistant';
/**
* If applicable, the ID of the
* [run](https://platform.openai.com/docs/api-reference/runs) associated with the
* authoring of this message.
*/
run_id: string | null;
/**
* The [thread](https://platform.openai.com/docs/api-reference/threads) ID that
* this message belongs to.
*/
thread_id: string;
}
export interface ThreadMessageDeleted {
id: string;
deleted: boolean;
object: 'thread.message.deleted';
}
export interface MessageCreateParams {
/**
* 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 MessageUpdateParams {
/**
* 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 MessageListParams extends CursorPageParams {
/**
* A cursor for use in pagination. `before` is an object ID that defines your place
* in the list. For instance, if you make a list request and receive 100 objects,
* ending with obj_foo, your subsequent call can include before=obj_foo in order to
* fetch the previous page of the list.
*/
before?: string;
/**
* Sort order by the `created_at` timestamp of the objects. `asc` for ascending
* order and `desc` for descending order.
*/
order?: 'asc' | 'desc';
}
export namespace 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;
export import Files = FilesAPI.Files;
export import MessageFile = FilesAPI.MessageFile;
export import MessageFilesPage = FilesAPI.MessageFilesPage;
export import FileListParams = FilesAPI.FileListParams;
}