@ai-sdk/azure 4.0.117 → 4.0.119
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 +25 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +169 -44
- package/dist/index.js.map +1 -1
- package/docs/04-azure.mdx +76 -23
- package/package.json +6 -6
- package/src/azure-deployment-model-catalog.ts +21 -0
- package/src/azure-image-model-options.ts +2 -10
- package/src/azure-model-catalog.ts +178 -0
- package/src/azure-openai-provider.ts +126 -25
- package/src/azure-speech-model-options.ts +5 -9
- package/src/azure-transcription-model-options.ts +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @ai-sdk/azure
|
|
2
2
|
|
|
3
|
+
## 4.0.119
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 6400cf8: Add `resolveProviderOptions` to parse provider options that a model accepts under several `providerOptions` keys, either as aliases (`first`) or merged in order (`merge`), and use it for the existing multi-key lookups in the OpenAI, OpenAI-compatible, Anthropic, Google, and Amazon Bedrock models. Resolution behavior for these models is unchanged.
|
|
8
|
+
- Updated dependencies [6400cf8]
|
|
9
|
+
- Updated dependencies [f608c05]
|
|
10
|
+
- Updated dependencies [cab9c1f]
|
|
11
|
+
- Updated dependencies [c70adf6]
|
|
12
|
+
- @ai-sdk/provider-utils@5.0.76
|
|
13
|
+
- @ai-sdk/openai@4.0.111
|
|
14
|
+
- @ai-sdk/provider@4.0.37
|
|
15
|
+
- @ai-sdk/deepseek@3.0.81
|
|
16
|
+
|
|
17
|
+
## 4.0.118
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- c6efa4b: Refactor Azure model ID logic into a model catalog that declares capabilities and provider options, and generate provider capability documentation from it. Export the OpenAI catalog internally for Azure to reuse. Request behavior is unchanged.
|
|
22
|
+
- Updated dependencies [c6efa4b]
|
|
23
|
+
- Updated dependencies [f6dbf04]
|
|
24
|
+
- Updated dependencies [646a7e3]
|
|
25
|
+
- Updated dependencies [6b97088]
|
|
26
|
+
- @ai-sdk/openai@4.0.110
|
|
27
|
+
|
|
3
28
|
## 4.0.117
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -212,6 +212,8 @@ type AzureImageModelOptions = InferSchema<typeof azureImageModelOptions>;
|
|
|
212
212
|
declare const azureSpeechModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
213
213
|
style?: string | undefined;
|
|
214
214
|
styleDegree?: number | undefined;
|
|
215
|
+
instructions?: string | null | undefined;
|
|
216
|
+
speed?: number | null | undefined;
|
|
215
217
|
api?: "openai" | "speech" | undefined;
|
|
216
218
|
}>;
|
|
217
219
|
type AzureSpeechModelOptions = InferSchema<typeof azureSpeechModelOptions>;
|
|
@@ -228,6 +230,23 @@ declare const azureTranscriptionModelOptions: import("@ai-sdk/provider-utils").L
|
|
|
228
230
|
phraseList?: {
|
|
229
231
|
phrases: string[];
|
|
230
232
|
} | undefined;
|
|
233
|
+
include?: string[] | undefined;
|
|
234
|
+
languages?: string[] | undefined;
|
|
235
|
+
keywords?: string[] | undefined;
|
|
236
|
+
prompt?: string | undefined;
|
|
237
|
+
temperature?: number | undefined;
|
|
238
|
+
timestampGranularities?: ("word" | "segment")[] | undefined;
|
|
239
|
+
responseFormat?: "json" | "verbose_json" | "diarized_json" | undefined;
|
|
240
|
+
chunkingStrategy?: "auto" | {
|
|
241
|
+
type: "server_vad";
|
|
242
|
+
threshold?: number | undefined;
|
|
243
|
+
prefixPaddingMs?: number | undefined;
|
|
244
|
+
silenceDurationMs?: number | undefined;
|
|
245
|
+
} | undefined;
|
|
246
|
+
streaming?: {
|
|
247
|
+
delay?: "low" | "medium" | "high" | "xhigh" | "minimal" | undefined;
|
|
248
|
+
include?: string[] | undefined;
|
|
249
|
+
} | undefined;
|
|
231
250
|
api?: "openai" | "mai" | "speech" | undefined;
|
|
232
251
|
}>;
|
|
233
252
|
type AzureTranscriptionModelOptions = InferSchema<typeof azureTranscriptionModelOptions>;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/azure-openai-tools.ts","../src/azure-openai-provider.ts","../src/azure-openai-provider-metadata.ts","../src/version.ts","../src/azure-image-model-options.ts","../src/azure-speech-model-options.ts","../src/azure-transcription-model-options.ts","../src/azure-transcription-provider-metadata.ts","../src/index.ts"],"mappings":";;;;;;cAYa;EACX,mBAAmB;EACnB,wBAAwB;EACxB,mBAAmB;EACnB,mBAAmB;EACnB,wBAAwB;EACxB,cAAc;EACd,mBAAmB;EACnB,kBAAkB;;;;EAIlB,yBAAyB;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/azure-openai-tools.ts","../src/azure-openai-provider.ts","../src/azure-openai-provider-metadata.ts","../src/version.ts","../src/azure-image-model-options.ts","../src/azure-speech-model-options.ts","../src/azure-transcription-model-options.ts","../src/azure-transcription-provider-metadata.ts","../src/index.ts"],"mappings":";;;;;;cAYa;EACX,mBAAmB;EACnB,wBAAwB;EACxB,mBAAmB;EACnB,mBAAmB;EACnB,wBAAwB;EACxB,cAAc;EACd,mBAAmB;EACnB,kBAAkB;;;;EAIlB,yBAAyB;;;;UCwCV;;;;;EAKf;;UAGe,4BAA4B;;;;;GAMzC,sBACA,WAAW,mCACV;;;;;EAMH,cACE,sBACA,WAAW,mCACV;;;;;EAMH,KACE,sBACA,WAAW,mCACV;;;;EAKH,SAAS,uBAAuB;;;;;EAMhC,UACE,sBACA,WAAW,mCACV;;;;;EAMH,WACE,sBACA,WAAW,mCACV;;;;EAKH,UAAU,uBAAuB;;;;EAKjC,eAAe,uBAAuB;;;;EAKtC,cAAc,uBAAuB;;;;EAKrC,mBAAmB,uBAAuB;;;;;EAM1C,MAAM,uBAAuB;;;;EAK7B,WAAW,uBAAuB;;;;;;EAOlC,cAAc,uBAAuB;;;;EAKrC,mBAAmB,uBAAuB;;;;;EAM1C,OAAO,uBAAuB;;;;EAK9B,YAAY,uBAAuB;;;;EAKnC,cAAc;;UAGC;;;;;;;EAOf;;;;;;;;;EAUA;;;;EAKA,SAAS;;;;;;EAOT,uBAAuB;;;;EAKvB,UAAU;;;;;EAMV,QAAQ;;;;;EAMR;;;;;;EAOA;;;;;;;;EASA;;;;;EAMA;;;;;;;EAQA,YAAY;;;;;wBAgCE,YACd,UAAS,8BACR;;;;qBAyRU,OAAK;;;KCvjBN;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;;;qBClBI;;;cCOA,yDAAsB;;;;;KAYvB,yBAAyB,mBAAmB;;;cCX3C,0DAAuB;;;;;;;KAcxB,0BAA0B,mBAC7B;;;cCdI,iEAA8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiB/B,iCAAiC,mBACpC;;;KC7BG;EACV;IACE,SAAS;MACP;MACA;MACA;MACA;MACA;MACA;MACA,QAAQ;QACN;QACA;QACA;;;;;;;YCVI,oCAAoC,KAC9C;;YAIU,2BAA2B"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
import { OpenAIChatLanguageModel, OpenAICompletionLanguageModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIResponsesLanguageModel, OpenAISpeechModel, OpenAITranscriptionModel, applyPatch, codeInterpreter, customTool, fileSearch, imageGeneration, shell, toolSearch, webSearch, webSearchPreview } from "@ai-sdk/openai/internal";
|
|
1
|
+
import { OpenAIChatLanguageModel, OpenAICompletionLanguageModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIResponsesLanguageModel, OpenAISpeechModel, OpenAITranscriptionModel, applyPatch, codeInterpreter, customTool, fileSearch, imageGeneration, openAITranscriptionModelOptionsShape, openaiImageModelEditOptionsShape, openaiImageModelGenerationOptionsShape, openaiSpeechModelOptionsShape, shell, toolSearch, webSearch, webSearchPreview } from "@ai-sdk/openai/internal";
|
|
2
2
|
import { DeepSeekChatLanguageModel } from "@ai-sdk/deepseek/internal";
|
|
3
3
|
import { APICallError, InvalidArgumentError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
4
4
|
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, createBinaryResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, downloadBlob, extractResponseHeaders, isValidHostnamePart, lazySchema, loadApiKey, loadSetting, mediaTypeToExtension, normalizeHeaders, parseProviderOptions, postFormDataToApi, postJsonToApi, postToApi, resolve, resolveWith, safeParseJSON, serializeModelOptions, toWebSocketUrl, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
|
+
//#region src/azure-model-catalog.ts
|
|
7
|
+
function imageEntry(webGrounding) {
|
|
8
|
+
return {
|
|
9
|
+
capabilities: { image: {
|
|
10
|
+
sizes: { description: "Sides must be multiples of 16 and at least 768 pixels." },
|
|
11
|
+
fileInput: true,
|
|
12
|
+
maskInput: false,
|
|
13
|
+
maxImagesPerCall: 1
|
|
14
|
+
} },
|
|
15
|
+
providerOptions: { image: {
|
|
16
|
+
api: true,
|
|
17
|
+
autoAspectRatio: webGrounding,
|
|
18
|
+
webGrounding
|
|
19
|
+
} },
|
|
20
|
+
requestConfig: { image: { api: "mai" } }
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function speechEntry(voiceModel) {
|
|
24
|
+
return {
|
|
25
|
+
capabilities: { speech: { instructions: false } },
|
|
26
|
+
providerOptions: { speech: {
|
|
27
|
+
api: true,
|
|
28
|
+
style: { condition: "Supported styles depend on the selected voice and model." },
|
|
29
|
+
styleDegree: { condition: "Requires a supported speaking style." }
|
|
30
|
+
} },
|
|
31
|
+
requestConfig: { speech: {
|
|
32
|
+
api: "speech",
|
|
33
|
+
voiceModel
|
|
34
|
+
} }
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function transcriptionEntry(name, supportsTimestamps) {
|
|
38
|
+
return {
|
|
39
|
+
capabilities: { transcription: {
|
|
40
|
+
transcription: true,
|
|
41
|
+
streaming: false,
|
|
42
|
+
duration: true,
|
|
43
|
+
segments: supportsTimestamps,
|
|
44
|
+
language: true
|
|
45
|
+
} },
|
|
46
|
+
providerOptions: { transcription: {
|
|
47
|
+
api: true,
|
|
48
|
+
language: { condition: "Requires the MAI streaming API override." },
|
|
49
|
+
timestamps: supportsTimestamps ? true : { condition: "Only none is supported." },
|
|
50
|
+
transcribeStyle: supportsTimestamps ? true : { condition: "Only verbatim is supported." },
|
|
51
|
+
locales: true,
|
|
52
|
+
diarization: supportsTimestamps,
|
|
53
|
+
phraseList: true
|
|
54
|
+
} },
|
|
55
|
+
requestConfig: { transcription: {
|
|
56
|
+
api: "speech",
|
|
57
|
+
name,
|
|
58
|
+
supportsTimestamps
|
|
59
|
+
} }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Azure-owned models. OpenAI and DeepSeek deployments use their adapters' model
|
|
64
|
+
* catalogs; arbitrary deployment names do not declare model-family support.
|
|
65
|
+
*/
|
|
66
|
+
const azureModelCatalog = {
|
|
67
|
+
"mai-image-2.5": imageEntry(false),
|
|
68
|
+
"mai-image-2.5-flash": imageEntry(false),
|
|
69
|
+
"mai-image-2.5-pro": imageEntry(false),
|
|
70
|
+
"mai-image-2.6": imageEntry(true),
|
|
71
|
+
"mai-image-2.6-flash": imageEntry(true),
|
|
72
|
+
"mai-voice-2.1-flash": speechEntry("MAI-Voice-2.1-Flash"),
|
|
73
|
+
"mai-voice-2.1": speechEntry("MAI-Voice-2.1"),
|
|
74
|
+
"mai-voice-2-flash": speechEntry("MAI-Voice-2-Flash"),
|
|
75
|
+
"mai-voice-2": speechEntry("MAI-Voice-2"),
|
|
76
|
+
"mai-transcribe-2": transcriptionEntry("MAI-Transcribe-2", true),
|
|
77
|
+
"mai-transcribe-1.5": transcriptionEntry("MAI-Transcribe-1.5", false),
|
|
78
|
+
"mai-transcribe-2-streaming": {
|
|
79
|
+
capabilities: { transcription: {
|
|
80
|
+
transcription: false,
|
|
81
|
+
streaming: true,
|
|
82
|
+
duration: { condition: "Requires an audio format with a known byte rate." },
|
|
83
|
+
segments: false,
|
|
84
|
+
language: { condition: "Reports the configured language hint." }
|
|
85
|
+
} },
|
|
86
|
+
providerOptions: { transcription: {
|
|
87
|
+
api: true,
|
|
88
|
+
language: true,
|
|
89
|
+
timestamps: false,
|
|
90
|
+
transcribeStyle: false,
|
|
91
|
+
locales: false,
|
|
92
|
+
diarization: false,
|
|
93
|
+
phraseList: false
|
|
94
|
+
} },
|
|
95
|
+
requestConfig: { transcription: { api: "mai" } }
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
function getAzureModelEntry(modelId) {
|
|
99
|
+
const id = modelId.toLowerCase();
|
|
100
|
+
return Object.prototype.hasOwnProperty.call(azureModelCatalog, id) ? azureModelCatalog[id] : void 0;
|
|
101
|
+
}
|
|
102
|
+
//#endregion
|
|
6
103
|
//#region src/azure-mai-image-model-options.ts
|
|
7
104
|
const azureMaiImageModelOptionsShape = () => ({
|
|
8
105
|
/**
|
|
@@ -25,15 +122,8 @@ const azureImageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
|
25
122
|
api: z.enum(["openai", "mai"]).optional(),
|
|
26
123
|
...azureMaiImageModelOptionsShape()
|
|
27
124
|
})));
|
|
28
|
-
const maiImageModels = /* @__PURE__ */ new Set([
|
|
29
|
-
"mai-image-2.5",
|
|
30
|
-
"mai-image-2.5-flash",
|
|
31
|
-
"mai-image-2.5-pro",
|
|
32
|
-
"mai-image-2.6",
|
|
33
|
-
"mai-image-2.6-flash"
|
|
34
|
-
]);
|
|
35
125
|
function isMAIImageModel(modelId) {
|
|
36
|
-
return
|
|
126
|
+
return getAzureModelEntry(modelId)?.requestConfig?.image?.api === "mai";
|
|
37
127
|
}
|
|
38
128
|
//#endregion
|
|
39
129
|
//#region src/azure-mai-image-model.ts
|
|
@@ -458,16 +548,11 @@ const azureSpeechModelOptions = lazySchema(() => zodSchema(z.strictObject({
|
|
|
458
548
|
* API to use. Defaults to Speech for MAI-Voice models, OpenAI otherwise.
|
|
459
549
|
*/
|
|
460
550
|
api: z.enum(["openai", "speech"]).optional(),
|
|
551
|
+
...openaiSpeechModelOptionsShape(),
|
|
461
552
|
...azureSpeechSpeechModelOptionsShape()
|
|
462
553
|
})));
|
|
463
|
-
const maiVoiceModels = /* @__PURE__ */ new Map([
|
|
464
|
-
["mai-voice-2.1-flash", "MAI-Voice-2.1-Flash"],
|
|
465
|
-
["mai-voice-2.1", "MAI-Voice-2.1"],
|
|
466
|
-
["mai-voice-2-flash", "MAI-Voice-2-Flash"],
|
|
467
|
-
["mai-voice-2", "MAI-Voice-2"]
|
|
468
|
-
]);
|
|
469
554
|
function getMAIVoiceModel(modelId) {
|
|
470
|
-
return
|
|
555
|
+
return getAzureModelEntry(modelId)?.requestConfig?.speech?.voiceModel;
|
|
471
556
|
}
|
|
472
557
|
//#endregion
|
|
473
558
|
//#region src/azure-speech-speech-model.ts
|
|
@@ -689,21 +774,19 @@ const azureTranscriptionModelOptions = lazySchema(() => zodSchema(z.strictObject
|
|
|
689
774
|
"speech",
|
|
690
775
|
"mai"
|
|
691
776
|
]).optional(),
|
|
777
|
+
...openAITranscriptionModelOptionsShape(),
|
|
692
778
|
...azureSpeechTranscriptionModelOptionsShape(),
|
|
693
779
|
...azureMaiTranscriptionModelOptionsShape()
|
|
694
780
|
})));
|
|
695
|
-
const maiTranscribeModels = /* @__PURE__ */ new Map([["mai-transcribe-2", {
|
|
696
|
-
name: "MAI-Transcribe-2",
|
|
697
|
-
supportsTimestamps: true
|
|
698
|
-
}], ["mai-transcribe-1.5", {
|
|
699
|
-
name: "MAI-Transcribe-1.5",
|
|
700
|
-
supportsTimestamps: false
|
|
701
|
-
}]]);
|
|
702
781
|
function getMAITranscribeModel(modelId) {
|
|
703
|
-
|
|
782
|
+
const config = getAzureModelEntry(modelId)?.requestConfig?.transcription;
|
|
783
|
+
return config?.api === "speech" ? {
|
|
784
|
+
name: config.name,
|
|
785
|
+
supportsTimestamps: config.supportsTimestamps
|
|
786
|
+
} : void 0;
|
|
704
787
|
}
|
|
705
788
|
function isMAITranscribeStreaming(modelId) {
|
|
706
|
-
return modelId
|
|
789
|
+
return getAzureModelEntry(modelId)?.requestConfig?.transcription?.api === "mai";
|
|
707
790
|
}
|
|
708
791
|
//#endregion
|
|
709
792
|
//#region src/azure-speech-transcription-model.ts
|
|
@@ -812,7 +895,7 @@ const responseSchema = lazySchema(() => zodSchema(z.object({
|
|
|
812
895
|
})));
|
|
813
896
|
//#endregion
|
|
814
897
|
//#region src/version.ts
|
|
815
|
-
const VERSION = "4.0.
|
|
898
|
+
const VERSION = "4.0.119";
|
|
816
899
|
//#endregion
|
|
817
900
|
//#region src/azure-openai-provider.ts
|
|
818
901
|
function getAzureOpenAIBaseURLInfo(baseURL) {
|
|
@@ -1011,41 +1094,42 @@ var AzureTranscriptionModel = class {
|
|
|
1011
1094
|
return createAzure(options.config).transcription(options.modelId);
|
|
1012
1095
|
}
|
|
1013
1096
|
async doGenerate(options) {
|
|
1014
|
-
const { api, speechOptions, maiOptions } = await this.getOptions(options.providerOptions);
|
|
1097
|
+
const { api, speechOptions, maiOptions, openaiOptions } = await this.getOptions(options.providerOptions);
|
|
1015
1098
|
if (api === "mai") return this.mai.doGenerate();
|
|
1016
1099
|
if (api === "speech") {
|
|
1017
1100
|
const result = await this.speech.doGenerate(options, speechOptions);
|
|
1018
1101
|
return {
|
|
1019
1102
|
...result,
|
|
1020
|
-
warnings: [
|
|
1103
|
+
warnings: [
|
|
1104
|
+
...result.warnings,
|
|
1105
|
+
...maiOnlyWarnings(maiOptions),
|
|
1106
|
+
...openaiTranscriptionOnlyWarnings(openaiOptions)
|
|
1107
|
+
]
|
|
1021
1108
|
};
|
|
1022
1109
|
}
|
|
1023
|
-
const result = await this.openai.doGenerate(options);
|
|
1110
|
+
const result = await this.openai.doGenerate(withAzureOptionsForOpenAI(options, openaiOptions));
|
|
1024
1111
|
return {
|
|
1025
1112
|
...result,
|
|
1026
|
-
warnings: [
|
|
1027
|
-
...result.warnings,
|
|
1028
|
-
...speechOnlyWarnings(speechOptions),
|
|
1029
|
-
...maiOnlyWarnings(maiOptions)
|
|
1030
|
-
]
|
|
1113
|
+
warnings: [...result.warnings, ...speechOnlyWarnings(speechOptions)]
|
|
1031
1114
|
};
|
|
1032
1115
|
}
|
|
1033
1116
|
async doStream(options) {
|
|
1034
|
-
const { api, speechOptions, maiOptions } = await this.getOptions(options.providerOptions);
|
|
1117
|
+
const { api, speechOptions, maiOptions, openaiOptions } = await this.getOptions(options.providerOptions);
|
|
1035
1118
|
if (api === "speech") throw new UnsupportedFunctionalityError({ functionality: "streaming transcription with the Azure Speech API" });
|
|
1036
|
-
if (api === "mai") return this.mai.doStream(options, maiOptions, speechOnlyWarnings(speechOptions));
|
|
1037
|
-
return this.openai.doStream(options);
|
|
1119
|
+
if (api === "mai") return this.mai.doStream(options, maiOptions, [...speechOnlyWarnings(speechOptions), ...openaiTranscriptionOnlyWarnings(openaiOptions)]);
|
|
1120
|
+
return this.openai.doStream(withAzureOptionsForOpenAI(options, openaiOptions));
|
|
1038
1121
|
}
|
|
1039
1122
|
async getOptions(providerOptions) {
|
|
1040
|
-
const { api, language, ...
|
|
1123
|
+
const { api, language, ...options } = await parseProviderOptions({
|
|
1041
1124
|
provider: "azure",
|
|
1042
1125
|
providerOptions,
|
|
1043
1126
|
schema: azureTranscriptionModelOptions
|
|
1044
1127
|
}) ?? {};
|
|
1045
1128
|
return {
|
|
1046
1129
|
api: api ?? (isMAITranscribeStreaming(this.modelId) ? "mai" : getMAITranscribeModel(this.modelId) ? "speech" : "openai"),
|
|
1047
|
-
speechOptions,
|
|
1048
|
-
maiOptions: language != null ? { language } : {}
|
|
1130
|
+
speechOptions: pickKeys(options, azureSpeechTranscriptionModelOptionsShape()),
|
|
1131
|
+
maiOptions: language != null ? { language } : {},
|
|
1132
|
+
openaiOptions: pickAzureOptions(providerOptions, openAITranscriptionModelOptionsShape())
|
|
1049
1133
|
};
|
|
1050
1134
|
}
|
|
1051
1135
|
};
|
|
@@ -1068,13 +1152,21 @@ var AzureSpeechModel = class {
|
|
|
1068
1152
|
return createAzure(options.config).speech(options.modelId);
|
|
1069
1153
|
}
|
|
1070
1154
|
async doGenerate(options) {
|
|
1071
|
-
const { api, ...
|
|
1155
|
+
const { api, ...parsedOptions } = await parseProviderOptions({
|
|
1072
1156
|
provider: "azure",
|
|
1073
1157
|
providerOptions: options.providerOptions,
|
|
1074
1158
|
schema: azureSpeechModelOptions
|
|
1075
1159
|
}) ?? {};
|
|
1076
|
-
|
|
1077
|
-
const
|
|
1160
|
+
const speechOptions = pickKeys(parsedOptions, azureSpeechSpeechModelOptionsShape());
|
|
1161
|
+
const openaiOptions = pickAzureOptions(options.providerOptions, openaiSpeechModelOptionsShape());
|
|
1162
|
+
if ((api ?? (getMAIVoiceModel(this.modelId) ? "speech" : "openai")) === "speech") {
|
|
1163
|
+
const result = await this.speech.doGenerate(options, speechOptions);
|
|
1164
|
+
return {
|
|
1165
|
+
...result,
|
|
1166
|
+
warnings: [...result.warnings, ...unsupportedOptionWarnings(openaiOptions, "This option requires the OpenAI speech API.")]
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
const result = await this.openai.doGenerate(withAzureOptionsForOpenAI(options, openaiOptions));
|
|
1078
1170
|
return {
|
|
1079
1171
|
...result,
|
|
1080
1172
|
warnings: [...result.warnings, ...speechOnlyWarnings(speechOptions)]
|
|
@@ -1118,13 +1210,46 @@ var AzureImageModel = class {
|
|
|
1118
1210
|
schema: azureImageModelOptions
|
|
1119
1211
|
}) ?? {};
|
|
1120
1212
|
if ((api ?? (isMAIImageModel(this.modelId) ? "mai" : "openai")) === "mai") return this.mai.doGenerate(options, maiOptions);
|
|
1121
|
-
const result = await this.openai.doGenerate(options);
|
|
1213
|
+
const result = await this.openai.doGenerate(withAzureOptionsForOpenAI(options, pickAzureOptions(options.providerOptions, options.files != null ? openaiImageModelEditOptionsShape() : openaiImageModelGenerationOptionsShape())));
|
|
1122
1214
|
return {
|
|
1123
1215
|
...result,
|
|
1124
1216
|
warnings: [...result.warnings, ...unsupportedOptionWarnings(maiOptions, "This option requires the MAI image API.")]
|
|
1125
1217
|
};
|
|
1126
1218
|
}
|
|
1127
1219
|
};
|
|
1220
|
+
/**
|
|
1221
|
+
* Picks the options that the given schema shape accepts from the raw `azure`
|
|
1222
|
+
* provider options. Raw values are used so schema defaults are not injected;
|
|
1223
|
+
* the OpenAI model validates them again.
|
|
1224
|
+
*/
|
|
1225
|
+
function pickAzureOptions(providerOptions, shape) {
|
|
1226
|
+
return pickKeys(providerOptions?.azure ?? {}, shape);
|
|
1227
|
+
}
|
|
1228
|
+
function pickKeys(options, shape) {
|
|
1229
|
+
return Object.fromEntries(Object.entries(options).filter(([key, value]) => Object.hasOwn(shape, key) && value !== void 0));
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Azure OpenAI deployments accept their OpenAI API options under `azure` as
|
|
1233
|
+
* well as `openai`. Both are merged into `openai` for the OpenAI model; `azure`
|
|
1234
|
+
* wins, like it does for Azure chat and completion models.
|
|
1235
|
+
*/
|
|
1236
|
+
function withAzureOptionsForOpenAI(options, azureOptions) {
|
|
1237
|
+
if (Object.keys(azureOptions).length === 0) return options;
|
|
1238
|
+
return {
|
|
1239
|
+
...options,
|
|
1240
|
+
providerOptions: {
|
|
1241
|
+
...options.providerOptions,
|
|
1242
|
+
openai: {
|
|
1243
|
+
...options.providerOptions?.openai,
|
|
1244
|
+
...azureOptions
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
}
|
|
1249
|
+
function openaiTranscriptionOnlyWarnings(options) {
|
|
1250
|
+
const { language: _language, ...openaiOnlyOptions } = options;
|
|
1251
|
+
return unsupportedOptionWarnings(openaiOnlyOptions, "This option requires the OpenAI transcription API.");
|
|
1252
|
+
}
|
|
1128
1253
|
function speechOnlyWarnings(options) {
|
|
1129
1254
|
return unsupportedOptionWarnings(options, "This option requires the Azure Speech API.");
|
|
1130
1255
|
}
|