Skip to content

Commit 85de382

Browse files
authored
fix(azure/audio): use model param for deployments (#1297)
1 parent 145ff67 commit 85de382

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

Diff for: src/core.ts

+2
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ export type RequestOptions<
814814
signal?: AbortSignal | undefined | null;
815815
idempotencyKey?: string;
816816

817+
__metadata?: Record<string, unknown>;
817818
__binaryRequest?: boolean | undefined;
818819
__binaryResponse?: boolean | undefined;
819820
__streamClass?: typeof Stream;
@@ -836,6 +837,7 @@ const requestOptionsKeys: KeysEnum<RequestOptions> = {
836837
signal: true,
837838
idempotencyKey: true,
838839

840+
__metadata: true,
839841
__binaryRequest: true,
840842
__binaryResponse: true,
841843
__streamClass: true,

Diff for: src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ export class AzureOpenAI extends OpenAI {
590590
if (!Core.isObj(options.body)) {
591591
throw new Error('Expected request body to be an object');
592592
}
593-
const model = this.deploymentName || options.body['model'];
593+
const model = this.deploymentName || options.body['model'] || options.__metadata?.['model'];
594594
if (model !== undefined && !this.baseURL.includes('/deployments')) {
595595
options.path = `/deployments/${model}${options.path}`;
596596
}

Diff for: src/resources/audio/transcriptions.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ export class Transcriptions extends APIResource {
2525
body: TranscriptionCreateParams,
2626
options?: Core.RequestOptions,
2727
): Core.APIPromise<TranscriptionCreateResponse | string> {
28-
return this._client.post('/audio/transcriptions', Core.multipartFormRequestOptions({ body, ...options }));
28+
return this._client.post(
29+
'/audio/transcriptions',
30+
Core.multipartFormRequestOptions({ body, ...options, __metadata: { model: body.model } }),
31+
);
2932
}
3033
}
3134

Diff for: src/resources/audio/translations.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export class Translations extends APIResource {
2626
body: TranslationCreateParams,
2727
options?: Core.RequestOptions,
2828
): Core.APIPromise<TranslationCreateResponse | string> {
29-
return this._client.post('/audio/translations', Core.multipartFormRequestOptions({ body, ...options }));
29+
return this._client.post(
30+
'/audio/translations',
31+
Core.multipartFormRequestOptions({ body, ...options, __metadata: { model: body.model } }),
32+
);
3033
}
3134
}
3235

Diff for: tests/lib/azure.test.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -495,21 +495,23 @@ describe('azure request building', () => {
495495
);
496496
});
497497

498-
test('Audio translations is not handled', async () => {
498+
test('handles audio translations', async () => {
499499
const { url } = (await client.audio.translations.create({
500500
model: deployment,
501501
file: { url: 'https://example.com', blob: () => 0 as any },
502502
})) as any;
503-
expect(url).toStrictEqual(`https://example.com/openai/audio/translations?api-version=${apiVersion}`);
503+
expect(url).toStrictEqual(
504+
`https://example.com/openai/deployments/${deployment}/audio/translations?api-version=${apiVersion}`,
505+
);
504506
});
505507

506-
test('Audio transcriptions is not handled', async () => {
508+
test('handles audio transcriptions', async () => {
507509
const { url } = (await client.audio.transcriptions.create({
508510
model: deployment,
509511
file: { url: 'https://example.com', blob: () => 0 as any },
510512
})) as any;
511513
expect(url).toStrictEqual(
512-
`https://example.com/openai/audio/transcriptions?api-version=${apiVersion}`,
514+
`https://example.com/openai/deployments/${deployment}/audio/transcriptions?api-version=${apiVersion}`,
513515
);
514516
});
515517

0 commit comments

Comments
 (0)