@ai-sdk/azure 4.0.90 → 4.0.92
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 +19 -0
- package/dist/index.d.ts +15 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +247 -6
- package/dist/index.js.map +1 -1
- package/docs/04-azure.mdx +64 -2
- package/package.json +6 -5
- package/src/azure-image-model-options.ts +34 -0
- package/src/azure-mai-image-model-options.ts +27 -0
- package/src/azure-mai-image-model.ts +261 -0
- package/src/azure-openai-provider.ts +104 -21
- package/src/azure-speech-speech-model.ts +3 -2
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/azure
|
|
2
2
|
|
|
3
|
+
## 4.0.92
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 35347c3: feat(azure): support MAI-Image models through the MAI image API
|
|
8
|
+
|
|
9
|
+
## 4.0.91
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 9210b70: fix(azure): report the Azure Speech voice-reset 502 as a non-retryable 400. An unknown voice or unsupported style on MAI-Voice-2.1 makes Azure Speech reset the connection with an Envoy `protocol error` 502; since this is a client input error, the resulting `APICallError` now carries `statusCode: 400` so HTTP clients and gateways do not retry it as a server error.
|
|
14
|
+
- Updated dependencies [2959d35]
|
|
15
|
+
- Updated dependencies [5b8e63b]
|
|
16
|
+
- Updated dependencies [59116e6]
|
|
17
|
+
- @ai-sdk/provider@4.0.22
|
|
18
|
+
- @ai-sdk/provider-utils@5.0.54
|
|
19
|
+
- @ai-sdk/openai@4.0.84
|
|
20
|
+
- @ai-sdk/deepseek@3.0.59
|
|
21
|
+
|
|
3
22
|
## 4.0.90
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -52,11 +52,12 @@ interface AzureOpenAIProvider extends ProviderV4 {
|
|
|
52
52
|
*/
|
|
53
53
|
textEmbeddingModel(deploymentId: string): EmbeddingModelV4;
|
|
54
54
|
/**
|
|
55
|
-
* Creates an Azure
|
|
55
|
+
* Creates an Azure image model. MAI-Image models use the MAI image API by
|
|
56
|
+
* default; other IDs use OpenAI. Override with providerOptions.azure.api.
|
|
56
57
|
*/
|
|
57
58
|
image(deploymentId: string): ImageModelV4;
|
|
58
59
|
/**
|
|
59
|
-
* Creates an Azure
|
|
60
|
+
* Creates an Azure image model. Alias of `image`.
|
|
60
61
|
*/
|
|
61
62
|
imageModel(deploymentId: string): ImageModelV4;
|
|
62
63
|
/**
|
|
@@ -139,8 +140,8 @@ interface AzureOpenAIProviderSettings {
|
|
|
139
140
|
*/
|
|
140
141
|
speechBaseURL?: string;
|
|
141
142
|
/**
|
|
142
|
-
* URL prefix for MAI
|
|
143
|
-
*
|
|
143
|
+
* URL prefix for MAI APIs (MAI-Image, MAI-Transcribe-2-Streaming). Defaults
|
|
144
|
+
* to `https://{resourceName}.services.ai.azure.com/mai/v1`.
|
|
144
145
|
*/
|
|
145
146
|
maiBaseURL?: string;
|
|
146
147
|
/**
|
|
@@ -177,6 +178,14 @@ type AzureResponsesSourceDocumentProviderMetadata = {
|
|
|
177
178
|
//#region src/version.d.ts
|
|
178
179
|
export declare const VERSION: string;
|
|
179
180
|
//#endregion
|
|
181
|
+
//#region src/azure-image-model-options.d.ts
|
|
182
|
+
declare const azureImageModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
183
|
+
autoAspectRatio?: boolean | undefined;
|
|
184
|
+
webGrounding?: boolean | undefined;
|
|
185
|
+
api?: "openai" | "mai" | undefined;
|
|
186
|
+
}>;
|
|
187
|
+
type AzureImageModelOptions = InferSchema<typeof azureImageModelOptions>;
|
|
188
|
+
//#endregion
|
|
180
189
|
//#region src/azure-speech-model-options.d.ts
|
|
181
190
|
declare const azureSpeechModelOptions: import("@ai-sdk/provider-utils").LazySchema<{
|
|
182
191
|
style?: string | undefined;
|
|
@@ -197,7 +206,7 @@ declare const azureTranscriptionModelOptions: import("@ai-sdk/provider-utils").L
|
|
|
197
206
|
phraseList?: {
|
|
198
207
|
phrases: string[];
|
|
199
208
|
} | undefined;
|
|
200
|
-
api?: "openai" | "
|
|
209
|
+
api?: "openai" | "mai" | "speech" | undefined;
|
|
201
210
|
}>;
|
|
202
211
|
type AzureTranscriptionModelOptions = InferSchema<typeof azureTranscriptionModelOptions>;
|
|
203
212
|
//#endregion
|
|
@@ -225,5 +234,5 @@ export type AzureDeepSeekLanguageModelOptions = Omit<DeepSeekLanguageModelChatOp
|
|
|
225
234
|
/** @deprecated Use `AzureDeepSeekLanguageModelOptions` instead. */
|
|
226
235
|
export type AzureDeepSeekChatOptions = AzureDeepSeekLanguageModelOptions;
|
|
227
236
|
//#endregion
|
|
228
|
-
export type { AzureOpenAIProvider, AzureOpenAIProviderSettings, AzureResponsesProviderMetadata, AzureResponsesReasoningProviderMetadata, AzureResponsesSourceDocumentProviderMetadata, AzureResponsesTextProviderMetadata, AzureSpeechModelOptions, AzureTranscriptionModelOptions, AzureTranscriptionProviderMetadata, OpenAIChatLanguageModelOptions, OpenAILanguageModelChatOptions, OpenAILanguageModelResponsesOptions, OpenAIResponsesProviderOptions, OpenAIResponsesSystemMessageOptions };
|
|
237
|
+
export type { AzureImageModelOptions, AzureOpenAIProvider, AzureOpenAIProviderSettings, AzureResponsesProviderMetadata, AzureResponsesReasoningProviderMetadata, AzureResponsesSourceDocumentProviderMetadata, AzureResponsesTextProviderMetadata, AzureSpeechModelOptions, AzureTranscriptionModelOptions, AzureTranscriptionProviderMetadata, OpenAIChatLanguageModelOptions, OpenAILanguageModelChatOptions, OpenAILanguageModelResponsesOptions, OpenAIResponsesProviderOptions, OpenAIResponsesSystemMessageOptions };
|
|
229
238
|
//# sourceMappingURL=index.d.ts.map
|
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-speech-model-options.ts","../src/azure-transcription-model-options.ts","../src/azure-transcription-provider-metadata.ts","../src/index.ts"],"mappings":";;;;;;cAQa;EACX,wBAAwB;EACxB,mBAAmB;EACnB,wBAAwB;EACxB,kBAAkB;EAClB,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":";;;;;;cAQa;EACX,wBAAwB;EACxB,mBAAmB;EACnB,wBAAwB;EACxB,kBAAkB;EAClB,yBAAyB;;;;UC0CV,4BAA4B;GAC1C,uBAAuB;;;;EAKxB,cAAc,uBAAuB;;;;EAKrC,KAAK,uBAAuB;;;;EAK5B,SAAS,uBAAuB;;;;EAKhC,UAAU,uBAAuB;;;;EAKjC,WAAW,uBAAuB;;;;EAKlC,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;;;;;;EAOA,uBAAuB;;;;EAKvB,UAAU;;;;;EAMV,QAAQ;;;;;EAMR;;;;;;EAOA;;;;;;;;EASA;;;;;EAMA;;;;;;;EAQA,YAAY;;;;;wBAgCE,YACd,UAAS,8BACR;;;;qBAyQU,OAAK;;;KC/fN;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;KAGG;EACV,OAAO;;;;qBClBI;;;cCMA,yDAAsB;;;;;KAYvB,yBAAyB,mBAAmB;;;cCZ3C,0DAAuB;;;;;KAYxB,0BAA0B,mBAC7B;;;cCZI,iEAA8B;;;;;;;;;;;;;KAc/B,iCAAiC,mBACpC;;;KCxBG;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,200 @@
|
|
|
1
1
|
import { OpenAIChatLanguageModel, OpenAICompletionLanguageModel, OpenAIEmbeddingModel, OpenAIImageModel, OpenAIResponsesLanguageModel, OpenAISpeechModel, OpenAITranscriptionModel, codeInterpreter, fileSearch, imageGeneration, 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
|
-
import { WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, connectToWebSocket, convertBase64ToUint8Array, convertToBase64, createBinaryResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, extractResponseHeaders, isValidHostnamePart, lazySchema, loadApiKey, loadSetting, mediaTypeToExtension, normalizeHeaders, parseProviderOptions, postFormDataToApi, postToApi, safeParseJSON, serializeModelOptions, toWebSocketUrl, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
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, safeParseJSON, serializeModelOptions, toWebSocketUrl, waitForWebSocketBufferDrain, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
|
+
//#region src/azure-mai-image-model-options.ts
|
|
7
|
+
const azureMaiImageModelOptionsShape = () => ({
|
|
8
|
+
/**
|
|
9
|
+
* Let the model pick the output aspect ratio from the prompt and any
|
|
10
|
+
* reference images. MAI-Image-2.6 models only.
|
|
11
|
+
*/
|
|
12
|
+
autoAspectRatio: z.boolean().optional(),
|
|
13
|
+
/**
|
|
14
|
+
* Ground generation in Bing web search results. MAI-Image-2.6 models only.
|
|
15
|
+
*/
|
|
16
|
+
webGrounding: z.boolean().optional()
|
|
17
|
+
});
|
|
18
|
+
lazySchema(() => zodSchema(z.object(azureMaiImageModelOptionsShape())));
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/azure-image-model-options.ts
|
|
21
|
+
const azureImageModelOptions = lazySchema(() => zodSchema(z.object({
|
|
22
|
+
/**
|
|
23
|
+
* API to use. Defaults to MAI for MAI-Image models, OpenAI otherwise.
|
|
24
|
+
*/
|
|
25
|
+
api: z.enum(["openai", "mai"]).optional(),
|
|
26
|
+
...azureMaiImageModelOptionsShape()
|
|
27
|
+
})));
|
|
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
|
+
function isMAIImageModel(modelId) {
|
|
36
|
+
return maiImageModels.has(modelId.toLowerCase());
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/azure-mai-image-model.ts
|
|
40
|
+
const MIN_SIDE = 768;
|
|
41
|
+
const DEFAULT_PIXELS = 1048576;
|
|
42
|
+
/**
|
|
43
|
+
* MAI image generations and edits (`/mai/v1/images/*`) on Azure AI Foundry.
|
|
44
|
+
* The API returns one PNG per request and takes `width`/`height`, not `size`.
|
|
45
|
+
*/
|
|
46
|
+
var AzureMaiImageModel = class {
|
|
47
|
+
constructor(modelId, config) {
|
|
48
|
+
this.modelId = modelId;
|
|
49
|
+
this.config = config;
|
|
50
|
+
this.specificationVersion = "v4";
|
|
51
|
+
this.provider = "azure.image";
|
|
52
|
+
this.maxImagesPerCall = 1;
|
|
53
|
+
this.supportsFileInputs = true;
|
|
54
|
+
this.supportsMaskInputs = false;
|
|
55
|
+
}
|
|
56
|
+
async doGenerate({ prompt, n, size, aspectRatio, seed, files, mask, headers, abortSignal }, { autoAspectRatio, webGrounding } = {}) {
|
|
57
|
+
const currentDate = this.config._internal?.currentDate?.() ?? /* @__PURE__ */ new Date();
|
|
58
|
+
const warnings = [];
|
|
59
|
+
if (seed != null) warnings.push({
|
|
60
|
+
type: "unsupported",
|
|
61
|
+
feature: "seed"
|
|
62
|
+
});
|
|
63
|
+
if (mask != null) warnings.push({
|
|
64
|
+
type: "unsupported",
|
|
65
|
+
feature: "mask",
|
|
66
|
+
details: "MAI image edits do not support masks."
|
|
67
|
+
});
|
|
68
|
+
let dimensions = parseSize(size);
|
|
69
|
+
if (size != null && aspectRatio != null) warnings.push({
|
|
70
|
+
type: "unsupported",
|
|
71
|
+
feature: "aspectRatio",
|
|
72
|
+
details: "aspectRatio is ignored when size is set."
|
|
73
|
+
});
|
|
74
|
+
else if (aspectRatio != null) {
|
|
75
|
+
dimensions = dimensionsForAspectRatio(aspectRatio);
|
|
76
|
+
if (dimensions == null) warnings.push({
|
|
77
|
+
type: "unsupported",
|
|
78
|
+
feature: "aspectRatio",
|
|
79
|
+
details: `Invalid aspect ratio: ${aspectRatio}.`
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const fields = {
|
|
83
|
+
model: this.modelId,
|
|
84
|
+
prompt,
|
|
85
|
+
width: dimensions?.width,
|
|
86
|
+
height: dimensions?.height,
|
|
87
|
+
auto_aspect_ratio: autoAspectRatio,
|
|
88
|
+
web_grounding: webGrounding
|
|
89
|
+
};
|
|
90
|
+
const requestOptions = {
|
|
91
|
+
headers: combineHeaders(this.config.headers(), headers),
|
|
92
|
+
failedResponseHandler: maiFailedResponseHandler,
|
|
93
|
+
successfulResponseHandler: createJsonResponseHandler(maiImageResponseSchema),
|
|
94
|
+
abortSignal,
|
|
95
|
+
fetch: this.config.fetch
|
|
96
|
+
};
|
|
97
|
+
const images = files != null && files.length > 0 ? await Promise.all(files.map((file) => fileToBlob(file, abortSignal))) : void 0;
|
|
98
|
+
const responses = await Promise.all(Array.from({ length: Math.max(1, n) }, () => images != null ? postFormDataToApi({
|
|
99
|
+
...requestOptions,
|
|
100
|
+
url: this.config.url("/images/edits"),
|
|
101
|
+
formData: toFormData(fields, images)
|
|
102
|
+
}) : postJsonToApi({
|
|
103
|
+
...requestOptions,
|
|
104
|
+
url: this.config.url("/images/generations"),
|
|
105
|
+
body: fields
|
|
106
|
+
})));
|
|
107
|
+
let usage;
|
|
108
|
+
const metadata = [];
|
|
109
|
+
for (const { value: response } of responses) {
|
|
110
|
+
const textTokens = response.usage?.num_input_text_tokens ?? void 0;
|
|
111
|
+
const imageTokens = response.usage?.num_input_image_tokens ?? void 0;
|
|
112
|
+
if (response.usage != null) {
|
|
113
|
+
const inputTokens = addTokens(textTokens, imageTokens);
|
|
114
|
+
const outputTokens = response.usage.num_output_tokens ?? void 0;
|
|
115
|
+
usage = {
|
|
116
|
+
inputTokens: addTokens(usage?.inputTokens, inputTokens),
|
|
117
|
+
outputTokens: addTokens(usage?.outputTokens, outputTokens),
|
|
118
|
+
totalTokens: addTokens(usage?.totalTokens, addTokens(inputTokens, outputTokens))
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
metadata.push(...response.data.map(() => ({
|
|
122
|
+
...response.created != null ? { created: response.created } : {},
|
|
123
|
+
...response.size != null ? { size: response.size } : {},
|
|
124
|
+
...textTokens != null ? { textTokens } : {},
|
|
125
|
+
...imageTokens != null ? { imageTokens } : {}
|
|
126
|
+
})));
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
images: responses.flatMap(({ value }) => value.data.map((item) => item.b64_json)),
|
|
130
|
+
warnings,
|
|
131
|
+
response: {
|
|
132
|
+
timestamp: currentDate,
|
|
133
|
+
modelId: this.modelId,
|
|
134
|
+
headers: responses[0]?.responseHeaders
|
|
135
|
+
},
|
|
136
|
+
usage,
|
|
137
|
+
providerMetadata: { azure: { images: metadata } }
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
function addTokens(a, b) {
|
|
142
|
+
return a == null && b == null ? void 0 : (a ?? 0) + (b ?? 0);
|
|
143
|
+
}
|
|
144
|
+
function parseSize(size) {
|
|
145
|
+
if (size == null) return void 0;
|
|
146
|
+
const [width, height] = size.split("x").map(Number);
|
|
147
|
+
return {
|
|
148
|
+
width,
|
|
149
|
+
height
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function dimensionsForAspectRatio(aspectRatio) {
|
|
153
|
+
const [w, h] = aspectRatio.split(":").map(Number);
|
|
154
|
+
if (!(w > 0 && h > 0)) return void 0;
|
|
155
|
+
const ratio = w / h;
|
|
156
|
+
let width = Math.sqrt(DEFAULT_PIXELS * ratio);
|
|
157
|
+
let height = width / ratio;
|
|
158
|
+
if (Math.min(width, height) < MIN_SIDE) [width, height] = width < height ? [MIN_SIDE, MIN_SIDE / ratio] : [MIN_SIDE * ratio, MIN_SIDE];
|
|
159
|
+
const floor16 = (value) => Math.floor(value / 16 + 1e-9) * 16;
|
|
160
|
+
return {
|
|
161
|
+
width: Math.max(MIN_SIDE, floor16(width)),
|
|
162
|
+
height: Math.max(MIN_SIDE, floor16(height))
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function toFormData(fields, images) {
|
|
166
|
+
const formData = new FormData();
|
|
167
|
+
for (const [key, value] of Object.entries(fields)) if (value != null) formData.append(key, String(value));
|
|
168
|
+
images.forEach((blob, index) => {
|
|
169
|
+
const extension = blob.type === "image/jpeg" ? "jpg" : "png";
|
|
170
|
+
formData.append("image", blob, `image-${index + 1}.${extension}`);
|
|
171
|
+
});
|
|
172
|
+
return formData;
|
|
173
|
+
}
|
|
174
|
+
async function fileToBlob(file, abortSignal) {
|
|
175
|
+
if (file.type === "url") return downloadBlob(file.url, { abortSignal });
|
|
176
|
+
const data = file.data instanceof Uint8Array ? file.data : convertBase64ToUint8Array(file.data);
|
|
177
|
+
return new Blob([data], { type: file.mediaType });
|
|
178
|
+
}
|
|
179
|
+
const maiErrorSchema = z.object({ error: z.object({
|
|
180
|
+
code: z.union([z.string(), z.number()]).nullish(),
|
|
181
|
+
message: z.string()
|
|
182
|
+
}) });
|
|
183
|
+
const maiFailedResponseHandler = createJsonErrorResponseHandler({
|
|
184
|
+
errorSchema: maiErrorSchema,
|
|
185
|
+
errorToMessage: (data) => data.error.message
|
|
186
|
+
});
|
|
187
|
+
const maiImageResponseSchema = z.object({
|
|
188
|
+
created: z.number().nullish(),
|
|
189
|
+
size: z.string().nullish(),
|
|
190
|
+
usage: z.object({
|
|
191
|
+
num_input_text_tokens: z.number().nullish(),
|
|
192
|
+
num_input_image_tokens: z.number().nullish(),
|
|
193
|
+
num_output_tokens: z.number().nullish()
|
|
194
|
+
}).nullish(),
|
|
195
|
+
data: z.array(z.object({ b64_json: z.string() }))
|
|
196
|
+
});
|
|
197
|
+
//#endregion
|
|
6
198
|
//#region src/azure-mai-transcription-model.ts
|
|
7
199
|
const SUPPORTED_SAMPLE_RATES = [16e3, 24e3];
|
|
8
200
|
const DEFAULT_SAMPLE_RATE = 24e3;
|
|
@@ -435,7 +627,7 @@ const failedResponseHandler = async ({ response, url, requestBodyValues }) => {
|
|
|
435
627
|
message,
|
|
436
628
|
url,
|
|
437
629
|
requestBodyValues,
|
|
438
|
-
statusCode: response.status,
|
|
630
|
+
statusCode: isVoiceReset ? 400 : response.status,
|
|
439
631
|
responseHeaders,
|
|
440
632
|
responseBody,
|
|
441
633
|
isRetryable: isVoiceReset ? false : void 0
|
|
@@ -593,7 +785,7 @@ const responseSchema = z.object({
|
|
|
593
785
|
});
|
|
594
786
|
//#endregion
|
|
595
787
|
//#region src/version.ts
|
|
596
|
-
const VERSION = "4.0.
|
|
788
|
+
const VERSION = "4.0.92";
|
|
597
789
|
//#endregion
|
|
598
790
|
//#region src/azure-openai-provider.ts
|
|
599
791
|
function getAzureOpenAIBaseURLInfo(baseURL) {
|
|
@@ -699,7 +891,8 @@ function createAzure(options = {}) {
|
|
|
699
891
|
explicitMessageItemType: isFoundryProject,
|
|
700
892
|
fileIdPrefixes: ["assistant-"]
|
|
701
893
|
});
|
|
702
|
-
const
|
|
894
|
+
const maiBaseURL = () => withoutTrailingSlash(options.maiBaseURL) ?? `https://${getResourceName()}.services.ai.azure.com/mai/v1`;
|
|
895
|
+
const createImageModel = (modelId) => new AzureImageModel(modelId, options, new OpenAIImageModel(modelId, {
|
|
703
896
|
provider: "azure.image",
|
|
704
897
|
url,
|
|
705
898
|
headers: getHeaders,
|
|
@@ -708,7 +901,11 @@ function createAzure(options = {}) {
|
|
|
708
901
|
supportsFileInputs: void 0,
|
|
709
902
|
supportsMaskInputs: void 0
|
|
710
903
|
}
|
|
711
|
-
})
|
|
904
|
+
}), new AzureMaiImageModel(modelId, {
|
|
905
|
+
url: (path) => `${maiBaseURL()}${path}`,
|
|
906
|
+
headers: () => getHeaders("mai"),
|
|
907
|
+
fetch
|
|
908
|
+
}));
|
|
712
909
|
const speechBaseURL = () => withoutTrailingSlash(options.speechBaseURL) ?? `https://${getResourceName()}.cognitiveservices.azure.com`;
|
|
713
910
|
const createTranscriptionModel = (modelId) => new AzureTranscriptionModel(modelId, options, new OpenAITranscriptionModel(modelId, {
|
|
714
911
|
provider: "azure.transcription",
|
|
@@ -720,7 +917,7 @@ function createAzure(options = {}) {
|
|
|
720
917
|
headers: () => getHeaders("speech"),
|
|
721
918
|
fetch
|
|
722
919
|
}), new AzureMaiTranscriptionModel(modelId, {
|
|
723
|
-
url: () => `${
|
|
920
|
+
url: () => `${maiBaseURL()}/realtime?intent=transcription`,
|
|
724
921
|
headers: async () => tokenProvider ? {
|
|
725
922
|
authorization: `Bearer ${await tokenProvider()}`,
|
|
726
923
|
...getHeaders("mai")
|
|
@@ -854,6 +1051,50 @@ var AzureSpeechModel = class {
|
|
|
854
1051
|
};
|
|
855
1052
|
}
|
|
856
1053
|
};
|
|
1054
|
+
var AzureImageModel = class {
|
|
1055
|
+
constructor(modelId, config, openai, mai) {
|
|
1056
|
+
this.modelId = modelId;
|
|
1057
|
+
this.config = config;
|
|
1058
|
+
this.openai = openai;
|
|
1059
|
+
this.mai = mai;
|
|
1060
|
+
this.specificationVersion = "v4";
|
|
1061
|
+
this.provider = "azure.image";
|
|
1062
|
+
}
|
|
1063
|
+
get defaultModel() {
|
|
1064
|
+
return isMAIImageModel(this.modelId) ? this.mai : this.openai;
|
|
1065
|
+
}
|
|
1066
|
+
get maxImagesPerCall() {
|
|
1067
|
+
return this.defaultModel.maxImagesPerCall;
|
|
1068
|
+
}
|
|
1069
|
+
get supportsFileInputs() {
|
|
1070
|
+
return this.defaultModel.supportsFileInputs;
|
|
1071
|
+
}
|
|
1072
|
+
get supportsMaskInputs() {
|
|
1073
|
+
return this.defaultModel.supportsMaskInputs;
|
|
1074
|
+
}
|
|
1075
|
+
static [WORKFLOW_SERIALIZE](model) {
|
|
1076
|
+
return serializeModelOptions({
|
|
1077
|
+
modelId: model.modelId,
|
|
1078
|
+
config: model.config
|
|
1079
|
+
});
|
|
1080
|
+
}
|
|
1081
|
+
static [WORKFLOW_DESERIALIZE](options) {
|
|
1082
|
+
return createAzure(options.config).image(options.modelId);
|
|
1083
|
+
}
|
|
1084
|
+
async doGenerate(options) {
|
|
1085
|
+
const { api, ...maiOptions } = await parseProviderOptions({
|
|
1086
|
+
provider: "azure",
|
|
1087
|
+
providerOptions: options.providerOptions,
|
|
1088
|
+
schema: azureImageModelOptions
|
|
1089
|
+
}) ?? {};
|
|
1090
|
+
if ((api ?? (isMAIImageModel(this.modelId) ? "mai" : "openai")) === "mai") return this.mai.doGenerate(options, maiOptions);
|
|
1091
|
+
const result = await this.openai.doGenerate(options);
|
|
1092
|
+
return {
|
|
1093
|
+
...result,
|
|
1094
|
+
warnings: [...result.warnings, ...unsupportedOptionWarnings(maiOptions, "This option requires the MAI image API.")]
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
857
1098
|
function speechOnlyWarnings(options) {
|
|
858
1099
|
return unsupportedOptionWarnings(options, "This option requires the Azure Speech API.");
|
|
859
1100
|
}
|