openai 6.40.0 → 6.42.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/CHANGELOG.md +16 -0
- package/README.md +33 -0
- package/bedrock.d.mts +58 -0
- package/bedrock.d.mts.map +1 -0
- package/bedrock.d.ts +58 -0
- package/bedrock.d.ts.map +1 -0
- package/bedrock.js +105 -0
- package/bedrock.js.map +1 -0
- package/bedrock.mjs +100 -0
- package/bedrock.mjs.map +1 -0
- package/index.d.mts +1 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +1 -0
- package/index.d.ts.map +1 -1
- package/index.js +3 -1
- package/index.js.map +1 -1
- package/index.mjs +1 -0
- package/index.mjs.map +1 -1
- package/package.json +11 -1
- package/resources/chat/completions/completions.d.mts +350 -1
- package/resources/chat/completions/completions.d.mts.map +1 -1
- package/resources/chat/completions/completions.d.ts +350 -1
- package/resources/chat/completions/completions.d.ts.map +1 -1
- package/resources/chat/completions/completions.js.map +1 -1
- package/resources/chat/completions/completions.mjs.map +1 -1
- package/resources/responses/responses.d.mts +157 -0
- package/resources/responses/responses.d.mts.map +1 -1
- package/resources/responses/responses.d.ts +157 -0
- package/resources/responses/responses.d.ts.map +1 -1
- package/resources/responses/responses.js.map +1 -1
- package/resources/responses/responses.mjs.map +1 -1
- package/src/bedrock.ts +191 -0
- package/src/index.ts +1 -0
- package/src/resources/chat/completions/completions.ts +382 -1
- package/src/resources/responses/responses.ts +170 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/src/bedrock.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import * as Errors from './error';
|
|
2
|
+
import { OpenAI } from './client';
|
|
3
|
+
import type { ApiKeySetter, ClientOptions } from './client';
|
|
4
|
+
import type { NullableHeaders } from './internal/headers';
|
|
5
|
+
import { buildHeaders } from './internal/headers';
|
|
6
|
+
import type { FinalRequestOptions, RequestOptions } from './internal/request-options';
|
|
7
|
+
import { readEnv } from './internal/utils';
|
|
8
|
+
import { addOutputText } from './lib/ResponsesParser';
|
|
9
|
+
import type { ResponseStreamParams } from './lib/responses/ResponseStream';
|
|
10
|
+
import * as API from './resources/index';
|
|
11
|
+
import type * as ResponsesAPI from './resources/responses/responses';
|
|
12
|
+
|
|
13
|
+
export interface BedrockClientOptions
|
|
14
|
+
extends Omit<ClientOptions, 'apiKey' | 'adminAPIKey' | 'baseURL' | 'workloadIdentity'> {
|
|
15
|
+
/**
|
|
16
|
+
* Bedrock bearer token used for authentication.
|
|
17
|
+
*
|
|
18
|
+
* Defaults to process.env['AWS_BEARER_TOKEN_BEDROCK'].
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string | null | undefined;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Bedrock API root.
|
|
24
|
+
*
|
|
25
|
+
* Defaults to process.env['AWS_BEDROCK_BASE_URL'], or derives
|
|
26
|
+
* `https://bedrock-mantle.<region>.api.aws/openai/v1` from `awsRegion`,
|
|
27
|
+
* process.env['AWS_REGION'], or process.env['AWS_DEFAULT_REGION'].
|
|
28
|
+
*/
|
|
29
|
+
baseURL?: string | null | undefined;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* BedrockOpenAI only supports Bedrock bearer token authentication.
|
|
33
|
+
*/
|
|
34
|
+
adminAPIKey?: never;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* BedrockOpenAI only supports Bedrock bearer token authentication.
|
|
38
|
+
*/
|
|
39
|
+
workloadIdentity?: never;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* AWS region used to derive the default Bedrock Mantle endpoint.
|
|
43
|
+
*
|
|
44
|
+
* Defaults to process.env['AWS_REGION'] or process.env['AWS_DEFAULT_REGION'].
|
|
45
|
+
*/
|
|
46
|
+
awsRegion?: string | undefined;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A function that returns a Bedrock bearer token and is invoked before each request.
|
|
50
|
+
*/
|
|
51
|
+
bedrockTokenProvider?: ApiKeySetter | undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Resolve the default Bedrock Mantle API root from the configured AWS region. */
|
|
55
|
+
function deriveBedrockBaseURL(awsRegion: string | undefined): string {
|
|
56
|
+
const region = awsRegion?.trim();
|
|
57
|
+
if (!region) {
|
|
58
|
+
throw new Errors.OpenAIError(
|
|
59
|
+
'Must provide one of the `baseURL` or `awsRegion` arguments, or set the `AWS_BEDROCK_BASE_URL`, `AWS_REGION`, or `AWS_DEFAULT_REGION` environment variable.',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return `https://bedrock-mantle.${region}.api.aws/openai/v1`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Normalize a Bedrock Responses URL variant back to the provider API root. */
|
|
67
|
+
function normalizeBedrockBaseURL(baseURL: string): string {
|
|
68
|
+
const url = new URL(baseURL);
|
|
69
|
+
const responsesMatch = url.pathname.match(/\/responses(?:\/.*)?$/);
|
|
70
|
+
if (responsesMatch?.index !== undefined) {
|
|
71
|
+
url.pathname = url.pathname.slice(0, responsesMatch.index) || '/';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return url.toString().replace(/\/$/, '');
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Restore the SDK convenience property when Bedrock omits it from a streamed final response. */
|
|
78
|
+
function addBedrockOutputText<ResponseT extends ResponsesAPI.Response>(response: ResponseT): ResponseT {
|
|
79
|
+
if (!Object.getOwnPropertyDescriptor(response, 'output_text')) {
|
|
80
|
+
addOutputText(response);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return response;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Keep the standard Responses surface while repairing Bedrock streamed final responses. */
|
|
87
|
+
function restoreBedrockStreamOutputText(responses: API.Responses): API.Responses {
|
|
88
|
+
const stream = responses.stream.bind(responses);
|
|
89
|
+
|
|
90
|
+
responses.stream = ((body: ResponseStreamParams, options?: RequestOptions) => {
|
|
91
|
+
const responseStream = stream(body, options);
|
|
92
|
+
const finalResponse = responseStream.finalResponse.bind(responseStream);
|
|
93
|
+
responseStream.finalResponse = async () => addBedrockOutputText(await finalResponse());
|
|
94
|
+
|
|
95
|
+
return responseStream;
|
|
96
|
+
}) as API.Responses['stream'];
|
|
97
|
+
|
|
98
|
+
return responses;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** API Client for interfacing with Amazon Bedrock's OpenAI-compatible endpoint. */
|
|
102
|
+
export class BedrockOpenAI extends OpenAI {
|
|
103
|
+
private readonly bedrockTokenProvider: ApiKeySetter | undefined;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* API Client for interfacing with Amazon Bedrock's OpenAI-compatible endpoint.
|
|
107
|
+
*
|
|
108
|
+
* @param {string | null | undefined} [opts.apiKey=process.env['AWS_BEARER_TOKEN_BEDROCK'] ?? null]
|
|
109
|
+
* @param {string | null | undefined} [opts.baseURL=process.env['AWS_BEDROCK_BASE_URL'] ?? derived from opts.awsRegion or AWS_REGION/AWS_DEFAULT_REGION]
|
|
110
|
+
* @param {string | undefined} [opts.awsRegion=process.env['AWS_REGION'] ?? process.env['AWS_DEFAULT_REGION'] ?? undefined]
|
|
111
|
+
* @param {ApiKeySetter | undefined} opts.bedrockTokenProvider - A function that returns a Bedrock bearer token and is invoked before each request.
|
|
112
|
+
*/
|
|
113
|
+
constructor({
|
|
114
|
+
baseURL = readEnv('AWS_BEDROCK_BASE_URL'),
|
|
115
|
+
apiKey,
|
|
116
|
+
awsRegion = readEnv('AWS_REGION') ?? readEnv('AWS_DEFAULT_REGION'),
|
|
117
|
+
bedrockTokenProvider,
|
|
118
|
+
adminAPIKey,
|
|
119
|
+
workloadIdentity,
|
|
120
|
+
...opts
|
|
121
|
+
}: BedrockClientOptions = {}) {
|
|
122
|
+
if (adminAPIKey || workloadIdentity) {
|
|
123
|
+
throw new Errors.OpenAIError('BedrockOpenAI only supports Bedrock bearer token authentication.');
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (apiKey === undefined && !bedrockTokenProvider) {
|
|
127
|
+
apiKey = readEnv('AWS_BEARER_TOKEN_BEDROCK') ?? null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (typeof (apiKey as unknown) === 'function') {
|
|
131
|
+
throw new Errors.OpenAIError(
|
|
132
|
+
'Pass refreshable Bedrock credentials via `bedrockTokenProvider`, not `apiKey`.',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (apiKey && bedrockTokenProvider) {
|
|
137
|
+
throw new Errors.OpenAIError(
|
|
138
|
+
'The `apiKey` and `bedrockTokenProvider` arguments are mutually exclusive; only one can be passed at a time.',
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (!apiKey && !bedrockTokenProvider) {
|
|
143
|
+
throw new Errors.OpenAIError(
|
|
144
|
+
'Missing credentials. Please pass an `apiKey` or `bedrockTokenProvider`, or set the `AWS_BEARER_TOKEN_BEDROCK` environment variable.',
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const configuredBaseURL = baseURL?.trim() ? baseURL : deriveBedrockBaseURL(awsRegion);
|
|
149
|
+
|
|
150
|
+
super({
|
|
151
|
+
apiKey: bedrockTokenProvider ?? apiKey,
|
|
152
|
+
adminAPIKey: null,
|
|
153
|
+
baseURL: normalizeBedrockBaseURL(configuredBaseURL),
|
|
154
|
+
...opts,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
this.bedrockTokenProvider = bedrockTokenProvider;
|
|
158
|
+
this.responses = restoreBedrockStreamOutputText(new API.Responses(this));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
protected override async prepareOptions(options: FinalRequestOptions): Promise<void> {
|
|
162
|
+
const security = options.__security ?? { bearerAuth: true };
|
|
163
|
+
if (security.adminAPIKeyAuth && !security.bearerAuth) {
|
|
164
|
+
await this._callApiKey();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
await super.prepareOptions(options);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
protected override async authHeaders(
|
|
171
|
+
opts: FinalRequestOptions,
|
|
172
|
+
schemes?: { bearerAuth?: boolean; adminAPIKeyAuth?: boolean },
|
|
173
|
+
): Promise<NullableHeaders | undefined> {
|
|
174
|
+
const security = schemes ?? { bearerAuth: true, adminAPIKeyAuth: true };
|
|
175
|
+
if ((security.bearerAuth || security.adminAPIKeyAuth) && this.apiKey !== null) {
|
|
176
|
+
return buildHeaders([{ Authorization: `Bearer ${this.apiKey}` }]);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return super.authHeaders(opts, security);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
override withOptions(options: Partial<BedrockClientOptions>): this {
|
|
183
|
+
const bedrockTokenProvider =
|
|
184
|
+
options.apiKey !== undefined ? undefined : options.bedrockTokenProvider ?? this.bedrockTokenProvider;
|
|
185
|
+
|
|
186
|
+
return super.withOptions({
|
|
187
|
+
...options,
|
|
188
|
+
...(bedrockTokenProvider ? { apiKey: undefined, bedrockTokenProvider } : {}),
|
|
189
|
+
} as Partial<ClientOptions>);
|
|
190
|
+
}
|
|
191
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -295,6 +295,12 @@ export interface ChatCompletion {
|
|
|
295
295
|
*/
|
|
296
296
|
object: 'chat.completion';
|
|
297
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Moderation results for the request input and generated output, if moderated
|
|
300
|
+
* completions were requested.
|
|
301
|
+
*/
|
|
302
|
+
moderation?: ChatCompletion.Moderation | null;
|
|
303
|
+
|
|
298
304
|
/**
|
|
299
305
|
* Specifies the processing type used for serving the request.
|
|
300
306
|
*
|
|
@@ -338,7 +344,8 @@ export namespace ChatCompletion {
|
|
|
338
344
|
* number of tokens specified in the request was reached, `content_filter` if
|
|
339
345
|
* content was omitted due to a flag from our content filters, `tool_calls` if the
|
|
340
346
|
* model called a tool, or `function_call` (deprecated) if the model called a
|
|
341
|
-
* function.
|
|
347
|
+
* function. Read the [Model Spec](https://model-spec.openai.com/2025-12-18.html)
|
|
348
|
+
* for more.
|
|
342
349
|
*/
|
|
343
350
|
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | 'function_call';
|
|
344
351
|
|
|
@@ -374,6 +381,182 @@ export namespace ChatCompletion {
|
|
|
374
381
|
refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
|
|
375
382
|
}
|
|
376
383
|
}
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* Moderation results for the request input and generated output, if moderated
|
|
387
|
+
* completions were requested.
|
|
388
|
+
*/
|
|
389
|
+
export interface Moderation {
|
|
390
|
+
/**
|
|
391
|
+
* Moderation for the request input.
|
|
392
|
+
*/
|
|
393
|
+
input: Moderation.ModerationResults | Moderation.Error;
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Moderation for the generated output.
|
|
397
|
+
*/
|
|
398
|
+
output: Moderation.ModerationResults | Moderation.Error;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
export namespace Moderation {
|
|
402
|
+
/**
|
|
403
|
+
* Successful moderation results for the request input or generated output.
|
|
404
|
+
*/
|
|
405
|
+
export interface ModerationResults {
|
|
406
|
+
/**
|
|
407
|
+
* The moderation model used to generate the results.
|
|
408
|
+
*/
|
|
409
|
+
model: string;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* A list of moderation results.
|
|
413
|
+
*/
|
|
414
|
+
results: Array<ModerationResults.Result>;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* The object type, which is always `moderation_results`.
|
|
418
|
+
*/
|
|
419
|
+
type: 'moderation_results';
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export namespace ModerationResults {
|
|
423
|
+
/**
|
|
424
|
+
* A moderation result produced for the response input or output.
|
|
425
|
+
*/
|
|
426
|
+
export interface Result {
|
|
427
|
+
/**
|
|
428
|
+
* A dictionary of moderation categories to booleans, True if the input is flagged
|
|
429
|
+
* under this category.
|
|
430
|
+
*/
|
|
431
|
+
categories: { [key: string]: boolean };
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* Which modalities of input are reflected by the score for each category.
|
|
435
|
+
*/
|
|
436
|
+
category_applied_input_types: { [key: string]: Array<'text' | 'image'> };
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* A dictionary of moderation categories to scores.
|
|
440
|
+
*/
|
|
441
|
+
category_scores: { [key: string]: number };
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* A boolean indicating whether the content was flagged by any category.
|
|
445
|
+
*/
|
|
446
|
+
flagged: boolean;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* The moderation model that produced this result.
|
|
450
|
+
*/
|
|
451
|
+
model: string;
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* The object type, which was always `moderation_result` for successful moderation
|
|
455
|
+
* results.
|
|
456
|
+
*/
|
|
457
|
+
type: 'moderation_result';
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* An error produced while attempting moderation.
|
|
463
|
+
*/
|
|
464
|
+
export interface Error {
|
|
465
|
+
/**
|
|
466
|
+
* The error code.
|
|
467
|
+
*/
|
|
468
|
+
code: string;
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* The error message.
|
|
472
|
+
*/
|
|
473
|
+
message: string;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* The object type, which is always `error`.
|
|
477
|
+
*/
|
|
478
|
+
type: 'error';
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Successful moderation results for the request input or generated output.
|
|
483
|
+
*/
|
|
484
|
+
export interface ModerationResults {
|
|
485
|
+
/**
|
|
486
|
+
* The moderation model used to generate the results.
|
|
487
|
+
*/
|
|
488
|
+
model: string;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* A list of moderation results.
|
|
492
|
+
*/
|
|
493
|
+
results: Array<ModerationResults.Result>;
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* The object type, which is always `moderation_results`.
|
|
497
|
+
*/
|
|
498
|
+
type: 'moderation_results';
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export namespace ModerationResults {
|
|
502
|
+
/**
|
|
503
|
+
* A moderation result produced for the response input or output.
|
|
504
|
+
*/
|
|
505
|
+
export interface Result {
|
|
506
|
+
/**
|
|
507
|
+
* A dictionary of moderation categories to booleans, True if the input is flagged
|
|
508
|
+
* under this category.
|
|
509
|
+
*/
|
|
510
|
+
categories: { [key: string]: boolean };
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Which modalities of input are reflected by the score for each category.
|
|
514
|
+
*/
|
|
515
|
+
category_applied_input_types: { [key: string]: Array<'text' | 'image'> };
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* A dictionary of moderation categories to scores.
|
|
519
|
+
*/
|
|
520
|
+
category_scores: { [key: string]: number };
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* A boolean indicating whether the content was flagged by any category.
|
|
524
|
+
*/
|
|
525
|
+
flagged: boolean;
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* The moderation model that produced this result.
|
|
529
|
+
*/
|
|
530
|
+
model: string;
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* The object type, which was always `moderation_result` for successful moderation
|
|
534
|
+
* results.
|
|
535
|
+
*/
|
|
536
|
+
type: 'moderation_result';
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* An error produced while attempting moderation.
|
|
542
|
+
*/
|
|
543
|
+
export interface Error {
|
|
544
|
+
/**
|
|
545
|
+
* The error code.
|
|
546
|
+
*/
|
|
547
|
+
code: string;
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* The error message.
|
|
551
|
+
*/
|
|
552
|
+
message: string;
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* The object type, which is always `error`.
|
|
556
|
+
*/
|
|
557
|
+
type: 'error';
|
|
558
|
+
}
|
|
559
|
+
}
|
|
377
560
|
}
|
|
378
561
|
|
|
379
562
|
/**
|
|
@@ -575,6 +758,12 @@ export interface ChatCompletionChunk {
|
|
|
575
758
|
*/
|
|
576
759
|
object: 'chat.completion.chunk';
|
|
577
760
|
|
|
761
|
+
/**
|
|
762
|
+
* Moderation results for the request input and generated output. Present on the
|
|
763
|
+
* moderation chunk when moderated completions are requested.
|
|
764
|
+
*/
|
|
765
|
+
moderation?: ChatCompletionChunk.Moderation | null;
|
|
766
|
+
|
|
578
767
|
/**
|
|
579
768
|
* Specifies the processing type used for serving the request.
|
|
580
769
|
*
|
|
@@ -740,6 +929,182 @@ export namespace ChatCompletionChunk {
|
|
|
740
929
|
refusal: Array<ChatCompletionsAPI.ChatCompletionTokenLogprob> | null;
|
|
741
930
|
}
|
|
742
931
|
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Moderation results for the request input and generated output. Present on the
|
|
935
|
+
* moderation chunk when moderated completions are requested.
|
|
936
|
+
*/
|
|
937
|
+
export interface Moderation {
|
|
938
|
+
/**
|
|
939
|
+
* Moderation for the request input.
|
|
940
|
+
*/
|
|
941
|
+
input: Moderation.ModerationResults | Moderation.Error;
|
|
942
|
+
|
|
943
|
+
/**
|
|
944
|
+
* Moderation for the generated output.
|
|
945
|
+
*/
|
|
946
|
+
output: Moderation.ModerationResults | Moderation.Error;
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
export namespace Moderation {
|
|
950
|
+
/**
|
|
951
|
+
* Successful moderation results for the request input or generated output.
|
|
952
|
+
*/
|
|
953
|
+
export interface ModerationResults {
|
|
954
|
+
/**
|
|
955
|
+
* The moderation model used to generate the results.
|
|
956
|
+
*/
|
|
957
|
+
model: string;
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* A list of moderation results.
|
|
961
|
+
*/
|
|
962
|
+
results: Array<ModerationResults.Result>;
|
|
963
|
+
|
|
964
|
+
/**
|
|
965
|
+
* The object type, which is always `moderation_results`.
|
|
966
|
+
*/
|
|
967
|
+
type: 'moderation_results';
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
export namespace ModerationResults {
|
|
971
|
+
/**
|
|
972
|
+
* A moderation result produced for the response input or output.
|
|
973
|
+
*/
|
|
974
|
+
export interface Result {
|
|
975
|
+
/**
|
|
976
|
+
* A dictionary of moderation categories to booleans, True if the input is flagged
|
|
977
|
+
* under this category.
|
|
978
|
+
*/
|
|
979
|
+
categories: { [key: string]: boolean };
|
|
980
|
+
|
|
981
|
+
/**
|
|
982
|
+
* Which modalities of input are reflected by the score for each category.
|
|
983
|
+
*/
|
|
984
|
+
category_applied_input_types: { [key: string]: Array<'text' | 'image'> };
|
|
985
|
+
|
|
986
|
+
/**
|
|
987
|
+
* A dictionary of moderation categories to scores.
|
|
988
|
+
*/
|
|
989
|
+
category_scores: { [key: string]: number };
|
|
990
|
+
|
|
991
|
+
/**
|
|
992
|
+
* A boolean indicating whether the content was flagged by any category.
|
|
993
|
+
*/
|
|
994
|
+
flagged: boolean;
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* The moderation model that produced this result.
|
|
998
|
+
*/
|
|
999
|
+
model: string;
|
|
1000
|
+
|
|
1001
|
+
/**
|
|
1002
|
+
* The object type, which was always `moderation_result` for successful moderation
|
|
1003
|
+
* results.
|
|
1004
|
+
*/
|
|
1005
|
+
type: 'moderation_result';
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* An error produced while attempting moderation.
|
|
1011
|
+
*/
|
|
1012
|
+
export interface Error {
|
|
1013
|
+
/**
|
|
1014
|
+
* The error code.
|
|
1015
|
+
*/
|
|
1016
|
+
code: string;
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* The error message.
|
|
1020
|
+
*/
|
|
1021
|
+
message: string;
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* The object type, which is always `error`.
|
|
1025
|
+
*/
|
|
1026
|
+
type: 'error';
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
/**
|
|
1030
|
+
* Successful moderation results for the request input or generated output.
|
|
1031
|
+
*/
|
|
1032
|
+
export interface ModerationResults {
|
|
1033
|
+
/**
|
|
1034
|
+
* The moderation model used to generate the results.
|
|
1035
|
+
*/
|
|
1036
|
+
model: string;
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* A list of moderation results.
|
|
1040
|
+
*/
|
|
1041
|
+
results: Array<ModerationResults.Result>;
|
|
1042
|
+
|
|
1043
|
+
/**
|
|
1044
|
+
* The object type, which is always `moderation_results`.
|
|
1045
|
+
*/
|
|
1046
|
+
type: 'moderation_results';
|
|
1047
|
+
}
|
|
1048
|
+
|
|
1049
|
+
export namespace ModerationResults {
|
|
1050
|
+
/**
|
|
1051
|
+
* A moderation result produced for the response input or output.
|
|
1052
|
+
*/
|
|
1053
|
+
export interface Result {
|
|
1054
|
+
/**
|
|
1055
|
+
* A dictionary of moderation categories to booleans, True if the input is flagged
|
|
1056
|
+
* under this category.
|
|
1057
|
+
*/
|
|
1058
|
+
categories: { [key: string]: boolean };
|
|
1059
|
+
|
|
1060
|
+
/**
|
|
1061
|
+
* Which modalities of input are reflected by the score for each category.
|
|
1062
|
+
*/
|
|
1063
|
+
category_applied_input_types: { [key: string]: Array<'text' | 'image'> };
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* A dictionary of moderation categories to scores.
|
|
1067
|
+
*/
|
|
1068
|
+
category_scores: { [key: string]: number };
|
|
1069
|
+
|
|
1070
|
+
/**
|
|
1071
|
+
* A boolean indicating whether the content was flagged by any category.
|
|
1072
|
+
*/
|
|
1073
|
+
flagged: boolean;
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* The moderation model that produced this result.
|
|
1077
|
+
*/
|
|
1078
|
+
model: string;
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* The object type, which was always `moderation_result` for successful moderation
|
|
1082
|
+
* results.
|
|
1083
|
+
*/
|
|
1084
|
+
type: 'moderation_result';
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* An error produced while attempting moderation.
|
|
1090
|
+
*/
|
|
1091
|
+
export interface Error {
|
|
1092
|
+
/**
|
|
1093
|
+
* The error code.
|
|
1094
|
+
*/
|
|
1095
|
+
code: string;
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* The error message.
|
|
1099
|
+
*/
|
|
1100
|
+
message: string;
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* The object type, which is always `error`.
|
|
1104
|
+
*/
|
|
1105
|
+
type: 'error';
|
|
1106
|
+
}
|
|
1107
|
+
}
|
|
743
1108
|
}
|
|
744
1109
|
|
|
745
1110
|
/**
|
|
@@ -1641,6 +2006,11 @@ export interface ChatCompletionCreateParamsBase {
|
|
|
1641
2006
|
*/
|
|
1642
2007
|
modalities?: Array<'text' | 'audio'> | null;
|
|
1643
2008
|
|
|
2009
|
+
/**
|
|
2010
|
+
* Configuration for running moderation on the request input and generated output.
|
|
2011
|
+
*/
|
|
2012
|
+
moderation?: ChatCompletionCreateParams.Moderation | null;
|
|
2013
|
+
|
|
1644
2014
|
/**
|
|
1645
2015
|
* How many chat completion choices to generate for each input message. Note that
|
|
1646
2016
|
* you will be charged based on the number of generated tokens across all of the
|
|
@@ -1897,6 +2267,17 @@ export namespace ChatCompletionCreateParams {
|
|
|
1897
2267
|
parameters?: Shared.FunctionParameters;
|
|
1898
2268
|
}
|
|
1899
2269
|
|
|
2270
|
+
/**
|
|
2271
|
+
* Configuration for running moderation on the request input and generated output.
|
|
2272
|
+
*/
|
|
2273
|
+
export interface Moderation {
|
|
2274
|
+
/**
|
|
2275
|
+
* The moderation model to use for moderated completions, e.g.
|
|
2276
|
+
* 'omni-moderation-latest'.
|
|
2277
|
+
*/
|
|
2278
|
+
model: string;
|
|
2279
|
+
}
|
|
2280
|
+
|
|
1900
2281
|
/**
|
|
1901
2282
|
* This tool searches the web for relevant results to use in a response. Learn more
|
|
1902
2283
|
* about the
|