@glexir/sdk 0.0.0-stage → 0.2.0
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/LICENSE +21 -0
- package/README.md +292 -2
- package/dist/client.d.ts +61 -0
- package/dist/client.js +245 -0
- package/dist/client.js.map +1 -0
- package/dist/core/api-promise.d.ts +31 -0
- package/dist/core/api-promise.js +39 -0
- package/dist/core/api-promise.js.map +1 -0
- package/dist/core/errors.d.ts +70 -0
- package/dist/core/errors.js +118 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/multipart.d.ts +16 -0
- package/dist/core/multipart.js +68 -0
- package/dist/core/multipart.js.map +1 -0
- package/dist/core/pagination.d.ts +41 -0
- package/dist/core/pagination.js +63 -0
- package/dist/core/pagination.js.map +1 -0
- package/dist/core/request-options.d.ts +29 -0
- package/dist/core/request-options.js +2 -0
- package/dist/core/request-options.js.map +1 -0
- package/dist/core/resource.d.ts +5 -0
- package/dist/core/resource.js +7 -0
- package/dist/core/resource.js.map +1 -0
- package/dist/core/retry.d.ts +13 -0
- package/dist/core/retry.js +65 -0
- package/dist/core/retry.js.map +1 -0
- package/dist/core/streaming.d.ts +44 -0
- package/dist/core/streaming.js +238 -0
- package/dist/core/streaming.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/chat-completion-stream.d.ts +26 -0
- package/dist/lib/chat-completion-stream.js +161 -0
- package/dist/lib/chat-completion-stream.js.map +1 -0
- package/dist/lib/output-text.d.ts +4 -0
- package/dist/lib/output-text.js +22 -0
- package/dist/lib/output-text.js.map +1 -0
- package/dist/lib/response-stream.d.ts +30 -0
- package/dist/lib/response-stream.js +122 -0
- package/dist/lib/response-stream.js.map +1 -0
- package/dist/lib/strict-schema.d.ts +11 -0
- package/dist/lib/strict-schema.js +116 -0
- package/dist/lib/strict-schema.js.map +1 -0
- package/dist/resources/audio.d.ts +46 -0
- package/dist/resources/audio.js +24 -0
- package/dist/resources/audio.js.map +1 -0
- package/dist/resources/batches.d.ts +20 -0
- package/dist/resources/batches.js +24 -0
- package/dist/resources/batches.js.map +1 -0
- package/dist/resources/chat.d.ts +63 -0
- package/dist/resources/chat.js +79 -0
- package/dist/resources/chat.js.map +1 -0
- package/dist/resources/conversations.d.ts +23 -0
- package/dist/resources/conversations.js +38 -0
- package/dist/resources/conversations.js.map +1 -0
- package/dist/resources/embeddings.d.ts +12 -0
- package/dist/resources/embeddings.js +34 -0
- package/dist/resources/embeddings.js.map +1 -0
- package/dist/resources/files.d.ts +15 -0
- package/dist/resources/files.js +27 -0
- package/dist/resources/files.js.map +1 -0
- package/dist/resources/models.d.ts +10 -0
- package/dist/resources/models.js +11 -0
- package/dist/resources/models.js.map +1 -0
- package/dist/resources/responses.d.ts +61 -0
- package/dist/resources/responses.js +85 -0
- package/dist/resources/responses.js.map +1 -0
- package/dist/types/audio.d.ts +172 -0
- package/dist/types/audio.js +2 -0
- package/dist/types/audio.js.map +1 -0
- package/dist/types/chat.d.ts +316 -0
- package/dist/types/chat.js +2 -0
- package/dist/types/chat.js.map +1 -0
- package/dist/types/conversations.d.ts +46 -0
- package/dist/types/conversations.js +2 -0
- package/dist/types/conversations.js.map +1 -0
- package/dist/types/platform.d.ts +151 -0
- package/dist/types/platform.js +2 -0
- package/dist/types/platform.js.map +1 -0
- package/dist/types/responses.d.ts +640 -0
- package/dist/types/responses.js +2 -0
- package/dist/types/responses.js.map +1 -0
- package/dist/types/shared.d.ts +108 -0
- package/dist/types/shared.js +2 -0
- package/dist/types/shared.js.map +1 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/package.json +37 -3
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { APIResource } from '../core/resource.js';
|
|
2
|
+
/** Decodes a base64 little-endian float32 vector. */
|
|
3
|
+
export function decodeBase64Embedding(base64) {
|
|
4
|
+
const binary = atob(base64);
|
|
5
|
+
const bytes = new Uint8Array(binary.length);
|
|
6
|
+
for (let i = 0; i < binary.length; i++)
|
|
7
|
+
bytes[i] = binary.charCodeAt(i);
|
|
8
|
+
const view = new DataView(bytes.buffer);
|
|
9
|
+
const out = new Array(bytes.length / 4);
|
|
10
|
+
for (let i = 0; i < out.length; i++)
|
|
11
|
+
out[i] = view.getFloat32(i * 4, true);
|
|
12
|
+
return out;
|
|
13
|
+
}
|
|
14
|
+
export class Embeddings extends APIResource {
|
|
15
|
+
/**
|
|
16
|
+
* Creates embedding vectors. When `encoding_format` is omitted the SDK requests compact
|
|
17
|
+
* base64 on the wire and decodes it to `number[]`, as OpenAI's SDK does.
|
|
18
|
+
*/
|
|
19
|
+
create(body, options) {
|
|
20
|
+
if (body.encoding_format !== undefined) {
|
|
21
|
+
return this.client.post('/embeddings', { ...options, body });
|
|
22
|
+
}
|
|
23
|
+
return this.client
|
|
24
|
+
.post('/embeddings', { ...options, body: { ...body, encoding_format: 'base64' } })
|
|
25
|
+
._thenUnwrap((response) => {
|
|
26
|
+
for (const item of response.data) {
|
|
27
|
+
if (typeof item.embedding === 'string')
|
|
28
|
+
item.embedding = decodeBase64Embedding(item.embedding);
|
|
29
|
+
}
|
|
30
|
+
return response;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=embeddings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeddings.js","sourceRoot":"","sources":["../../src/resources/embeddings.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,qDAAqD;AACrD,MAAM,UAAU,qBAAqB,CAAC,MAAc;IAClD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GA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ACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { APIPromise } from '../core/api-promise.js';
|
|
2
|
+
import type { PagePromise } from '../core/pagination.js';
|
|
3
|
+
import type { RequestOptions } from '../core/request-options.js';
|
|
4
|
+
import { APIResource } from '../core/resource.js';
|
|
5
|
+
import type { FileCreateParams, FileDeleted, FileListParams, FileObject } from '../types/platform.js';
|
|
6
|
+
/** Upload files for model input (`user_data`) or batch jobs (`batch`). */
|
|
7
|
+
export declare class Files extends APIResource {
|
|
8
|
+
create(body: FileCreateParams, options?: RequestOptions): APIPromise<FileObject>;
|
|
9
|
+
retrieve(fileId: string, options?: RequestOptions): APIPromise<FileObject>;
|
|
10
|
+
/** Lists your files. Iterate with `for await` to page through all of them. */
|
|
11
|
+
list(query?: FileListParams, options?: RequestOptions): PagePromise<FileObject>;
|
|
12
|
+
delete(fileId: string, options?: RequestOptions): APIPromise<FileDeleted>;
|
|
13
|
+
/** Downloads a file's contents (e.g. batch output). Returns the raw `Response`; use `.text()`, `.arrayBuffer()` or `.body`. */
|
|
14
|
+
content(fileId: string, options?: RequestOptions): APIPromise<Response>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { APIResource } from '../core/resource.js';
|
|
2
|
+
const encode = encodeURIComponent;
|
|
3
|
+
/** Upload files for model input (`user_data`) or batch jobs (`batch`). */
|
|
4
|
+
export class Files extends APIResource {
|
|
5
|
+
create(body, options) {
|
|
6
|
+
return this.client.post('/files', { ...options, body, multipart: true });
|
|
7
|
+
}
|
|
8
|
+
retrieve(fileId, options) {
|
|
9
|
+
return this.client.get(`/files/${encode(fileId)}`, options);
|
|
10
|
+
}
|
|
11
|
+
/** Lists your files. Iterate with `for await` to page through all of them. */
|
|
12
|
+
list(query = {}, options) {
|
|
13
|
+
return this.client.requestAPIList({ ...options, method: 'get', path: '/files', query: { ...query } }, 'last-item-id');
|
|
14
|
+
}
|
|
15
|
+
delete(fileId, options) {
|
|
16
|
+
return this.client.delete(`/files/${encode(fileId)}`, options);
|
|
17
|
+
}
|
|
18
|
+
/** Downloads a file's contents (e.g. batch output). Returns the raw `Response`; use `.text()`, `.arrayBuffer()` or `.body`. */
|
|
19
|
+
content(fileId, options) {
|
|
20
|
+
return this.client.get(`/files/${encode(fileId)}/content`, {
|
|
21
|
+
...options,
|
|
22
|
+
binary: true,
|
|
23
|
+
headers: { accept: 'application/binary', ...options?.headers },
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files.js","sourceRoot":"","sources":["../../src/resources/files.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,MAAM,MAAM,GAAG,kBAAkB,CAAC;AAElC,0EAA0E;AAC1E,MAAM,OAAO,KAAM,SAAQ,WAAW;IACpC,MAAM,CAAC,IAAsB,EAAE,OAAwB;QACrD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,QAAQ,CAAC,MAAc,EAAE,OAAwB;QAC/C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC9D,CAAC;IAED,8EAA8E;IAC9E,IAAI,CAAC,QAAwB,EAAE,EAAE,OAAwB;QACvD,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAa,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,EAAE,cAAc,CAAC,CAAC;IACpI,CAAC;IAED,MAAM,CAAC,MAAc,EAAE,OAAwB;QAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IACjE,CAAC;IAED,+HAA+H;IAC/H,OAAO,CAAC,MAAc,EAAE,OAAwB;QAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;YACzD,GAAG,OAAO;YACV,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,EAAE,MAAM,EAAE,oBAAoB,EAAE,GAAG,OAAO,EAAE,OAAO,EAAE;SAC/D,CAAC,CAAC;IACL,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { APIPromise } from '../core/api-promise.js';
|
|
2
|
+
import type { PagePromise } from '../core/pagination.js';
|
|
3
|
+
import type { RequestOptions } from '../core/request-options.js';
|
|
4
|
+
import { APIResource } from '../core/resource.js';
|
|
5
|
+
import type { Model } from '../types/platform.js';
|
|
6
|
+
export declare class Models extends APIResource {
|
|
7
|
+
/** Models available to your Glexir key. */
|
|
8
|
+
list(options?: RequestOptions): PagePromise<Model>;
|
|
9
|
+
retrieve(model: string, options?: RequestOptions): APIPromise<Model>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { APIResource } from '../core/resource.js';
|
|
2
|
+
export class Models extends APIResource {
|
|
3
|
+
/** Models available to your Glexir key. */
|
|
4
|
+
list(options) {
|
|
5
|
+
return this.client.requestAPIList({ ...options, method: 'get', path: '/models' }, 'none');
|
|
6
|
+
}
|
|
7
|
+
retrieve(model, options) {
|
|
8
|
+
return this.client.get(`/models/${encodeURIComponent(model)}`, options);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=models.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/resources/models.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGlD,MAAM,OAAO,MAAO,SAAQ,WAAW;IACrC,2CAA2C;IAC3C,IAAI,CAAC,OAAwB;QAC3B,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAQ,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,MAAM,CAAC,CAAC;IACnG,CAAC;IAED,QAAQ,CAAC,KAAa,EAAE,OAAwB;QAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,kBAAkB,CAAC,KAAK,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAC1E,CAAC;CACF"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { APIPromise } from '../core/api-promise.js';
|
|
2
|
+
import type { PagePromise } from '../core/pagination.js';
|
|
3
|
+
import type { RequestOptions } from '../core/request-options.js';
|
|
4
|
+
import { APIResource } from '../core/resource.js';
|
|
5
|
+
import type { Stream } from '../core/streaming.js';
|
|
6
|
+
import { ResponseStream } from '../lib/response-stream.js';
|
|
7
|
+
import type { CompactedResponse, InputItemListParams, InputTokenCountParams, InputTokenCountResponse, Response, ResponseCompactParams, ResponseCreateParams, ResponseCreateParamsBase, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, ResponseItem, ResponseRetrieveParams, ResponseStreamEvent } from '../types/responses.js';
|
|
8
|
+
export interface ParseOptions<T> extends RequestOptions {
|
|
9
|
+
/** Validate/transform the parsed JSON (e.g. `schema.parse` from zod). */
|
|
10
|
+
validate?: (value: unknown) => T;
|
|
11
|
+
}
|
|
12
|
+
export interface ParsedResponse<T> extends Response {
|
|
13
|
+
/** The parsed structured output, or `null` when the model refused. */
|
|
14
|
+
output_parsed: T | null;
|
|
15
|
+
}
|
|
16
|
+
/** Resume a background response that was created with `stream: true`. */
|
|
17
|
+
export interface ResponseStreamResumeParams {
|
|
18
|
+
response_id: string;
|
|
19
|
+
starting_after?: number;
|
|
20
|
+
}
|
|
21
|
+
export type ResponseStreamParams = (ResponseCreateParamsBase & {
|
|
22
|
+
stream?: true;
|
|
23
|
+
}) | ResponseStreamResumeParams;
|
|
24
|
+
export declare class InputItems extends APIResource {
|
|
25
|
+
/** Lists the input items of a stored response. Iterate with `for await` to page through all of them. */
|
|
26
|
+
list(responseId: string, query?: InputItemListParams, options?: RequestOptions): PagePromise<ResponseItem>;
|
|
27
|
+
}
|
|
28
|
+
export declare class InputTokens extends APIResource {
|
|
29
|
+
/** Counts input tokens for a would-be request without generating output. */
|
|
30
|
+
count(body?: InputTokenCountParams, options?: RequestOptions): APIPromise<InputTokenCountResponse>;
|
|
31
|
+
}
|
|
32
|
+
/** The Responses API: OpenAI's recommended interface for text generation, reasoning and tool calling. */
|
|
33
|
+
export declare class Responses extends APIResource {
|
|
34
|
+
readonly inputItems: InputItems;
|
|
35
|
+
readonly inputTokens: InputTokens;
|
|
36
|
+
create(body: ResponseCreateParamsNonStreaming, options?: RequestOptions): APIPromise<Response>;
|
|
37
|
+
create(body: ResponseCreateParamsStreaming, options?: RequestOptions): APIPromise<Stream<ResponseStreamEvent>>;
|
|
38
|
+
create(body: ResponseCreateParams, options?: RequestOptions): APIPromise<Response | Stream<ResponseStreamEvent>>;
|
|
39
|
+
retrieve(responseId: string, query?: ResponseRetrieveParams & {
|
|
40
|
+
stream?: false;
|
|
41
|
+
}, options?: RequestOptions): APIPromise<Response>;
|
|
42
|
+
retrieve(responseId: string, query: ResponseRetrieveParams & {
|
|
43
|
+
stream: true;
|
|
44
|
+
}, options?: RequestOptions): APIPromise<Stream<ResponseStreamEvent>>;
|
|
45
|
+
delete(responseId: string, options?: RequestOptions): APIPromise<void>;
|
|
46
|
+
/** Cancels a background response. Calling it again returns the final response. */
|
|
47
|
+
cancel(responseId: string, options?: RequestOptions): APIPromise<Response>;
|
|
48
|
+
/** Compacts a conversation into an opaque `compaction` item you can pass as input later. */
|
|
49
|
+
compact(body: ResponseCompactParams, options?: RequestOptions): APIPromise<CompactedResponse>;
|
|
50
|
+
/**
|
|
51
|
+
* Streams a response with an accumulating helper. Pass create params, or
|
|
52
|
+
* `{ response_id, starting_after }` to resume a background response created with `stream: true`.
|
|
53
|
+
*/
|
|
54
|
+
stream(params: ResponseStreamParams, options?: RequestOptions): ResponseStream;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a response and parses the structured output when `text.format` is `json_schema`
|
|
57
|
+
* (or `json_object`). Throws if the output was truncated or filtered.
|
|
58
|
+
*/
|
|
59
|
+
parse<T = unknown>(body: ResponseCreateParamsNonStreaming, options?: ParseOptions<T>): Promise<ParsedResponse<T>>;
|
|
60
|
+
}
|
|
61
|
+
export declare function parseResponseOutput<T>(response: Response, body: Pick<ResponseCreateParamsNonStreaming, 'text'>, validate?: (value: unknown) => T): ParsedResponse<T>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { ContentFilterFinishReasonError, LengthFinishReasonError } from '../core/errors.js';
|
|
2
|
+
import { APIResource } from '../core/resource.js';
|
|
3
|
+
import { addOutputText } from '../lib/output-text.js';
|
|
4
|
+
import { ResponseStream } from '../lib/response-stream.js';
|
|
5
|
+
const encode = encodeURIComponent;
|
|
6
|
+
export class InputItems extends APIResource {
|
|
7
|
+
/** Lists the input items of a stored response. Iterate with `for await` to page through all of them. */
|
|
8
|
+
list(responseId, query = {}, options) {
|
|
9
|
+
return this.client.requestAPIList({ ...options, method: 'get', path: `/responses/${encode(responseId)}/input_items`, query: { ...query } }, 'last-item-id');
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export class InputTokens extends APIResource {
|
|
13
|
+
/** Counts input tokens for a would-be request without generating output. */
|
|
14
|
+
count(body = {}, options) {
|
|
15
|
+
return this.client.post('/responses/input_tokens', { ...options, body });
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** The Responses API: OpenAI's recommended interface for text generation, reasoning and tool calling. */
|
|
19
|
+
export class Responses extends APIResource {
|
|
20
|
+
inputItems = new InputItems(this.client);
|
|
21
|
+
inputTokens = new InputTokens(this.client);
|
|
22
|
+
create(body, options) {
|
|
23
|
+
if (body.stream) {
|
|
24
|
+
return this.client.post('/responses', { ...options, body, stream: true });
|
|
25
|
+
}
|
|
26
|
+
return this.client.post('/responses', { ...options, body })._thenUnwrap((r) => addOutputText(r));
|
|
27
|
+
}
|
|
28
|
+
retrieve(responseId, query = {}, options) {
|
|
29
|
+
const path = `/responses/${encode(responseId)}`;
|
|
30
|
+
if (query.stream) {
|
|
31
|
+
return this.client.get(path, { ...options, query: { ...query }, stream: true });
|
|
32
|
+
}
|
|
33
|
+
return this.client.get(path, { ...options, query: { ...query } })._thenUnwrap((r) => addOutputText(r));
|
|
34
|
+
}
|
|
35
|
+
delete(responseId, options) {
|
|
36
|
+
return this.client.delete(`/responses/${encode(responseId)}`, { ...options, headers: { accept: '*/*', ...options?.headers } });
|
|
37
|
+
}
|
|
38
|
+
/** Cancels a background response. Calling it again returns the final response. */
|
|
39
|
+
cancel(responseId, options) {
|
|
40
|
+
return this.client.post(`/responses/${encode(responseId)}/cancel`, options)._thenUnwrap((r) => addOutputText(r));
|
|
41
|
+
}
|
|
42
|
+
/** Compacts a conversation into an opaque `compaction` item you can pass as input later. */
|
|
43
|
+
compact(body, options) {
|
|
44
|
+
return this.client.post('/responses/compact', { ...options, body });
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Streams a response with an accumulating helper. Pass create params, or
|
|
48
|
+
* `{ response_id, starting_after }` to resume a background response created with `stream: true`.
|
|
49
|
+
*/
|
|
50
|
+
stream(params, options) {
|
|
51
|
+
if (!('model' in params) && typeof params.response_id === 'string') {
|
|
52
|
+
const resume = params;
|
|
53
|
+
const query = { stream: true };
|
|
54
|
+
if (resume.starting_after !== undefined)
|
|
55
|
+
query.starting_after = resume.starting_after;
|
|
56
|
+
return new ResponseStream(this.retrieve(resume.response_id, query, options));
|
|
57
|
+
}
|
|
58
|
+
return new ResponseStream(this.create({ ...params, stream: true }, options));
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a response and parses the structured output when `text.format` is `json_schema`
|
|
62
|
+
* (or `json_object`). Throws if the output was truncated or filtered.
|
|
63
|
+
*/
|
|
64
|
+
async parse(body, options = {}) {
|
|
65
|
+
const { validate, ...requestOptions } = options;
|
|
66
|
+
const response = await this.create(body, requestOptions);
|
|
67
|
+
return parseResponseOutput(response, body, validate);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export function parseResponseOutput(response, body, validate) {
|
|
71
|
+
const reason = response.incomplete_details?.reason;
|
|
72
|
+
if (reason === 'max_output_tokens')
|
|
73
|
+
throw new LengthFinishReasonError();
|
|
74
|
+
if (reason === 'content_filter')
|
|
75
|
+
throw new ContentFilterFinishReasonError();
|
|
76
|
+
const format = body.text?.format?.type;
|
|
77
|
+
const refused = response.output.some((item) => item.type === 'message' && item.content.some((p) => p.type === 'refusal'));
|
|
78
|
+
let parsed = null;
|
|
79
|
+
if (!refused && (format === 'json_schema' || format === 'json_object')) {
|
|
80
|
+
const value = JSON.parse(response.output_text);
|
|
81
|
+
parsed = validate ? validate(value) : value;
|
|
82
|
+
}
|
|
83
|
+
return Object.assign(response, { output_parsed: parsed });
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=responses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responses.js","sourceRoot":"","sources":["../../src/resources/responses.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAG5F,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAmC3D,MAAM,MAAM,GAAG,kBAAkB,CAAC;AAElC,MAAM,OAAO,UAAW,SAAQ,WAAW;IACzC,wGAAwG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,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC;IAC1H,IAAI,MAAM,GAAa,IAAI,CAAC;IAC5B,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,KAAK,aAAa,IAAI,MAAM,KAAK,aAAa,CAAC,EAAE,CAAC;QACvE,MAAM,KAAK,GAAY,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAE,KAAW,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type { Uploadable } from '../core/multipart.js';
|
|
2
|
+
/**
|
|
3
|
+
* Speech-to-text models. Start with `gpt-transcribe`; every other model listed here
|
|
4
|
+
* shuts down on 2027-02-26.
|
|
5
|
+
*/
|
|
6
|
+
export type TranscriptionModel = 'gpt-transcribe' | 'gpt-4o-transcribe' | 'gpt-4o-mini-transcribe' | 'gpt-4o-mini-transcribe-2025-12-15' | 'gpt-4o-transcribe-diarize' | 'whisper-1' | (string & {});
|
|
7
|
+
export type AudioResponseFormat = 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt' | 'diarized_json';
|
|
8
|
+
export interface VadConfig {
|
|
9
|
+
type: 'server_vad';
|
|
10
|
+
/** Audio to include before detected speech, in milliseconds. */
|
|
11
|
+
prefix_padding_ms?: number;
|
|
12
|
+
/** Silence that ends a speech segment, in milliseconds. */
|
|
13
|
+
silence_duration_ms?: number;
|
|
14
|
+
/** Detection sensitivity, 0.0–1.0. */
|
|
15
|
+
threshold?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface TranscriptionCreateParamsBase {
|
|
18
|
+
/**
|
|
19
|
+
* Audio file, at most 25 MB: flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav or webm. The format
|
|
20
|
+
* is detected from the filename, so use a `File` or `toFile(data, "name.ext")`.
|
|
21
|
+
*/
|
|
22
|
+
file: Uploadable;
|
|
23
|
+
model: TranscriptionModel;
|
|
24
|
+
response_format?: AudioResponseFormat;
|
|
25
|
+
/** ISO-639-1 code. With `gpt-transcribe`, use `languages` instead (not both). */
|
|
26
|
+
language?: string;
|
|
27
|
+
/** Candidate languages (`gpt-transcribe`). Accepts ISO 639-1, some ISO 639-3, and `zh-cn` / `zh-tw` / `zh-hk`. */
|
|
28
|
+
languages?: string[];
|
|
29
|
+
/** Domain terms to bias recognition (`gpt-transcribe`). Entries must not contain `<`, `>`, CR or LF. */
|
|
30
|
+
keywords?: string[];
|
|
31
|
+
/** Context or previous transcript; should match the audio language. Not supported by the diarize model. */
|
|
32
|
+
prompt?: string;
|
|
33
|
+
/** 0–1. 0 lets the model pick automatically. */
|
|
34
|
+
temperature?: number;
|
|
35
|
+
/** Requires `response_format: "verbose_json"` (whisper-1 only). */
|
|
36
|
+
timestamp_granularities?: Array<'word' | 'segment'>;
|
|
37
|
+
/** `logprobs` works with `json` output on gpt-4o-transcribe models. */
|
|
38
|
+
include?: Array<'logprobs'>;
|
|
39
|
+
/** Required for the diarize model when audio is longer than 30 seconds. */
|
|
40
|
+
chunking_strategy?: 'auto' | VadConfig;
|
|
41
|
+
/** Up to 4 speaker labels for diarization, e.g. `customer`, `agent`. */
|
|
42
|
+
known_speaker_names?: string[];
|
|
43
|
+
/** `data:` URLs of 2–10 second samples, matching `known_speaker_names`. */
|
|
44
|
+
known_speaker_references?: string[];
|
|
45
|
+
stream?: boolean | null;
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
}
|
|
48
|
+
export interface TranscriptionLogprob {
|
|
49
|
+
token?: string;
|
|
50
|
+
bytes?: number[];
|
|
51
|
+
logprob?: number;
|
|
52
|
+
}
|
|
53
|
+
export interface TranscriptionTokenUsage {
|
|
54
|
+
type: 'tokens';
|
|
55
|
+
input_tokens: number;
|
|
56
|
+
output_tokens: number;
|
|
57
|
+
total_tokens: number;
|
|
58
|
+
input_token_details?: {
|
|
59
|
+
audio_tokens?: number;
|
|
60
|
+
text_tokens?: number;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export interface TranscriptionDurationUsage {
|
|
64
|
+
type: 'duration';
|
|
65
|
+
/** Audio duration billed, in seconds. */
|
|
66
|
+
seconds: number;
|
|
67
|
+
}
|
|
68
|
+
export type TranscriptionUsage = TranscriptionTokenUsage | TranscriptionDurationUsage;
|
|
69
|
+
/** `response_format: "json"` (the default). */
|
|
70
|
+
export interface Transcription {
|
|
71
|
+
text: string;
|
|
72
|
+
/** Detected languages (`gpt-transcribe`); empty when detection was unreliable. */
|
|
73
|
+
languages?: Array<{
|
|
74
|
+
code: string;
|
|
75
|
+
}>;
|
|
76
|
+
logprobs?: TranscriptionLogprob[];
|
|
77
|
+
usage?: TranscriptionUsage;
|
|
78
|
+
_request_id?: string | null;
|
|
79
|
+
}
|
|
80
|
+
export interface TranscriptionSegment {
|
|
81
|
+
id: number;
|
|
82
|
+
seek: number;
|
|
83
|
+
start: number;
|
|
84
|
+
end: number;
|
|
85
|
+
text: string;
|
|
86
|
+
tokens: number[];
|
|
87
|
+
temperature: number;
|
|
88
|
+
avg_logprob: number;
|
|
89
|
+
compression_ratio: number;
|
|
90
|
+
no_speech_prob: number;
|
|
91
|
+
}
|
|
92
|
+
export interface TranscriptionWord {
|
|
93
|
+
word: string;
|
|
94
|
+
start: number;
|
|
95
|
+
end: number;
|
|
96
|
+
}
|
|
97
|
+
/** `response_format: "verbose_json"`. */
|
|
98
|
+
export interface TranscriptionVerbose {
|
|
99
|
+
duration: number;
|
|
100
|
+
language: string;
|
|
101
|
+
text: string;
|
|
102
|
+
segments?: TranscriptionSegment[];
|
|
103
|
+
words?: TranscriptionWord[];
|
|
104
|
+
usage?: TranscriptionDurationUsage;
|
|
105
|
+
_request_id?: string | null;
|
|
106
|
+
}
|
|
107
|
+
export interface TranscriptionDiarizedSegment {
|
|
108
|
+
id: string;
|
|
109
|
+
type: 'transcript.text.segment';
|
|
110
|
+
start: number;
|
|
111
|
+
end: number;
|
|
112
|
+
text: string;
|
|
113
|
+
/** A `known_speaker_names` value, otherwise `A`, `B`, ... */
|
|
114
|
+
speaker: string;
|
|
115
|
+
}
|
|
116
|
+
/** `response_format: "diarized_json"` (gpt-4o-transcribe-diarize). */
|
|
117
|
+
export interface TranscriptionDiarized {
|
|
118
|
+
task: 'transcribe';
|
|
119
|
+
duration: number;
|
|
120
|
+
text: string;
|
|
121
|
+
segments: TranscriptionDiarizedSegment[];
|
|
122
|
+
usage?: TranscriptionUsage;
|
|
123
|
+
_request_id?: string | null;
|
|
124
|
+
}
|
|
125
|
+
export interface TranscriptionTextDeltaEvent {
|
|
126
|
+
type: 'transcript.text.delta';
|
|
127
|
+
delta: string;
|
|
128
|
+
logprobs?: TranscriptionLogprob[];
|
|
129
|
+
/** Diarization only. */
|
|
130
|
+
segment_id?: string;
|
|
131
|
+
}
|
|
132
|
+
export interface TranscriptionTextDoneEvent {
|
|
133
|
+
type: 'transcript.text.done';
|
|
134
|
+
text: string;
|
|
135
|
+
languages?: Array<{
|
|
136
|
+
code: string;
|
|
137
|
+
}>;
|
|
138
|
+
logprobs?: TranscriptionLogprob[];
|
|
139
|
+
usage?: TranscriptionUsage;
|
|
140
|
+
}
|
|
141
|
+
/** Emitted with the diarize model and `response_format: "diarized_json"`. */
|
|
142
|
+
export interface TranscriptionTextSegmentEvent {
|
|
143
|
+
type: 'transcript.text.segment';
|
|
144
|
+
id: string;
|
|
145
|
+
start: number;
|
|
146
|
+
end: number;
|
|
147
|
+
speaker: string;
|
|
148
|
+
text: string;
|
|
149
|
+
}
|
|
150
|
+
export type TranscriptionStreamEvent = TranscriptionTextDeltaEvent | TranscriptionTextDoneEvent | TranscriptionTextSegmentEvent;
|
|
151
|
+
/** @deprecated `/audio/translations` shuts down on 2027-02-26. */
|
|
152
|
+
export interface TranslationCreateParams {
|
|
153
|
+
file: Uploadable;
|
|
154
|
+
/** Only `whisper-1`. */
|
|
155
|
+
model: 'whisper-1' | (string & {});
|
|
156
|
+
/** Should be in English. */
|
|
157
|
+
prompt?: string;
|
|
158
|
+
response_format?: 'json' | 'text' | 'srt' | 'verbose_json' | 'vtt';
|
|
159
|
+
temperature?: number;
|
|
160
|
+
[key: string]: unknown;
|
|
161
|
+
}
|
|
162
|
+
export interface Translation {
|
|
163
|
+
text: string;
|
|
164
|
+
_request_id?: string | null;
|
|
165
|
+
}
|
|
166
|
+
export interface TranslationVerbose {
|
|
167
|
+
duration: number;
|
|
168
|
+
language: string;
|
|
169
|
+
text: string;
|
|
170
|
+
segments?: TranscriptionSegment[];
|
|
171
|
+
_request_id?: string | null;
|
|
172
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audio.js","sourceRoot":"","sources":["../../src/types/audio.ts"],"names":[],"mappings":""}
|