@ai-sdk/azure 4.0.84 → 4.0.86
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 +20 -0
- package/dist/index.d.ts +176 -170
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +333 -461
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,476 +1,348 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
OpenAIChatLanguageModel,
|
|
4
|
-
OpenAICompletionLanguageModel,
|
|
5
|
-
OpenAIEmbeddingModel,
|
|
6
|
-
OpenAIImageModel,
|
|
7
|
-
OpenAIResponsesLanguageModel,
|
|
8
|
-
OpenAISpeechModel,
|
|
9
|
-
OpenAITranscriptionModel
|
|
10
|
-
} from "@ai-sdk/openai/internal";
|
|
1
|
+
import { OpenAIChatLanguageModel, OpenAICompletionLanguageModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIResponsesLanguageModel, OpenAISpeechModel, OpenAITranscriptionModel, codeInterpreter, fileSearch, imageGeneration, webSearch, webSearchPreview } from "@ai-sdk/openai/internal";
|
|
11
2
|
import { DeepSeekChatLanguageModel } from "@ai-sdk/deepseek/internal";
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
UnsupportedFunctionalityError
|
|
15
|
-
} from "@ai-sdk/provider";
|
|
16
|
-
import {
|
|
17
|
-
loadApiKey,
|
|
18
|
-
loadSetting,
|
|
19
|
-
normalizeHeaders,
|
|
20
|
-
parseProviderOptions,
|
|
21
|
-
serializeModelOptions,
|
|
22
|
-
WORKFLOW_DESERIALIZE,
|
|
23
|
-
WORKFLOW_SERIALIZE,
|
|
24
|
-
withoutTrailingSlash,
|
|
25
|
-
withUserAgentSuffix
|
|
26
|
-
} from "@ai-sdk/provider-utils";
|
|
27
|
-
|
|
28
|
-
// src/azure-openai-tools.ts
|
|
29
|
-
import {
|
|
30
|
-
codeInterpreter,
|
|
31
|
-
fileSearch,
|
|
32
|
-
imageGeneration,
|
|
33
|
-
webSearch,
|
|
34
|
-
webSearchPreview
|
|
35
|
-
} from "@ai-sdk/openai/internal";
|
|
36
|
-
var azureOpenaiTools = {
|
|
37
|
-
codeInterpreter,
|
|
38
|
-
fileSearch,
|
|
39
|
-
imageGeneration,
|
|
40
|
-
webSearch,
|
|
41
|
-
webSearchPreview
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
// src/azure-speech-transcription-model.ts
|
|
45
|
-
import {
|
|
46
|
-
combineHeaders,
|
|
47
|
-
convertBase64ToUint8Array,
|
|
48
|
-
createJsonErrorResponseHandler,
|
|
49
|
-
createJsonResponseHandler,
|
|
50
|
-
mediaTypeToExtension,
|
|
51
|
-
postFormDataToApi
|
|
52
|
-
} from "@ai-sdk/provider-utils";
|
|
53
|
-
import { z as z3 } from "zod/v4";
|
|
54
|
-
|
|
55
|
-
// src/azure-transcription-model-options.ts
|
|
56
|
-
import {
|
|
57
|
-
lazySchema as lazySchema2,
|
|
58
|
-
zodSchema as zodSchema2
|
|
59
|
-
} from "@ai-sdk/provider-utils";
|
|
60
|
-
import { z as z2 } from "zod/v4";
|
|
61
|
-
|
|
62
|
-
// src/azure-speech-transcription-model-options.ts
|
|
63
|
-
import {
|
|
64
|
-
lazySchema,
|
|
65
|
-
zodSchema
|
|
66
|
-
} from "@ai-sdk/provider-utils";
|
|
3
|
+
import { InvalidArgumentError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
|
|
4
|
+
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, createJsonErrorResponseHandler, createJsonResponseHandler, lazySchema, loadApiKey, loadSetting, mediaTypeToExtension, normalizeHeaders, parseProviderOptions, postFormDataToApi, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
67
5
|
import { z } from "zod/v4";
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
6
|
+
//#region src/azure-openai-tools.ts
|
|
7
|
+
const azureOpenaiTools = {
|
|
8
|
+
codeInterpreter,
|
|
9
|
+
fileSearch,
|
|
10
|
+
imageGeneration,
|
|
11
|
+
webSearch,
|
|
12
|
+
webSearchPreview
|
|
13
|
+
};
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/azure-speech-transcription-model-options.ts
|
|
16
|
+
const azureSpeechTranscriptionModelOptionsShape = () => ({
|
|
17
|
+
/**
|
|
18
|
+
* Timing granularity. Defaults to `segment` so that transcription results
|
|
19
|
+
* include timed segments (Azure's own default is `none`).
|
|
20
|
+
*/
|
|
21
|
+
timestamps: z.enum([
|
|
22
|
+
"word",
|
|
23
|
+
"segment",
|
|
24
|
+
"none"
|
|
25
|
+
]).optional(),
|
|
26
|
+
/**
|
|
27
|
+
* `verbatim` keeps fillers and false starts, `clean` removes them.
|
|
28
|
+
* Azure defaults to `verbatim`.
|
|
29
|
+
*/
|
|
30
|
+
transcribeStyle: z.enum(["verbatim", "clean"]).optional(),
|
|
31
|
+
/**
|
|
32
|
+
* Forces a single language, e.g. `['en']`. Omit for automatic language
|
|
33
|
+
* detection and code switching.
|
|
34
|
+
*/
|
|
35
|
+
locales: z.array(z.string()).length(1).optional(),
|
|
36
|
+
/**
|
|
37
|
+
* Speaker diarization. Speaker IDs are available in provider metadata.
|
|
38
|
+
*/
|
|
39
|
+
diarization: z.strictObject({ enabled: z.boolean() }).optional(),
|
|
40
|
+
/**
|
|
41
|
+
* Keyword biasing for names and domain terminology.
|
|
42
|
+
*/
|
|
43
|
+
phraseList: z.strictObject({ phrases: z.array(z.string()) }).optional()
|
|
92
44
|
});
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
*/
|
|
104
|
-
api: z2.enum(["openai", "speech"]).optional(),
|
|
105
|
-
...azureSpeechTranscriptionModelOptionsShape()
|
|
106
|
-
})
|
|
107
|
-
)
|
|
108
|
-
);
|
|
45
|
+
lazySchema(() => zodSchema(z.strictObject(azureSpeechTranscriptionModelOptionsShape())));
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/azure-transcription-model-options.ts
|
|
48
|
+
const azureTranscriptionModelOptions = lazySchema(() => zodSchema(z.strictObject({
|
|
49
|
+
/**
|
|
50
|
+
* API to use. Defaults to Speech for MAI-Transcribe-2, OpenAI otherwise.
|
|
51
|
+
*/
|
|
52
|
+
api: z.enum(["openai", "speech"]).optional(),
|
|
53
|
+
...azureSpeechTranscriptionModelOptionsShape()
|
|
54
|
+
})));
|
|
109
55
|
function isMAITranscribe2(modelId) {
|
|
110
|
-
|
|
56
|
+
return modelId.toLowerCase() === "mai-transcribe-2";
|
|
111
57
|
}
|
|
112
|
-
|
|
113
|
-
|
|
58
|
+
//#endregion
|
|
59
|
+
//#region src/azure-speech-transcription-model.ts
|
|
114
60
|
var AzureSpeechTranscriptionModel = class {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
text: value.combinedPhrases.map((phrase) => phrase.text).join(" "),
|
|
175
|
-
segments: phrases.flatMap(
|
|
176
|
-
(phrase) => phrase.offsetMilliseconds != null && phrase.durationMilliseconds != null ? [
|
|
177
|
-
{
|
|
178
|
-
text: phrase.text,
|
|
179
|
-
startSecond: phrase.offsetMilliseconds / 1e3,
|
|
180
|
-
endSecond: (phrase.offsetMilliseconds + phrase.durationMilliseconds) / 1e3
|
|
181
|
-
}
|
|
182
|
-
] : []
|
|
183
|
-
),
|
|
184
|
-
language: reportedLanguage,
|
|
185
|
-
durationInSeconds: value.durationMilliseconds != null ? value.durationMilliseconds / 1e3 : void 0,
|
|
186
|
-
warnings: [],
|
|
187
|
-
providerMetadata: {
|
|
188
|
-
azure: { phrases }
|
|
189
|
-
},
|
|
190
|
-
response: {
|
|
191
|
-
timestamp,
|
|
192
|
-
modelId: this.modelId,
|
|
193
|
-
headers: responseHeaders,
|
|
194
|
-
body: rawValue
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
}
|
|
61
|
+
constructor(modelId, config) {
|
|
62
|
+
this.modelId = modelId;
|
|
63
|
+
this.config = config;
|
|
64
|
+
this.specificationVersion = "v4";
|
|
65
|
+
this.provider = "azure.transcription";
|
|
66
|
+
}
|
|
67
|
+
async doGenerate(options, azureOptions = {}) {
|
|
68
|
+
const timestamp = /* @__PURE__ */ new Date();
|
|
69
|
+
const formData = new FormData();
|
|
70
|
+
formData.append("audio", new Blob([typeof options.audio === "string" ? convertBase64ToUint8Array(options.audio) : options.audio], { type: options.mediaType }), `audio.${mediaTypeToExtension(options.mediaType)}`);
|
|
71
|
+
formData.append("definition", JSON.stringify({
|
|
72
|
+
enhancedMode: {
|
|
73
|
+
enabled: true,
|
|
74
|
+
model: isMAITranscribe2(this.modelId) ? "MAI-Transcribe-2" : this.modelId,
|
|
75
|
+
modelOptions: {
|
|
76
|
+
timestamps: azureOptions.timestamps ?? "segment",
|
|
77
|
+
transcribeStyle: azureOptions.transcribeStyle
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
locales: azureOptions.locales,
|
|
81
|
+
diarization: azureOptions.diarization,
|
|
82
|
+
phraseList: azureOptions.phraseList
|
|
83
|
+
}));
|
|
84
|
+
const { value, rawValue, responseHeaders } = await postFormDataToApi({
|
|
85
|
+
url: this.config.url(),
|
|
86
|
+
headers: combineHeaders(this.config.headers(), options.headers),
|
|
87
|
+
formData,
|
|
88
|
+
abortSignal: options.abortSignal,
|
|
89
|
+
fetch: this.config.fetch,
|
|
90
|
+
failedResponseHandler: createJsonErrorResponseHandler({
|
|
91
|
+
errorSchema: z.union([z.object({ error: z.object({ message: z.string() }) }), z.object({ message: z.string() })]),
|
|
92
|
+
errorToMessage: (data) => "error" in data ? data.error.message : data.message
|
|
93
|
+
}),
|
|
94
|
+
successfulResponseHandler: createJsonResponseHandler(responseSchema)
|
|
95
|
+
});
|
|
96
|
+
const phrases = value.phrases ?? [];
|
|
97
|
+
const languages = new Set(phrases.flatMap((phrase) => phrase.locale ? [phrase.locale.split("-")[0].toLowerCase()] : []));
|
|
98
|
+
const [language] = languages;
|
|
99
|
+
const reportedLanguage = languages.size === 1 && /^[a-z]{2}$/.test(language) ? language : void 0;
|
|
100
|
+
return {
|
|
101
|
+
text: value.combinedPhrases.map((phrase) => phrase.text).join(" "),
|
|
102
|
+
segments: phrases.flatMap((phrase) => phrase.offsetMilliseconds != null && phrase.durationMilliseconds != null ? [{
|
|
103
|
+
text: phrase.text,
|
|
104
|
+
startSecond: phrase.offsetMilliseconds / 1e3,
|
|
105
|
+
endSecond: (phrase.offsetMilliseconds + phrase.durationMilliseconds) / 1e3
|
|
106
|
+
}] : []),
|
|
107
|
+
language: reportedLanguage,
|
|
108
|
+
durationInSeconds: value.durationMilliseconds != null ? value.durationMilliseconds / 1e3 : void 0,
|
|
109
|
+
warnings: [],
|
|
110
|
+
providerMetadata: { azure: { phrases } },
|
|
111
|
+
response: {
|
|
112
|
+
timestamp,
|
|
113
|
+
modelId: this.modelId,
|
|
114
|
+
headers: responseHeaders,
|
|
115
|
+
body: rawValue
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
198
119
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
})
|
|
216
|
-
).nullish()
|
|
217
|
-
})
|
|
218
|
-
).nullish()
|
|
120
|
+
const responseSchema = z.object({
|
|
121
|
+
combinedPhrases: z.array(z.object({ text: z.string() })),
|
|
122
|
+
durationMilliseconds: z.number().nullish(),
|
|
123
|
+
phrases: z.array(z.object({
|
|
124
|
+
text: z.string(),
|
|
125
|
+
offsetMilliseconds: z.number().nullish(),
|
|
126
|
+
durationMilliseconds: z.number().nullish(),
|
|
127
|
+
locale: z.string().nullish(),
|
|
128
|
+
speaker: z.number().nullish(),
|
|
129
|
+
confidence: z.number().nullish(),
|
|
130
|
+
words: z.array(z.object({
|
|
131
|
+
text: z.string(),
|
|
132
|
+
offsetMilliseconds: z.number().nullish(),
|
|
133
|
+
durationMilliseconds: z.number().nullish()
|
|
134
|
+
})).nullish()
|
|
135
|
+
})).nullish()
|
|
219
136
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/version.ts
|
|
139
|
+
const VERSION = "4.0.86";
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/azure-openai-provider.ts
|
|
225
142
|
function getAzureOpenAIBaseURLInfo(baseURL) {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
isVersioned: isAzureOpenAI && pathname.toLowerCase().endsWith("/openai/v1")
|
|
241
|
-
};
|
|
143
|
+
if (baseURL == null) return {
|
|
144
|
+
isAzureOpenAI: true,
|
|
145
|
+
isFoundryProject: false,
|
|
146
|
+
isVersioned: false
|
|
147
|
+
};
|
|
148
|
+
const url = new URL(baseURL);
|
|
149
|
+
const hostname = url.hostname;
|
|
150
|
+
const isAzureOpenAI = hostname.endsWith(".openai.azure.com") || hostname.endsWith(".services.ai.azure.com") || hostname.endsWith(".cognitiveservices.azure.com");
|
|
151
|
+
const pathname = url.pathname.replace(/\/+$/, "");
|
|
152
|
+
return {
|
|
153
|
+
isAzureOpenAI,
|
|
154
|
+
isFoundryProject: hostname.endsWith(".services.ai.azure.com") && pathname.startsWith("/api/projects/"),
|
|
155
|
+
isVersioned: isAzureOpenAI && pathname.toLowerCase().endsWith("/openai/v1")
|
|
156
|
+
};
|
|
242
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Create an Azure OpenAI provider instance.
|
|
160
|
+
*/
|
|
243
161
|
function createAzure(options = {}) {
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
url: () => `${withoutTrailingSlash(options.speechBaseURL) ?? `https://${getResourceName()}.cognitiveservices.azure.com`}/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
|
|
375
|
-
headers: () => getHeaders("speech"),
|
|
376
|
-
fetch
|
|
377
|
-
})
|
|
378
|
-
);
|
|
379
|
-
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
380
|
-
provider: "azure.speech",
|
|
381
|
-
url,
|
|
382
|
-
headers: getHeaders,
|
|
383
|
-
fetch
|
|
384
|
-
});
|
|
385
|
-
const provider = function(deploymentId) {
|
|
386
|
-
if (new.target) {
|
|
387
|
-
throw new Error(
|
|
388
|
-
"The Azure OpenAI model function cannot be called with the new keyword."
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
return createResponsesModel(deploymentId);
|
|
392
|
-
};
|
|
393
|
-
provider.specificationVersion = "v4";
|
|
394
|
-
provider.languageModel = createResponsesModel;
|
|
395
|
-
provider.chat = createChatModel;
|
|
396
|
-
provider.deepseek = createDeepSeekModel;
|
|
397
|
-
provider.completion = createCompletionModel;
|
|
398
|
-
provider.embedding = createEmbeddingModel;
|
|
399
|
-
provider.embeddingModel = createEmbeddingModel;
|
|
400
|
-
provider.textEmbedding = createEmbeddingModel;
|
|
401
|
-
provider.textEmbeddingModel = createEmbeddingModel;
|
|
402
|
-
provider.image = createImageModel;
|
|
403
|
-
provider.imageModel = createImageModel;
|
|
404
|
-
provider.responses = createResponsesModel;
|
|
405
|
-
provider.transcription = createTranscriptionModel;
|
|
406
|
-
provider.transcriptionModel = createTranscriptionModel;
|
|
407
|
-
provider.speech = createSpeechModel;
|
|
408
|
-
provider.tools = azureOpenaiTools;
|
|
409
|
-
return provider;
|
|
162
|
+
const tokenProvider = options.tokenProvider;
|
|
163
|
+
if (options.apiKey && tokenProvider) throw new InvalidArgumentError({
|
|
164
|
+
argument: "apiKey/tokenProvider",
|
|
165
|
+
message: "Both apiKey and tokenProvider were provided. Please use only one authentication method."
|
|
166
|
+
});
|
|
167
|
+
const getHeaders = (api = "openai") => {
|
|
168
|
+
const authHeaders = tokenProvider ? {} : { [api === "speech" ? "Ocp-Apim-Subscription-Key" : "api-key"]: loadApiKey({
|
|
169
|
+
apiKey: options.apiKey,
|
|
170
|
+
environmentVariableName: "AZURE_API_KEY",
|
|
171
|
+
description: api === "speech" ? "Azure Speech" : "Azure OpenAI"
|
|
172
|
+
}) };
|
|
173
|
+
return withUserAgentSuffix({
|
|
174
|
+
...authHeaders,
|
|
175
|
+
...options.headers
|
|
176
|
+
}, `ai-sdk-azure/${VERSION}`);
|
|
177
|
+
};
|
|
178
|
+
const fetch = tokenProvider ? async (input, init) => {
|
|
179
|
+
const headers = normalizeHeaders(init?.headers);
|
|
180
|
+
if (headers.authorization == null) headers.authorization = `Bearer ${await tokenProvider()}`;
|
|
181
|
+
return (options.fetch ?? globalThis.fetch)(input, {
|
|
182
|
+
...init,
|
|
183
|
+
headers
|
|
184
|
+
});
|
|
185
|
+
} : options.fetch;
|
|
186
|
+
const getResourceName = () => {
|
|
187
|
+
const resourceName = loadSetting({
|
|
188
|
+
settingValue: options.resourceName,
|
|
189
|
+
settingName: "resourceName",
|
|
190
|
+
environmentVariableName: "AZURE_RESOURCE_NAME",
|
|
191
|
+
description: "Azure OpenAI resource name"
|
|
192
|
+
});
|
|
193
|
+
if (!/^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/i.test(resourceName)) throw new InvalidArgumentError({
|
|
194
|
+
argument: "resourceName",
|
|
195
|
+
message: "Invalid Azure resource name. Expected a single DNS label (letters, digits, and hyphens). Use `baseURL` for custom endpoints."
|
|
196
|
+
});
|
|
197
|
+
return resourceName;
|
|
198
|
+
};
|
|
199
|
+
const apiVersion = options.apiVersion ?? "v1";
|
|
200
|
+
const { isAzureOpenAI, isFoundryProject, isVersioned: isAzureOpenAIVersioned } = getAzureOpenAIBaseURLInfo(options.baseURL);
|
|
201
|
+
const url = ({ path, modelId }) => {
|
|
202
|
+
const baseUrlPrefix = withoutTrailingSlash(options.baseURL ?? `https://${getResourceName()}.openai.azure.com/openai`);
|
|
203
|
+
let fullUrl;
|
|
204
|
+
if (options.useDeploymentBasedUrls) fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path}`);
|
|
205
|
+
else if (!isAzureOpenAI || isAzureOpenAIVersioned) fullUrl = new URL(`${baseUrlPrefix}${path}`);
|
|
206
|
+
else fullUrl = new URL(`${baseUrlPrefix}/v1${path}`);
|
|
207
|
+
if (options.useDeploymentBasedUrls || isAzureOpenAI && !isAzureOpenAIVersioned && !isFoundryProject) fullUrl.searchParams.set("api-version", apiVersion);
|
|
208
|
+
return fullUrl.toString();
|
|
209
|
+
};
|
|
210
|
+
const createChatModel = (deploymentName) => new OpenAIChatLanguageModel(deploymentName, {
|
|
211
|
+
provider: "azure.chat",
|
|
212
|
+
url,
|
|
213
|
+
headers: getHeaders,
|
|
214
|
+
fetch
|
|
215
|
+
});
|
|
216
|
+
const createDeepSeekModel = (deploymentName) => new DeepSeekChatLanguageModel(deploymentName, {
|
|
217
|
+
provider: "azure.deepseek",
|
|
218
|
+
url,
|
|
219
|
+
headers: getHeaders,
|
|
220
|
+
fetch,
|
|
221
|
+
supportsPenaltySampling: true,
|
|
222
|
+
supportsThinking: false,
|
|
223
|
+
supportsStructuredOutputs: true
|
|
224
|
+
});
|
|
225
|
+
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
226
|
+
provider: "azure.completion",
|
|
227
|
+
url,
|
|
228
|
+
headers: getHeaders,
|
|
229
|
+
fetch
|
|
230
|
+
});
|
|
231
|
+
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
232
|
+
provider: "azure.embeddings",
|
|
233
|
+
headers: getHeaders,
|
|
234
|
+
url,
|
|
235
|
+
fetch
|
|
236
|
+
});
|
|
237
|
+
const createResponsesModel = (modelId) => new OpenAIResponsesLanguageModel(modelId, {
|
|
238
|
+
provider: "azure.responses",
|
|
239
|
+
url,
|
|
240
|
+
headers: getHeaders,
|
|
241
|
+
fetch,
|
|
242
|
+
explicitMessageItemType: isFoundryProject,
|
|
243
|
+
fileIdPrefixes: ["assistant-"]
|
|
244
|
+
});
|
|
245
|
+
const createImageModel = (modelId) => new OpenAIImageModel(modelId, {
|
|
246
|
+
provider: "azure.image",
|
|
247
|
+
url,
|
|
248
|
+
headers: getHeaders,
|
|
249
|
+
fetch,
|
|
250
|
+
imageInputCapabilities: {
|
|
251
|
+
supportsFileInputs: void 0,
|
|
252
|
+
supportsMaskInputs: void 0
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
const createTranscriptionModel = (modelId) => new AzureTranscriptionModel(modelId, options, new OpenAITranscriptionModel(modelId, {
|
|
256
|
+
provider: "azure.transcription",
|
|
257
|
+
url,
|
|
258
|
+
headers: getHeaders,
|
|
259
|
+
fetch
|
|
260
|
+
}), new AzureSpeechTranscriptionModel(modelId, {
|
|
261
|
+
url: () => `${withoutTrailingSlash(options.speechBaseURL) ?? `https://${getResourceName()}.cognitiveservices.azure.com`}/speechtotext/transcriptions:transcribe?api-version=2025-10-15`,
|
|
262
|
+
headers: () => getHeaders("speech"),
|
|
263
|
+
fetch
|
|
264
|
+
}));
|
|
265
|
+
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
266
|
+
provider: "azure.speech",
|
|
267
|
+
url,
|
|
268
|
+
headers: getHeaders,
|
|
269
|
+
fetch
|
|
270
|
+
});
|
|
271
|
+
const provider = function(deploymentId) {
|
|
272
|
+
if (new.target) throw new Error("The Azure OpenAI model function cannot be called with the new keyword.");
|
|
273
|
+
return createResponsesModel(deploymentId);
|
|
274
|
+
};
|
|
275
|
+
provider.specificationVersion = "v4";
|
|
276
|
+
provider.languageModel = createResponsesModel;
|
|
277
|
+
provider.chat = createChatModel;
|
|
278
|
+
provider.deepseek = createDeepSeekModel;
|
|
279
|
+
provider.completion = createCompletionModel;
|
|
280
|
+
provider.embedding = createEmbeddingModel;
|
|
281
|
+
provider.embeddingModel = createEmbeddingModel;
|
|
282
|
+
provider.textEmbedding = createEmbeddingModel;
|
|
283
|
+
provider.textEmbeddingModel = createEmbeddingModel;
|
|
284
|
+
provider.image = createImageModel;
|
|
285
|
+
provider.imageModel = createImageModel;
|
|
286
|
+
provider.responses = createResponsesModel;
|
|
287
|
+
provider.transcription = createTranscriptionModel;
|
|
288
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
289
|
+
provider.speech = createSpeechModel;
|
|
290
|
+
provider.tools = azureOpenaiTools;
|
|
291
|
+
return provider;
|
|
410
292
|
}
|
|
411
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Default Azure OpenAI provider instance.
|
|
295
|
+
*/
|
|
296
|
+
const azure = createAzure();
|
|
412
297
|
var AzureTranscriptionModel = class {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
async getOptions(providerOptions) {
|
|
460
|
-
const options = await parseProviderOptions({
|
|
461
|
-
provider: "azure",
|
|
462
|
-
providerOptions,
|
|
463
|
-
schema: azureTranscriptionModelOptions
|
|
464
|
-
});
|
|
465
|
-
return {
|
|
466
|
-
...options,
|
|
467
|
-
api: options?.api ?? (isMAITranscribe2(this.modelId) ? "speech" : "openai")
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
export {
|
|
472
|
-
VERSION,
|
|
473
|
-
azure,
|
|
474
|
-
createAzure
|
|
298
|
+
constructor(modelId, config, openai, speech) {
|
|
299
|
+
this.modelId = modelId;
|
|
300
|
+
this.config = config;
|
|
301
|
+
this.openai = openai;
|
|
302
|
+
this.speech = speech;
|
|
303
|
+
this.specificationVersion = "v4";
|
|
304
|
+
this.provider = "azure.transcription";
|
|
305
|
+
}
|
|
306
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
307
|
+
return serializeModelOptions({
|
|
308
|
+
modelId: model.modelId,
|
|
309
|
+
config: model.config
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
313
|
+
return createAzure(options.config).transcription(options.modelId);
|
|
314
|
+
}
|
|
315
|
+
async doGenerate(options) {
|
|
316
|
+
const { api, ...speechOptions } = await this.getOptions(options.providerOptions);
|
|
317
|
+
if (api === "speech") return this.speech.doGenerate(options, speechOptions);
|
|
318
|
+
const result = await this.openai.doGenerate(options);
|
|
319
|
+
return {
|
|
320
|
+
...result,
|
|
321
|
+
warnings: [...result.warnings, ...Object.keys(speechOptions).map((key) => ({
|
|
322
|
+
type: "unsupported",
|
|
323
|
+
feature: `providerOptions.azure.${key}`,
|
|
324
|
+
details: "This option requires the Azure Speech API."
|
|
325
|
+
}))]
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
async doStream(options) {
|
|
329
|
+
const { api } = await this.getOptions(options.providerOptions);
|
|
330
|
+
if (api === "speech") throw new UnsupportedFunctionalityError({ functionality: "streaming transcription with the Azure Speech API" });
|
|
331
|
+
return this.openai.doStream(options);
|
|
332
|
+
}
|
|
333
|
+
async getOptions(providerOptions) {
|
|
334
|
+
const options = await parseProviderOptions({
|
|
335
|
+
provider: "azure",
|
|
336
|
+
providerOptions,
|
|
337
|
+
schema: azureTranscriptionModelOptions
|
|
338
|
+
});
|
|
339
|
+
return {
|
|
340
|
+
...options,
|
|
341
|
+
api: options?.api ?? (isMAITranscribe2(this.modelId) ? "speech" : "openai")
|
|
342
|
+
};
|
|
343
|
+
}
|
|
475
344
|
};
|
|
345
|
+
//#endregion
|
|
346
|
+
export { VERSION, azure, createAzure };
|
|
347
|
+
|
|
476
348
|
//# sourceMappingURL=index.js.map
|