openai 4.86.2 → 4.87.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/README.md +50 -101
- package/core.js +2 -1
- package/core.js.map +1 -1
- package/core.mjs +2 -1
- package/core.mjs.map +1 -1
- package/helpers/zod.d.ts +14 -1
- package/helpers/zod.d.ts.map +1 -1
- package/helpers/zod.js +25 -1
- package/helpers/zod.js.map +1 -1
- package/helpers/zod.mjs +23 -1
- package/helpers/zod.mjs.map +1 -1
- package/index.d.mts +14 -3
- package/index.d.ts +14 -3
- package/index.d.ts.map +1 -1
- package/index.js +8 -0
- package/index.js.map +1 -1
- package/index.mjs +8 -0
- package/index.mjs.map +1 -1
- package/lib/ResponsesParser.d.ts +33 -0
- package/lib/ResponsesParser.d.ts.map +1 -0
- package/lib/ResponsesParser.js +171 -0
- package/lib/ResponsesParser.js.map +1 -0
- package/lib/ResponsesParser.mjs +160 -0
- package/lib/ResponsesParser.mjs.map +1 -0
- package/lib/parser.d.ts +7 -0
- package/lib/parser.d.ts.map +1 -1
- package/lib/parser.js +16 -1
- package/lib/parser.js.map +1 -1
- package/lib/parser.mjs +14 -0
- package/lib/parser.mjs.map +1 -1
- package/lib/responses/EventTypes.d.ts +9 -0
- package/lib/responses/EventTypes.d.ts.map +1 -0
- package/lib/responses/EventTypes.js +3 -0
- package/lib/responses/EventTypes.js.map +1 -0
- package/lib/responses/EventTypes.mjs +2 -0
- package/lib/responses/EventTypes.mjs.map +1 -0
- package/lib/responses/ResponseStream.d.ts +34 -0
- package/lib/responses/ResponseStream.d.ts.map +1 -0
- package/lib/responses/ResponseStream.js +238 -0
- package/lib/responses/ResponseStream.js.map +1 -0
- package/lib/responses/ResponseStream.mjs +234 -0
- package/lib/responses/ResponseStream.mjs.map +1 -0
- package/package.json +1 -1
- package/resources/beta/assistants.d.ts +41 -9
- package/resources/beta/assistants.d.ts.map +1 -1
- package/resources/beta/assistants.js.map +1 -1
- package/resources/beta/assistants.mjs.map +1 -1
- package/resources/beta/beta.d.ts +0 -4
- package/resources/beta/beta.d.ts.map +1 -1
- package/resources/beta/beta.js +0 -5
- package/resources/beta/beta.js.map +1 -1
- package/resources/beta/beta.mjs +0 -5
- package/resources/beta/beta.mjs.map +1 -1
- package/resources/beta/index.d.ts +0 -1
- package/resources/beta/index.d.ts.map +1 -1
- package/resources/beta/index.js +1 -4
- package/resources/beta/index.js.map +1 -1
- package/resources/beta/index.mjs +0 -1
- package/resources/beta/index.mjs.map +1 -1
- package/resources/beta/threads/runs/runs.d.ts +3 -4
- package/resources/beta/threads/runs/runs.d.ts.map +1 -1
- package/resources/beta/threads/runs/runs.js.map +1 -1
- package/resources/beta/threads/runs/runs.mjs.map +1 -1
- package/resources/beta/threads/threads.d.ts +73 -7
- package/resources/beta/threads/threads.d.ts.map +1 -1
- package/resources/beta/threads/threads.js.map +1 -1
- package/resources/beta/threads/threads.mjs.map +1 -1
- package/resources/chat/chat.d.ts +3 -2
- package/resources/chat/chat.d.ts.map +1 -1
- package/resources/chat/chat.js.map +1 -1
- package/resources/chat/chat.mjs.map +1 -1
- package/resources/chat/completions/completions.d.ts +200 -64
- package/resources/chat/completions/completions.d.ts.map +1 -1
- package/resources/chat/completions/completions.js +3 -3
- package/resources/chat/completions/completions.js.map +1 -1
- package/resources/chat/completions/completions.mjs +3 -3
- package/resources/chat/completions/completions.mjs.map +1 -1
- package/resources/chat/completions/index.d.ts +1 -1
- package/resources/chat/completions/index.d.ts.map +1 -1
- package/resources/chat/completions/index.js.map +1 -1
- package/resources/chat/completions/index.mjs.map +1 -1
- package/resources/chat/completions/messages.d.ts +1 -1
- package/resources/chat/index.d.ts +2 -2
- package/resources/chat/index.d.ts.map +1 -1
- package/resources/chat/index.js.map +1 -1
- package/resources/chat/index.mjs.map +1 -1
- package/resources/files.d.ts +9 -17
- package/resources/files.d.ts.map +1 -1
- package/resources/files.js.map +1 -1
- package/resources/files.mjs.map +1 -1
- package/resources/index.d.ts +2 -0
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js +7 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs +2 -0
- package/resources/index.mjs.map +1 -1
- package/resources/responses/index.d.ts +3 -0
- package/resources/responses/index.d.ts.map +1 -0
- package/resources/responses/index.js +10 -0
- package/resources/responses/index.js.map +1 -0
- package/resources/responses/index.mjs +4 -0
- package/resources/responses/index.mjs.map +1 -0
- package/resources/responses/input-items.d.ts +169 -0
- package/resources/responses/input-items.d.ts.map +1 -0
- package/resources/responses/input-items.js +24 -0
- package/resources/responses/input-items.js.map +1 -0
- package/resources/responses/input-items.mjs +19 -0
- package/resources/responses/input-items.mjs.map +1 -0
- package/resources/responses/responses.d.ts +2230 -0
- package/resources/responses/responses.d.ts.map +1 -0
- package/resources/responses/responses.js +77 -0
- package/resources/responses/responses.js.map +1 -0
- package/resources/responses/responses.mjs +50 -0
- package/resources/responses/responses.mjs.map +1 -0
- package/resources/shared.d.ts +99 -4
- package/resources/shared.d.ts.map +1 -1
- package/resources/uploads/uploads.d.ts +3 -4
- package/resources/uploads/uploads.d.ts.map +1 -1
- package/resources/uploads/uploads.js +3 -4
- package/resources/uploads/uploads.js.map +1 -1
- package/resources/uploads/uploads.mjs +3 -4
- package/resources/uploads/uploads.mjs.map +1 -1
- package/resources/{beta/vector-stores → vector-stores}/file-batches.d.ts +12 -4
- package/resources/vector-stores/file-batches.d.ts.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/file-batches.js +4 -4
- package/resources/vector-stores/file-batches.js.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/file-batches.mjs +4 -4
- package/resources/vector-stores/file-batches.mjs.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/files.d.ts +54 -5
- package/resources/vector-stores/files.d.ts.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/files.js +27 -4
- package/resources/vector-stores/files.js.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/files.mjs +25 -3
- package/resources/vector-stores/files.mjs.map +1 -0
- package/resources/vector-stores/index.d.ts +4 -0
- package/resources/vector-stores/index.d.ts.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/index.js +3 -1
- package/resources/vector-stores/index.js.map +1 -0
- package/resources/vector-stores/index.mjs +5 -0
- package/resources/vector-stores/index.mjs.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/vector-stores.d.ts +90 -7
- package/resources/vector-stores/vector-stores.d.ts.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/vector-stores.js +24 -4
- package/resources/vector-stores/vector-stores.js.map +1 -0
- package/resources/{beta/vector-stores → vector-stores}/vector-stores.mjs +23 -4
- package/resources/vector-stores/vector-stores.mjs.map +1 -0
- package/src/core.ts +2 -2
- package/src/helpers/zod.ts +46 -0
- package/src/index.ts +54 -4
- package/src/lib/ResponsesParser.ts +262 -0
- package/src/lib/parser.ts +28 -0
- package/src/lib/responses/EventTypes.ts +76 -0
- package/src/lib/responses/ResponseStream.ts +298 -0
- package/src/resources/beta/assistants.ts +46 -9
- package/src/resources/beta/beta.ts +0 -37
- package/src/resources/beta/index.ts +0 -16
- package/src/resources/beta/threads/runs/runs.ts +3 -4
- package/src/resources/beta/threads/threads.ts +83 -7
- package/src/resources/chat/chat.ts +3 -43
- package/src/resources/chat/completions/completions.ts +224 -66
- package/src/resources/chat/completions/index.ts +0 -1
- package/src/resources/chat/completions/messages.ts +1 -1
- package/src/resources/chat/index.ts +1 -2
- package/src/resources/files.ts +9 -17
- package/src/resources/index.ts +20 -0
- package/src/resources/responses/index.ts +9 -0
- package/src/resources/responses/input-items.ts +276 -0
- package/src/resources/responses/responses.ts +2761 -0
- package/src/resources/shared.ts +152 -4
- package/src/resources/uploads/uploads.ts +3 -4
- package/src/resources/{beta/vector-stores → vector-stores}/file-batches.ts +16 -7
- package/src/resources/{beta/vector-stores → vector-stores}/files.ts +85 -4
- package/src/resources/{beta/vector-stores → vector-stores}/index.ts +6 -0
- package/src/resources/{beta/vector-stores → vector-stores}/vector-stores.ts +125 -5
- package/src/streaming.ts +1 -1
- package/src/version.ts +1 -1
- package/streaming.js +1 -1
- package/streaming.js.map +1 -1
- package/streaming.mjs +1 -1
- package/streaming.mjs.map +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/resources/beta/vector-stores/file-batches.d.ts.map +0 -1
- package/resources/beta/vector-stores/file-batches.js.map +0 -1
- package/resources/beta/vector-stores/file-batches.mjs.map +0 -1
- package/resources/beta/vector-stores/files.d.ts.map +0 -1
- package/resources/beta/vector-stores/files.js.map +0 -1
- package/resources/beta/vector-stores/files.mjs.map +0 -1
- package/resources/beta/vector-stores/index.d.ts +0 -4
- package/resources/beta/vector-stores/index.d.ts.map +0 -1
- package/resources/beta/vector-stores/index.js.map +0 -1
- package/resources/beta/vector-stores/index.mjs +0 -5
- package/resources/beta/vector-stores/index.mjs.map +0 -1
- package/resources/beta/vector-stores/vector-stores.d.ts.map +0 -1
- package/resources/beta/vector-stores/vector-stores.js.map +0 -1
- package/resources/beta/vector-stores/vector-stores.mjs.map +0 -1
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ParsedResponse,
|
|
3
|
+
type Response,
|
|
4
|
+
type ResponseCreateParamsBase,
|
|
5
|
+
type ResponseCreateParamsStreaming,
|
|
6
|
+
type ResponseStreamEvent,
|
|
7
|
+
} from '../../resources/responses/responses';
|
|
8
|
+
import * as Core from '../../core';
|
|
9
|
+
import { APIUserAbortError, OpenAIError } from '../../error';
|
|
10
|
+
import OpenAI from '../../index';
|
|
11
|
+
import { type BaseEvents, EventStream } from '../EventStream';
|
|
12
|
+
import { type ResponseFunctionCallArgumentsDeltaEvent, type ResponseTextDeltaEvent } from './EventTypes';
|
|
13
|
+
import { maybeParseResponse } from '../ResponsesParser';
|
|
14
|
+
|
|
15
|
+
export type ResponseStreamParams = Omit<ResponseCreateParamsBase, 'stream'> & {
|
|
16
|
+
stream?: true;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type ResponseEvents = BaseEvents &
|
|
20
|
+
Omit<
|
|
21
|
+
{
|
|
22
|
+
[K in ResponseStreamEvent['type']]: (event: Extract<ResponseStreamEvent, { type: K }>) => void;
|
|
23
|
+
},
|
|
24
|
+
'response.output_text.delta' | 'response.function_call_arguments.delta'
|
|
25
|
+
> & {
|
|
26
|
+
event: (event: ResponseStreamEvent) => void;
|
|
27
|
+
'response.output_text.delta': (event: ResponseTextDeltaEvent) => void;
|
|
28
|
+
'response.function_call_arguments.delta': (event: ResponseFunctionCallArgumentsDeltaEvent) => void;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ResponseStreamingParams = Omit<ResponseCreateParamsBase, 'stream'> & {
|
|
32
|
+
stream?: true;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export class ResponseStream<ParsedT = null>
|
|
36
|
+
extends EventStream<ResponseEvents>
|
|
37
|
+
implements AsyncIterable<ResponseStreamEvent>
|
|
38
|
+
{
|
|
39
|
+
#params: ResponseStreamingParams | null;
|
|
40
|
+
#currentResponseSnapshot: Response | undefined;
|
|
41
|
+
#finalResponse: ParsedResponse<ParsedT> | undefined;
|
|
42
|
+
|
|
43
|
+
constructor(params: ResponseStreamingParams | null) {
|
|
44
|
+
super();
|
|
45
|
+
this.#params = params;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static createResponse<ParsedT>(
|
|
49
|
+
client: OpenAI,
|
|
50
|
+
params: ResponseStreamParams,
|
|
51
|
+
options?: Core.RequestOptions,
|
|
52
|
+
): ResponseStream<ParsedT> {
|
|
53
|
+
const runner = new ResponseStream<ParsedT>(params as ResponseCreateParamsStreaming);
|
|
54
|
+
runner._run(() =>
|
|
55
|
+
runner._createResponse(client, params, {
|
|
56
|
+
...options,
|
|
57
|
+
headers: { ...options?.headers, 'X-Stainless-Helper-Method': 'stream' },
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
return runner;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#beginRequest() {
|
|
64
|
+
if (this.ended) return;
|
|
65
|
+
this.#currentResponseSnapshot = undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#addEvent(this: ResponseStream<ParsedT>, event: ResponseStreamEvent) {
|
|
69
|
+
if (this.ended) return;
|
|
70
|
+
|
|
71
|
+
const response = this.#accumulateResponse(event);
|
|
72
|
+
this._emit('event', event);
|
|
73
|
+
|
|
74
|
+
switch (event.type) {
|
|
75
|
+
case 'response.output_text.delta': {
|
|
76
|
+
const output = response.output[event.output_index];
|
|
77
|
+
if (!output) {
|
|
78
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
79
|
+
}
|
|
80
|
+
if (output.type === 'message') {
|
|
81
|
+
const content = output.content[event.content_index];
|
|
82
|
+
if (!content) {
|
|
83
|
+
throw new OpenAIError(`missing content at index ${event.content_index}`);
|
|
84
|
+
}
|
|
85
|
+
if (content.type !== 'output_text') {
|
|
86
|
+
throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this._emit('response.output_text.delta', {
|
|
90
|
+
...event,
|
|
91
|
+
snapshot: content.text,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'response.function_call_arguments.delta': {
|
|
97
|
+
const output = response.output[event.output_index];
|
|
98
|
+
if (!output) {
|
|
99
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
100
|
+
}
|
|
101
|
+
if (output.type === 'function_call') {
|
|
102
|
+
this._emit('response.function_call_arguments.delta', {
|
|
103
|
+
...event,
|
|
104
|
+
snapshot: output.arguments,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
default:
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
this._emit(event.type, event);
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#endRequest(): ParsedResponse<ParsedT> {
|
|
117
|
+
if (this.ended) {
|
|
118
|
+
throw new OpenAIError(`stream has ended, this shouldn't happen`);
|
|
119
|
+
}
|
|
120
|
+
const snapshot = this.#currentResponseSnapshot;
|
|
121
|
+
if (!snapshot) {
|
|
122
|
+
throw new OpenAIError(`request ended without sending any events`);
|
|
123
|
+
}
|
|
124
|
+
this.#currentResponseSnapshot = undefined;
|
|
125
|
+
const parsedResponse = finalizeResponse<ParsedT>(snapshot, this.#params);
|
|
126
|
+
this.#finalResponse = parsedResponse;
|
|
127
|
+
|
|
128
|
+
return parsedResponse;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
protected async _createResponse(
|
|
132
|
+
client: OpenAI,
|
|
133
|
+
params: ResponseStreamingParams,
|
|
134
|
+
options?: Core.RequestOptions,
|
|
135
|
+
): Promise<ParsedResponse<ParsedT>> {
|
|
136
|
+
const signal = options?.signal;
|
|
137
|
+
if (signal) {
|
|
138
|
+
if (signal.aborted) this.controller.abort();
|
|
139
|
+
signal.addEventListener('abort', () => this.controller.abort());
|
|
140
|
+
}
|
|
141
|
+
this.#beginRequest();
|
|
142
|
+
|
|
143
|
+
const stream = await client.responses.create(
|
|
144
|
+
{ ...params, stream: true },
|
|
145
|
+
{ ...options, signal: this.controller.signal },
|
|
146
|
+
);
|
|
147
|
+
this._connected();
|
|
148
|
+
for await (const event of stream) {
|
|
149
|
+
this.#addEvent(event);
|
|
150
|
+
}
|
|
151
|
+
if (stream.controller.signal?.aborted) {
|
|
152
|
+
throw new APIUserAbortError();
|
|
153
|
+
}
|
|
154
|
+
return this.#endRequest();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
#accumulateResponse(event: ResponseStreamEvent): Response {
|
|
158
|
+
let snapshot = this.#currentResponseSnapshot;
|
|
159
|
+
if (!snapshot) {
|
|
160
|
+
if (event.type !== 'response.created') {
|
|
161
|
+
throw new OpenAIError(
|
|
162
|
+
`When snapshot hasn't been set yet, expected 'response.created' event, got ${event.type}`,
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
snapshot = this.#currentResponseSnapshot = event.response;
|
|
166
|
+
return snapshot;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
switch (event.type) {
|
|
170
|
+
case 'response.output_item.added': {
|
|
171
|
+
snapshot.output.push(event.item);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case 'response.content_part.added': {
|
|
175
|
+
const output = snapshot.output[event.output_index];
|
|
176
|
+
if (!output) {
|
|
177
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
178
|
+
}
|
|
179
|
+
if (output.type === 'message') {
|
|
180
|
+
output.content.push(event.part);
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case 'response.output_text.delta': {
|
|
185
|
+
const output = snapshot.output[event.output_index];
|
|
186
|
+
if (!output) {
|
|
187
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
188
|
+
}
|
|
189
|
+
if (output.type === 'message') {
|
|
190
|
+
const content = output.content[event.content_index];
|
|
191
|
+
if (!content) {
|
|
192
|
+
throw new OpenAIError(`missing content at index ${event.content_index}`);
|
|
193
|
+
}
|
|
194
|
+
if (content.type !== 'output_text') {
|
|
195
|
+
throw new OpenAIError(`expected content to be 'output_text', got ${content.type}`);
|
|
196
|
+
}
|
|
197
|
+
content.text += event.delta;
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
case 'response.function_call_arguments.delta': {
|
|
202
|
+
const output = snapshot.output[event.output_index];
|
|
203
|
+
if (!output) {
|
|
204
|
+
throw new OpenAIError(`missing output at index ${event.output_index}`);
|
|
205
|
+
}
|
|
206
|
+
if (output.type === 'function_call') {
|
|
207
|
+
output.arguments += event.delta;
|
|
208
|
+
}
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
case 'response.completed': {
|
|
212
|
+
this.#currentResponseSnapshot = event.response;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return snapshot;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
[Symbol.asyncIterator](this: ResponseStream<ParsedT>): AsyncIterator<ResponseStreamEvent> {
|
|
221
|
+
const pushQueue: ResponseStreamEvent[] = [];
|
|
222
|
+
const readQueue: {
|
|
223
|
+
resolve: (event: ResponseStreamEvent | undefined) => void;
|
|
224
|
+
reject: (err: unknown) => void;
|
|
225
|
+
}[] = [];
|
|
226
|
+
let done = false;
|
|
227
|
+
|
|
228
|
+
this.on('event', (event) => {
|
|
229
|
+
const reader = readQueue.shift();
|
|
230
|
+
if (reader) {
|
|
231
|
+
reader.resolve(event);
|
|
232
|
+
} else {
|
|
233
|
+
pushQueue.push(event);
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
this.on('end', () => {
|
|
238
|
+
done = true;
|
|
239
|
+
for (const reader of readQueue) {
|
|
240
|
+
reader.resolve(undefined);
|
|
241
|
+
}
|
|
242
|
+
readQueue.length = 0;
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
this.on('abort', (err) => {
|
|
246
|
+
done = true;
|
|
247
|
+
for (const reader of readQueue) {
|
|
248
|
+
reader.reject(err);
|
|
249
|
+
}
|
|
250
|
+
readQueue.length = 0;
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
this.on('error', (err) => {
|
|
254
|
+
done = true;
|
|
255
|
+
for (const reader of readQueue) {
|
|
256
|
+
reader.reject(err);
|
|
257
|
+
}
|
|
258
|
+
readQueue.length = 0;
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
next: async (): Promise<IteratorResult<ResponseStreamEvent>> => {
|
|
263
|
+
if (!pushQueue.length) {
|
|
264
|
+
if (done) {
|
|
265
|
+
return { value: undefined, done: true };
|
|
266
|
+
}
|
|
267
|
+
return new Promise<ResponseStreamEvent | undefined>((resolve, reject) =>
|
|
268
|
+
readQueue.push({ resolve, reject }),
|
|
269
|
+
).then((event) => (event ? { value: event, done: false } : { value: undefined, done: true }));
|
|
270
|
+
}
|
|
271
|
+
const event = pushQueue.shift()!;
|
|
272
|
+
return { value: event, done: false };
|
|
273
|
+
},
|
|
274
|
+
return: async () => {
|
|
275
|
+
this.abort();
|
|
276
|
+
return { value: undefined, done: true };
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* @returns a promise that resolves with the final Response, or rejects
|
|
283
|
+
* if an error occurred or the stream ended prematurely without producing a REsponse.
|
|
284
|
+
*/
|
|
285
|
+
async finalResponse(): Promise<ParsedResponse<ParsedT>> {
|
|
286
|
+
await this.done();
|
|
287
|
+
const response = this.#finalResponse;
|
|
288
|
+
if (!response) throw new OpenAIError('stream ended without producing a ChatCompletion');
|
|
289
|
+
return response;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function finalizeResponse<ParsedT>(
|
|
294
|
+
snapshot: Response,
|
|
295
|
+
params: ResponseStreamingParams | null,
|
|
296
|
+
): ParsedResponse<ParsedT> {
|
|
297
|
+
return maybeParseResponse(snapshot, params);
|
|
298
|
+
}
|
|
@@ -4,10 +4,8 @@ import { APIResource } from '../../resource';
|
|
|
4
4
|
import { isRequestOptions } from '../../core';
|
|
5
5
|
import * as Core from '../../core';
|
|
6
6
|
import * as Shared from '../shared';
|
|
7
|
-
import * as ChatAPI from '../chat/chat';
|
|
8
7
|
import * as MessagesAPI from './threads/messages';
|
|
9
8
|
import * as ThreadsAPI from './threads/threads';
|
|
10
|
-
import * as VectorStoresAPI from './vector-stores/vector-stores';
|
|
11
9
|
import * as RunsAPI from './threads/runs/runs';
|
|
12
10
|
import * as StepsAPI from './threads/runs/steps';
|
|
13
11
|
import { CursorPage, type CursorPageParams } from '../../pagination';
|
|
@@ -1105,7 +1103,7 @@ export interface AssistantCreateParams {
|
|
|
1105
1103
|
* [Model overview](https://platform.openai.com/docs/models) for descriptions of
|
|
1106
1104
|
* them.
|
|
1107
1105
|
*/
|
|
1108
|
-
model: (string & {}) |
|
|
1106
|
+
model: (string & {}) | Shared.ChatModel;
|
|
1109
1107
|
|
|
1110
1108
|
/**
|
|
1111
1109
|
* The description of the assistant. The maximum length is 512 characters.
|
|
@@ -1134,14 +1132,14 @@ export interface AssistantCreateParams {
|
|
|
1134
1132
|
name?: string | null;
|
|
1135
1133
|
|
|
1136
1134
|
/**
|
|
1137
|
-
* **
|
|
1135
|
+
* **o-series models only**
|
|
1138
1136
|
*
|
|
1139
1137
|
* Constrains effort on reasoning for
|
|
1140
1138
|
* [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
|
|
1141
1139
|
* supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
|
|
1142
1140
|
* result in faster responses and fewer tokens used on reasoning in a response.
|
|
1143
1141
|
*/
|
|
1144
|
-
reasoning_effort?:
|
|
1142
|
+
reasoning_effort?: Shared.ReasoningEffort | null;
|
|
1145
1143
|
|
|
1146
1144
|
/**
|
|
1147
1145
|
* Specifies the format that the model must output. Compatible with
|
|
@@ -1244,9 +1242,9 @@ export namespace AssistantCreateParams {
|
|
|
1244
1242
|
export interface VectorStore {
|
|
1245
1243
|
/**
|
|
1246
1244
|
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
|
|
1247
|
-
* strategy.
|
|
1245
|
+
* strategy.
|
|
1248
1246
|
*/
|
|
1249
|
-
chunking_strategy?:
|
|
1247
|
+
chunking_strategy?: VectorStore.Auto | VectorStore.Static;
|
|
1250
1248
|
|
|
1251
1249
|
/**
|
|
1252
1250
|
* A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
|
|
@@ -1265,6 +1263,45 @@ export namespace AssistantCreateParams {
|
|
|
1265
1263
|
*/
|
|
1266
1264
|
metadata?: Shared.Metadata | null;
|
|
1267
1265
|
}
|
|
1266
|
+
|
|
1267
|
+
export namespace VectorStore {
|
|
1268
|
+
/**
|
|
1269
|
+
* The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
|
|
1270
|
+
* `800` and `chunk_overlap_tokens` of `400`.
|
|
1271
|
+
*/
|
|
1272
|
+
export interface Auto {
|
|
1273
|
+
/**
|
|
1274
|
+
* Always `auto`.
|
|
1275
|
+
*/
|
|
1276
|
+
type: 'auto';
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
export interface Static {
|
|
1280
|
+
static: Static.Static;
|
|
1281
|
+
|
|
1282
|
+
/**
|
|
1283
|
+
* Always `static`.
|
|
1284
|
+
*/
|
|
1285
|
+
type: 'static';
|
|
1286
|
+
}
|
|
1287
|
+
|
|
1288
|
+
export namespace Static {
|
|
1289
|
+
export interface Static {
|
|
1290
|
+
/**
|
|
1291
|
+
* The number of tokens that overlap between chunks. The default value is `400`.
|
|
1292
|
+
*
|
|
1293
|
+
* Note that the overlap must not exceed half of `max_chunk_size_tokens`.
|
|
1294
|
+
*/
|
|
1295
|
+
chunk_overlap_tokens: number;
|
|
1296
|
+
|
|
1297
|
+
/**
|
|
1298
|
+
* The maximum number of tokens in each chunk. The default value is `800`. The
|
|
1299
|
+
* minimum value is `100` and the maximum value is `4096`.
|
|
1300
|
+
*/
|
|
1301
|
+
max_chunk_size_tokens: number;
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1268
1305
|
}
|
|
1269
1306
|
}
|
|
1270
1307
|
}
|
|
@@ -1337,14 +1374,14 @@ export interface AssistantUpdateParams {
|
|
|
1337
1374
|
name?: string | null;
|
|
1338
1375
|
|
|
1339
1376
|
/**
|
|
1340
|
-
* **
|
|
1377
|
+
* **o-series models only**
|
|
1341
1378
|
*
|
|
1342
1379
|
* Constrains effort on reasoning for
|
|
1343
1380
|
* [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
|
|
1344
1381
|
* supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
|
|
1345
1382
|
* result in faster responses and fewer tokens used on reasoning in a response.
|
|
1346
1383
|
*/
|
|
1347
|
-
reasoning_effort?:
|
|
1384
|
+
reasoning_effort?: Shared.ReasoningEffort | null;
|
|
1348
1385
|
|
|
1349
1386
|
/**
|
|
1350
1387
|
* Specifies the format that the model must output. Compatible with
|
|
@@ -40,36 +40,16 @@ import {
|
|
|
40
40
|
ThreadUpdateParams,
|
|
41
41
|
Threads,
|
|
42
42
|
} from './threads/threads';
|
|
43
|
-
import * as VectorStoresAPI from './vector-stores/vector-stores';
|
|
44
|
-
import {
|
|
45
|
-
AutoFileChunkingStrategyParam,
|
|
46
|
-
FileChunkingStrategy,
|
|
47
|
-
FileChunkingStrategyParam,
|
|
48
|
-
OtherFileChunkingStrategyObject,
|
|
49
|
-
StaticFileChunkingStrategy,
|
|
50
|
-
StaticFileChunkingStrategyObject,
|
|
51
|
-
StaticFileChunkingStrategyObjectParam,
|
|
52
|
-
VectorStore,
|
|
53
|
-
VectorStoreCreateParams,
|
|
54
|
-
VectorStoreDeleted,
|
|
55
|
-
VectorStoreListParams,
|
|
56
|
-
VectorStoreUpdateParams,
|
|
57
|
-
VectorStores,
|
|
58
|
-
VectorStoresPage,
|
|
59
|
-
} from './vector-stores/vector-stores';
|
|
60
43
|
import { Chat } from './chat/chat';
|
|
61
44
|
|
|
62
45
|
export class Beta extends APIResource {
|
|
63
46
|
realtime: RealtimeAPI.Realtime = new RealtimeAPI.Realtime(this._client);
|
|
64
|
-
vectorStores: VectorStoresAPI.VectorStores = new VectorStoresAPI.VectorStores(this._client);
|
|
65
47
|
chat: ChatAPI.Chat = new ChatAPI.Chat(this._client);
|
|
66
48
|
assistants: AssistantsAPI.Assistants = new AssistantsAPI.Assistants(this._client);
|
|
67
49
|
threads: ThreadsAPI.Threads = new ThreadsAPI.Threads(this._client);
|
|
68
50
|
}
|
|
69
51
|
|
|
70
52
|
Beta.Realtime = Realtime;
|
|
71
|
-
Beta.VectorStores = VectorStores;
|
|
72
|
-
Beta.VectorStoresPage = VectorStoresPage;
|
|
73
53
|
Beta.Assistants = Assistants;
|
|
74
54
|
Beta.AssistantsPage = AssistantsPage;
|
|
75
55
|
Beta.Threads = Threads;
|
|
@@ -77,23 +57,6 @@ Beta.Threads = Threads;
|
|
|
77
57
|
export declare namespace Beta {
|
|
78
58
|
export { Realtime as Realtime };
|
|
79
59
|
|
|
80
|
-
export {
|
|
81
|
-
VectorStores as VectorStores,
|
|
82
|
-
type AutoFileChunkingStrategyParam as AutoFileChunkingStrategyParam,
|
|
83
|
-
type FileChunkingStrategy as FileChunkingStrategy,
|
|
84
|
-
type FileChunkingStrategyParam as FileChunkingStrategyParam,
|
|
85
|
-
type OtherFileChunkingStrategyObject as OtherFileChunkingStrategyObject,
|
|
86
|
-
type StaticFileChunkingStrategy as StaticFileChunkingStrategy,
|
|
87
|
-
type StaticFileChunkingStrategyObject as StaticFileChunkingStrategyObject,
|
|
88
|
-
type StaticFileChunkingStrategyObjectParam as StaticFileChunkingStrategyObjectParam,
|
|
89
|
-
type VectorStore as VectorStore,
|
|
90
|
-
type VectorStoreDeleted as VectorStoreDeleted,
|
|
91
|
-
VectorStoresPage as VectorStoresPage,
|
|
92
|
-
type VectorStoreCreateParams as VectorStoreCreateParams,
|
|
93
|
-
type VectorStoreUpdateParams as VectorStoreUpdateParams,
|
|
94
|
-
type VectorStoreListParams as VectorStoreListParams,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
60
|
export { Chat };
|
|
98
61
|
|
|
99
62
|
export {
|
|
@@ -37,19 +37,3 @@ export {
|
|
|
37
37
|
type ThreadCreateAndRunPollParams,
|
|
38
38
|
type ThreadCreateAndRunStreamParams,
|
|
39
39
|
} from './threads/index';
|
|
40
|
-
export {
|
|
41
|
-
VectorStoresPage,
|
|
42
|
-
VectorStores,
|
|
43
|
-
type AutoFileChunkingStrategyParam,
|
|
44
|
-
type FileChunkingStrategy,
|
|
45
|
-
type FileChunkingStrategyParam,
|
|
46
|
-
type OtherFileChunkingStrategyObject,
|
|
47
|
-
type StaticFileChunkingStrategy,
|
|
48
|
-
type StaticFileChunkingStrategyObject,
|
|
49
|
-
type StaticFileChunkingStrategyObjectParam,
|
|
50
|
-
type VectorStore,
|
|
51
|
-
type VectorStoreDeleted,
|
|
52
|
-
type VectorStoreCreateParams,
|
|
53
|
-
type VectorStoreUpdateParams,
|
|
54
|
-
type VectorStoreListParams,
|
|
55
|
-
} from './vector-stores/index';
|
|
@@ -10,7 +10,6 @@ import { RunSubmitToolOutputsParamsStream } from '../../../../lib/AssistantStrea
|
|
|
10
10
|
import * as RunsAPI from './runs';
|
|
11
11
|
import * as Shared from '../../../shared';
|
|
12
12
|
import * as AssistantsAPI from '../../assistants';
|
|
13
|
-
import * as ChatAPI from '../../../chat/chat';
|
|
14
13
|
import * as MessagesAPI from '../messages';
|
|
15
14
|
import * as ThreadsAPI from '../threads';
|
|
16
15
|
import * as StepsAPI from './steps';
|
|
@@ -722,7 +721,7 @@ export interface RunCreateParamsBase {
|
|
|
722
721
|
* associated with the assistant. If not, the model associated with the assistant
|
|
723
722
|
* will be used.
|
|
724
723
|
*/
|
|
725
|
-
model?: (string & {}) |
|
|
724
|
+
model?: (string & {}) | Shared.ChatModel | null;
|
|
726
725
|
|
|
727
726
|
/**
|
|
728
727
|
* Body param: Whether to enable
|
|
@@ -732,14 +731,14 @@ export interface RunCreateParamsBase {
|
|
|
732
731
|
parallel_tool_calls?: boolean;
|
|
733
732
|
|
|
734
733
|
/**
|
|
735
|
-
* Body param: **
|
|
734
|
+
* Body param: **o-series models only**
|
|
736
735
|
*
|
|
737
736
|
* Constrains effort on reasoning for
|
|
738
737
|
* [reasoning models](https://platform.openai.com/docs/guides/reasoning). Currently
|
|
739
738
|
* supported values are `low`, `medium`, and `high`. Reducing reasoning effort can
|
|
740
739
|
* result in faster responses and fewer tokens used on reasoning in a response.
|
|
741
740
|
*/
|
|
742
|
-
reasoning_effort?:
|
|
741
|
+
reasoning_effort?: Shared.ReasoningEffort | null;
|
|
743
742
|
|
|
744
743
|
/**
|
|
745
744
|
* Body param: Specifies the format that the model must output. Compatible with
|
|
@@ -8,7 +8,6 @@ import * as Core from '../../../core';
|
|
|
8
8
|
import * as ThreadsAPI from './threads';
|
|
9
9
|
import * as Shared from '../../shared';
|
|
10
10
|
import * as AssistantsAPI from '../assistants';
|
|
11
|
-
import * as ChatAPI from '../../chat/chat';
|
|
12
11
|
import * as MessagesAPI from './messages';
|
|
13
12
|
import {
|
|
14
13
|
Annotation,
|
|
@@ -45,7 +44,6 @@ import {
|
|
|
45
44
|
TextDelta,
|
|
46
45
|
TextDeltaBlock,
|
|
47
46
|
} from './messages';
|
|
48
|
-
import * as VectorStoresAPI from '../vector-stores/vector-stores';
|
|
49
47
|
import * as RunsAPI from './runs/runs';
|
|
50
48
|
import {
|
|
51
49
|
RequiredActionFunctionToolCall,
|
|
@@ -441,9 +439,9 @@ export namespace ThreadCreateParams {
|
|
|
441
439
|
export interface VectorStore {
|
|
442
440
|
/**
|
|
443
441
|
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
|
|
444
|
-
* strategy.
|
|
442
|
+
* strategy.
|
|
445
443
|
*/
|
|
446
|
-
chunking_strategy?:
|
|
444
|
+
chunking_strategy?: VectorStore.Auto | VectorStore.Static;
|
|
447
445
|
|
|
448
446
|
/**
|
|
449
447
|
* A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
|
|
@@ -462,6 +460,45 @@ export namespace ThreadCreateParams {
|
|
|
462
460
|
*/
|
|
463
461
|
metadata?: Shared.Metadata | null;
|
|
464
462
|
}
|
|
463
|
+
|
|
464
|
+
export namespace VectorStore {
|
|
465
|
+
/**
|
|
466
|
+
* The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
|
|
467
|
+
* `800` and `chunk_overlap_tokens` of `400`.
|
|
468
|
+
*/
|
|
469
|
+
export interface Auto {
|
|
470
|
+
/**
|
|
471
|
+
* Always `auto`.
|
|
472
|
+
*/
|
|
473
|
+
type: 'auto';
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
export interface Static {
|
|
477
|
+
static: Static.Static;
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Always `static`.
|
|
481
|
+
*/
|
|
482
|
+
type: 'static';
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
export namespace Static {
|
|
486
|
+
export interface Static {
|
|
487
|
+
/**
|
|
488
|
+
* The number of tokens that overlap between chunks. The default value is `400`.
|
|
489
|
+
*
|
|
490
|
+
* Note that the overlap must not exceed half of `max_chunk_size_tokens`.
|
|
491
|
+
*/
|
|
492
|
+
chunk_overlap_tokens: number;
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* The maximum number of tokens in each chunk. The default value is `800`. The
|
|
496
|
+
* minimum value is `100` and the maximum value is `4096`.
|
|
497
|
+
*/
|
|
498
|
+
max_chunk_size_tokens: number;
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
465
502
|
}
|
|
466
503
|
}
|
|
467
504
|
}
|
|
@@ -573,7 +610,7 @@ export interface ThreadCreateAndRunParamsBase {
|
|
|
573
610
|
* model associated with the assistant. If not, the model associated with the
|
|
574
611
|
* assistant will be used.
|
|
575
612
|
*/
|
|
576
|
-
model?: (string & {}) |
|
|
613
|
+
model?: (string & {}) | Shared.ChatModel | null;
|
|
577
614
|
|
|
578
615
|
/**
|
|
579
616
|
* Whether to enable
|
|
@@ -800,9 +837,9 @@ export namespace ThreadCreateAndRunParams {
|
|
|
800
837
|
export interface VectorStore {
|
|
801
838
|
/**
|
|
802
839
|
* The chunking strategy used to chunk the file(s). If not set, will use the `auto`
|
|
803
|
-
* strategy.
|
|
840
|
+
* strategy.
|
|
804
841
|
*/
|
|
805
|
-
chunking_strategy?:
|
|
842
|
+
chunking_strategy?: VectorStore.Auto | VectorStore.Static;
|
|
806
843
|
|
|
807
844
|
/**
|
|
808
845
|
* A list of [file](https://platform.openai.com/docs/api-reference/files) IDs to
|
|
@@ -821,6 +858,45 @@ export namespace ThreadCreateAndRunParams {
|
|
|
821
858
|
*/
|
|
822
859
|
metadata?: Shared.Metadata | null;
|
|
823
860
|
}
|
|
861
|
+
|
|
862
|
+
export namespace VectorStore {
|
|
863
|
+
/**
|
|
864
|
+
* The default strategy. This strategy currently uses a `max_chunk_size_tokens` of
|
|
865
|
+
* `800` and `chunk_overlap_tokens` of `400`.
|
|
866
|
+
*/
|
|
867
|
+
export interface Auto {
|
|
868
|
+
/**
|
|
869
|
+
* Always `auto`.
|
|
870
|
+
*/
|
|
871
|
+
type: 'auto';
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
export interface Static {
|
|
875
|
+
static: Static.Static;
|
|
876
|
+
|
|
877
|
+
/**
|
|
878
|
+
* Always `static`.
|
|
879
|
+
*/
|
|
880
|
+
type: 'static';
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
export namespace Static {
|
|
884
|
+
export interface Static {
|
|
885
|
+
/**
|
|
886
|
+
* The number of tokens that overlap between chunks. The default value is `400`.
|
|
887
|
+
*
|
|
888
|
+
* Note that the overlap must not exceed half of `max_chunk_size_tokens`.
|
|
889
|
+
*/
|
|
890
|
+
chunk_overlap_tokens: number;
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* The maximum number of tokens in each chunk. The default value is `800`. The
|
|
894
|
+
* minimum value is `100` and the maximum value is `4096`.
|
|
895
|
+
*/
|
|
896
|
+
max_chunk_size_tokens: number;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
}
|
|
824
900
|
}
|
|
825
901
|
}
|
|
826
902
|
}
|