@ai-sdk/azure 4.0.0-beta.7 → 4.0.0-beta.76
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 +595 -8
- package/README.md +2 -0
- package/dist/index.d.ts +18 -2
- package/dist/index.js +86 -59
- package/dist/index.js.map +1 -1
- package/docs/04-azure.mdx +87 -24
- package/package.json +16 -15
- package/src/azure-openai-provider-metadata.ts +1 -1
- package/src/azure-openai-provider.ts +82 -23
- package/src/azure-openai-tools.ts +3 -0
- package/src/index.ts +8 -0
- package/dist/index.d.mts +0 -130
- package/dist/index.mjs +0 -140
- package/dist/index.mjs.map +0 -1
|
@@ -7,19 +7,22 @@ import {
|
|
|
7
7
|
OpenAISpeechModel,
|
|
8
8
|
OpenAITranscriptionModel,
|
|
9
9
|
} from '@ai-sdk/openai/internal';
|
|
10
|
+
import { DeepSeekChatLanguageModel } from '@ai-sdk/deepseek/internal';
|
|
10
11
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
InvalidArgumentError,
|
|
13
|
+
type EmbeddingModelV4,
|
|
14
|
+
type LanguageModelV4,
|
|
15
|
+
type ProviderV4,
|
|
16
|
+
type ImageModelV4,
|
|
17
|
+
type SpeechModelV4,
|
|
18
|
+
type TranscriptionModelV4,
|
|
17
19
|
} from '@ai-sdk/provider';
|
|
18
20
|
import {
|
|
19
|
-
FetchFunction,
|
|
20
21
|
loadApiKey,
|
|
21
22
|
loadSetting,
|
|
23
|
+
normalizeHeaders,
|
|
22
24
|
withUserAgentSuffix,
|
|
25
|
+
type FetchFunction,
|
|
23
26
|
} from '@ai-sdk/provider-utils';
|
|
24
27
|
import { azureOpenaiTools } from './azure-openai-tools';
|
|
25
28
|
import { VERSION } from './version';
|
|
@@ -37,6 +40,11 @@ export interface AzureOpenAIProvider extends ProviderV4 {
|
|
|
37
40
|
*/
|
|
38
41
|
chat(deploymentId: string): LanguageModelV4;
|
|
39
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Creates an Azure-hosted DeepSeek chat model for text generation.
|
|
45
|
+
*/
|
|
46
|
+
deepseek(deploymentId: string): LanguageModelV4;
|
|
47
|
+
|
|
40
48
|
/**
|
|
41
49
|
* Creates an Azure OpenAI responses API model for text generation.
|
|
42
50
|
*/
|
|
@@ -114,6 +122,13 @@ export interface AzureOpenAIProviderSettings {
|
|
|
114
122
|
*/
|
|
115
123
|
apiKey?: string;
|
|
116
124
|
|
|
125
|
+
/**
|
|
126
|
+
* A function that returns an access token for Microsoft Entra
|
|
127
|
+
* (formerly known as Azure Active Directory), which will be invoked
|
|
128
|
+
* on every request.
|
|
129
|
+
*/
|
|
130
|
+
tokenProvider?: (() => Promise<string>) | undefined;
|
|
131
|
+
|
|
117
132
|
/**
|
|
118
133
|
* Custom headers to include in the requests.
|
|
119
134
|
*/
|
|
@@ -144,18 +159,51 @@ export interface AzureOpenAIProviderSettings {
|
|
|
144
159
|
export function createAzure(
|
|
145
160
|
options: AzureOpenAIProviderSettings = {},
|
|
146
161
|
): AzureOpenAIProvider {
|
|
162
|
+
const tokenProvider = options.tokenProvider;
|
|
163
|
+
|
|
164
|
+
if (options.apiKey && tokenProvider) {
|
|
165
|
+
throw new InvalidArgumentError({
|
|
166
|
+
argument: 'apiKey/tokenProvider',
|
|
167
|
+
message:
|
|
168
|
+
'Both apiKey and tokenProvider were provided. Please use only one authentication method.',
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
147
172
|
const getHeaders = () => {
|
|
148
|
-
const
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
173
|
+
const authHeaders = tokenProvider
|
|
174
|
+
? {}
|
|
175
|
+
: {
|
|
176
|
+
'api-key': loadApiKey({
|
|
177
|
+
apiKey: options.apiKey,
|
|
178
|
+
environmentVariableName: 'AZURE_API_KEY',
|
|
179
|
+
description: 'Azure OpenAI',
|
|
180
|
+
}),
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
return withUserAgentSuffix(
|
|
184
|
+
{
|
|
185
|
+
...authHeaders,
|
|
186
|
+
...options.headers,
|
|
187
|
+
},
|
|
188
|
+
`ai-sdk/azure/${VERSION}`,
|
|
189
|
+
);
|
|
157
190
|
};
|
|
158
191
|
|
|
192
|
+
const fetch: FetchFunction | undefined = tokenProvider
|
|
193
|
+
? async (input, init) => {
|
|
194
|
+
const headers = normalizeHeaders(init?.headers);
|
|
195
|
+
|
|
196
|
+
if (headers.authorization == null) {
|
|
197
|
+
headers.authorization = `Bearer ${await tokenProvider()}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return (options.fetch ?? globalThis.fetch)(input, {
|
|
201
|
+
...init,
|
|
202
|
+
headers,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
: options.fetch;
|
|
206
|
+
|
|
159
207
|
const getResourceName = () =>
|
|
160
208
|
loadSetting({
|
|
161
209
|
settingValue: options.resourceName,
|
|
@@ -188,7 +236,16 @@ export function createAzure(
|
|
|
188
236
|
provider: 'azure.chat',
|
|
189
237
|
url,
|
|
190
238
|
headers: getHeaders,
|
|
191
|
-
fetch
|
|
239
|
+
fetch,
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
const createDeepSeekModel = (deploymentName: string) =>
|
|
243
|
+
new DeepSeekChatLanguageModel(deploymentName, {
|
|
244
|
+
provider: 'azure.deepseek',
|
|
245
|
+
url,
|
|
246
|
+
headers: getHeaders,
|
|
247
|
+
fetch,
|
|
248
|
+
supportsThinking: false,
|
|
192
249
|
});
|
|
193
250
|
|
|
194
251
|
const createCompletionModel = (modelId: string) =>
|
|
@@ -196,7 +253,7 @@ export function createAzure(
|
|
|
196
253
|
provider: 'azure.completion',
|
|
197
254
|
url,
|
|
198
255
|
headers: getHeaders,
|
|
199
|
-
fetch
|
|
256
|
+
fetch,
|
|
200
257
|
});
|
|
201
258
|
|
|
202
259
|
const createEmbeddingModel = (modelId: string) =>
|
|
@@ -204,7 +261,7 @@ export function createAzure(
|
|
|
204
261
|
provider: 'azure.embeddings',
|
|
205
262
|
headers: getHeaders,
|
|
206
263
|
url,
|
|
207
|
-
fetch
|
|
264
|
+
fetch,
|
|
208
265
|
});
|
|
209
266
|
|
|
210
267
|
const createResponsesModel = (modelId: string) =>
|
|
@@ -212,7 +269,8 @@ export function createAzure(
|
|
|
212
269
|
provider: 'azure.responses',
|
|
213
270
|
url,
|
|
214
271
|
headers: getHeaders,
|
|
215
|
-
fetch
|
|
272
|
+
fetch,
|
|
273
|
+
// Soft-deprecated. TODO: remove in v8
|
|
216
274
|
fileIdPrefixes: ['assistant-'],
|
|
217
275
|
});
|
|
218
276
|
|
|
@@ -221,7 +279,7 @@ export function createAzure(
|
|
|
221
279
|
provider: 'azure.image',
|
|
222
280
|
url,
|
|
223
281
|
headers: getHeaders,
|
|
224
|
-
fetch
|
|
282
|
+
fetch,
|
|
225
283
|
});
|
|
226
284
|
|
|
227
285
|
const createTranscriptionModel = (modelId: string) =>
|
|
@@ -229,7 +287,7 @@ export function createAzure(
|
|
|
229
287
|
provider: 'azure.transcription',
|
|
230
288
|
url,
|
|
231
289
|
headers: getHeaders,
|
|
232
|
-
fetch
|
|
290
|
+
fetch,
|
|
233
291
|
});
|
|
234
292
|
|
|
235
293
|
const createSpeechModel = (modelId: string) =>
|
|
@@ -237,7 +295,7 @@ export function createAzure(
|
|
|
237
295
|
provider: 'azure.speech',
|
|
238
296
|
url,
|
|
239
297
|
headers: getHeaders,
|
|
240
|
-
fetch
|
|
298
|
+
fetch,
|
|
241
299
|
});
|
|
242
300
|
|
|
243
301
|
const provider = function (deploymentId: string) {
|
|
@@ -253,6 +311,7 @@ export function createAzure(
|
|
|
253
311
|
provider.specificationVersion = 'v4' as const;
|
|
254
312
|
provider.languageModel = createResponsesModel;
|
|
255
313
|
provider.chat = createChatModel;
|
|
314
|
+
provider.deepseek = createDeepSeekModel;
|
|
256
315
|
provider.completion = createCompletionModel;
|
|
257
316
|
provider.embedding = createEmbeddingModel;
|
|
258
317
|
provider.embeddingModel = createEmbeddingModel;
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
codeInterpreter,
|
|
3
3
|
fileSearch,
|
|
4
4
|
imageGeneration,
|
|
5
|
+
webSearch,
|
|
5
6
|
webSearchPreview,
|
|
6
7
|
} from '@ai-sdk/openai/internal';
|
|
7
8
|
|
|
@@ -9,10 +10,12 @@ export const azureOpenaiTools: {
|
|
|
9
10
|
codeInterpreter: typeof codeInterpreter;
|
|
10
11
|
fileSearch: typeof fileSearch;
|
|
11
12
|
imageGeneration: typeof imageGeneration;
|
|
13
|
+
webSearch: typeof webSearch;
|
|
12
14
|
webSearchPreview: typeof webSearchPreview;
|
|
13
15
|
} = {
|
|
14
16
|
codeInterpreter,
|
|
15
17
|
fileSearch,
|
|
16
18
|
imageGeneration,
|
|
19
|
+
webSearch,
|
|
17
20
|
webSearchPreview,
|
|
18
21
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import type { DeepSeekLanguageModelChatOptions } from '@ai-sdk/deepseek';
|
|
2
|
+
|
|
3
|
+
export type AzureDeepSeekLanguageModelOptions = Omit<
|
|
4
|
+
DeepSeekLanguageModelChatOptions,
|
|
5
|
+
'thinking'
|
|
6
|
+
>;
|
|
7
|
+
/** @deprecated Use `AzureDeepSeekLanguageModelOptions` instead. */
|
|
8
|
+
export type AzureDeepSeekChatOptions = AzureDeepSeekLanguageModelOptions;
|
|
1
9
|
export type {
|
|
2
10
|
OpenAILanguageModelResponsesOptions,
|
|
3
11
|
/** @deprecated Use `OpenAILanguageModelResponsesOptions` instead. */
|
package/dist/index.d.mts
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
export { OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, OpenAILanguageModelChatOptions, OpenAILanguageModelResponsesOptions, OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions } from '@ai-sdk/openai';
|
|
2
|
-
import { ProviderV4, LanguageModelV4, EmbeddingModelV4, ImageModelV4, TranscriptionModelV4, SpeechModelV4 } from '@ai-sdk/provider';
|
|
3
|
-
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
|
-
import { codeInterpreter, fileSearch, imageGeneration, webSearchPreview, ResponsesProviderMetadata, ResponsesReasoningProviderMetadata, ResponsesTextProviderMetadata, ResponsesSourceDocumentProviderMetadata } from '@ai-sdk/openai/internal';
|
|
5
|
-
|
|
6
|
-
declare const azureOpenaiTools: {
|
|
7
|
-
codeInterpreter: typeof codeInterpreter;
|
|
8
|
-
fileSearch: typeof fileSearch;
|
|
9
|
-
imageGeneration: typeof imageGeneration;
|
|
10
|
-
webSearchPreview: typeof webSearchPreview;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
interface AzureOpenAIProvider extends ProviderV4 {
|
|
14
|
-
(deploymentId: string): LanguageModelV4;
|
|
15
|
-
/**
|
|
16
|
-
* Creates an Azure OpenAI responses API model for text generation.
|
|
17
|
-
*/
|
|
18
|
-
languageModel(deploymentId: string): LanguageModelV4;
|
|
19
|
-
/**
|
|
20
|
-
* Creates an Azure OpenAI chat model for text generation.
|
|
21
|
-
*/
|
|
22
|
-
chat(deploymentId: string): LanguageModelV4;
|
|
23
|
-
/**
|
|
24
|
-
* Creates an Azure OpenAI responses API model for text generation.
|
|
25
|
-
*/
|
|
26
|
-
responses(deploymentId: string): LanguageModelV4;
|
|
27
|
-
/**
|
|
28
|
-
* Creates an Azure OpenAI completion model for text generation.
|
|
29
|
-
*/
|
|
30
|
-
completion(deploymentId: string): LanguageModelV4;
|
|
31
|
-
/**
|
|
32
|
-
* Creates an Azure OpenAI model for text embeddings.
|
|
33
|
-
*/
|
|
34
|
-
embedding(deploymentId: string): EmbeddingModelV4;
|
|
35
|
-
/**
|
|
36
|
-
* Creates an Azure OpenAI model for text embeddings.
|
|
37
|
-
*/
|
|
38
|
-
embeddingModel(deploymentId: string): EmbeddingModelV4;
|
|
39
|
-
/**
|
|
40
|
-
* @deprecated Use `embedding` instead.
|
|
41
|
-
*/
|
|
42
|
-
textEmbedding(deploymentId: string): EmbeddingModelV4;
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated Use `embeddingModel` instead.
|
|
45
|
-
*/
|
|
46
|
-
textEmbeddingModel(deploymentId: string): EmbeddingModelV4;
|
|
47
|
-
/**
|
|
48
|
-
* Creates an Azure OpenAI DALL-E model for image generation.
|
|
49
|
-
*/
|
|
50
|
-
image(deploymentId: string): ImageModelV4;
|
|
51
|
-
/**
|
|
52
|
-
* Creates an Azure OpenAI DALL-E model for image generation.
|
|
53
|
-
*/
|
|
54
|
-
imageModel(deploymentId: string): ImageModelV4;
|
|
55
|
-
/**
|
|
56
|
-
* Creates an Azure OpenAI model for audio transcription.
|
|
57
|
-
*/
|
|
58
|
-
transcription(deploymentId: string): TranscriptionModelV4;
|
|
59
|
-
/**
|
|
60
|
-
* Creates an Azure OpenAI model for speech generation.
|
|
61
|
-
*/
|
|
62
|
-
speech(deploymentId: string): SpeechModelV4;
|
|
63
|
-
/**
|
|
64
|
-
* AzureOpenAI-specific tools.
|
|
65
|
-
*/
|
|
66
|
-
tools: typeof azureOpenaiTools;
|
|
67
|
-
}
|
|
68
|
-
interface AzureOpenAIProviderSettings {
|
|
69
|
-
/**
|
|
70
|
-
* Name of the Azure OpenAI resource. Either this or `baseURL` can be used.
|
|
71
|
-
*
|
|
72
|
-
* The resource name is used in the assembled URL: `https://{resourceName}.openai.azure.com/openai/v1{path}`.
|
|
73
|
-
*/
|
|
74
|
-
resourceName?: string;
|
|
75
|
-
/**
|
|
76
|
-
* Use a different URL prefix for API calls, e.g. to use proxy servers. Either this or `resourceName` can be used.
|
|
77
|
-
* When a baseURL is provided, the resourceName is ignored.
|
|
78
|
-
*
|
|
79
|
-
* With a baseURL, the resolved URL is `{baseURL}/v1{path}`.
|
|
80
|
-
*/
|
|
81
|
-
baseURL?: string;
|
|
82
|
-
/**
|
|
83
|
-
* API key for authenticating requests.
|
|
84
|
-
*/
|
|
85
|
-
apiKey?: string;
|
|
86
|
-
/**
|
|
87
|
-
* Custom headers to include in the requests.
|
|
88
|
-
*/
|
|
89
|
-
headers?: Record<string, string>;
|
|
90
|
-
/**
|
|
91
|
-
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
92
|
-
* or to provide a custom fetch implementation for e.g. testing.
|
|
93
|
-
*/
|
|
94
|
-
fetch?: FetchFunction;
|
|
95
|
-
/**
|
|
96
|
-
* Custom api version to use. Defaults to `preview`.
|
|
97
|
-
*/
|
|
98
|
-
apiVersion?: string;
|
|
99
|
-
/**
|
|
100
|
-
* Use deployment-based URLs for specific model types. Set to true to use legacy deployment format:
|
|
101
|
-
* `{baseURL}/deployments/{deploymentId}{path}?api-version={apiVersion}` instead of
|
|
102
|
-
* `{baseURL}/v1{path}?api-version={apiVersion}`.
|
|
103
|
-
*/
|
|
104
|
-
useDeploymentBasedUrls?: boolean;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Create an Azure OpenAI provider instance.
|
|
108
|
-
*/
|
|
109
|
-
declare function createAzure(options?: AzureOpenAIProviderSettings): AzureOpenAIProvider;
|
|
110
|
-
/**
|
|
111
|
-
* Default Azure OpenAI provider instance.
|
|
112
|
-
*/
|
|
113
|
-
declare const azure: AzureOpenAIProvider;
|
|
114
|
-
|
|
115
|
-
type AzureResponsesProviderMetadata = {
|
|
116
|
-
azure: ResponsesProviderMetadata;
|
|
117
|
-
};
|
|
118
|
-
type AzureResponsesReasoningProviderMetadata = {
|
|
119
|
-
azure: ResponsesReasoningProviderMetadata;
|
|
120
|
-
};
|
|
121
|
-
type AzureResponsesTextProviderMetadata = {
|
|
122
|
-
azure: ResponsesTextProviderMetadata;
|
|
123
|
-
};
|
|
124
|
-
type AzureResponsesSourceDocumentProviderMetadata = {
|
|
125
|
-
azure: ResponsesSourceDocumentProviderMetadata;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
declare const VERSION: string;
|
|
129
|
-
|
|
130
|
-
export { type AzureOpenAIProvider, type AzureOpenAIProviderSettings, type AzureResponsesProviderMetadata, type AzureResponsesReasoningProviderMetadata, type AzureResponsesSourceDocumentProviderMetadata, type AzureResponsesTextProviderMetadata, VERSION, azure, createAzure };
|
package/dist/index.mjs
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// src/azure-openai-provider.ts
|
|
2
|
-
import {
|
|
3
|
-
OpenAIChatLanguageModel,
|
|
4
|
-
OpenAICompletionLanguageModel,
|
|
5
|
-
OpenAIEmbeddingModel,
|
|
6
|
-
OpenAIImageModel,
|
|
7
|
-
OpenAIResponsesLanguageModel,
|
|
8
|
-
OpenAISpeechModel,
|
|
9
|
-
OpenAITranscriptionModel
|
|
10
|
-
} from "@ai-sdk/openai/internal";
|
|
11
|
-
import {
|
|
12
|
-
loadApiKey,
|
|
13
|
-
loadSetting,
|
|
14
|
-
withUserAgentSuffix
|
|
15
|
-
} from "@ai-sdk/provider-utils";
|
|
16
|
-
|
|
17
|
-
// src/azure-openai-tools.ts
|
|
18
|
-
import {
|
|
19
|
-
codeInterpreter,
|
|
20
|
-
fileSearch,
|
|
21
|
-
imageGeneration,
|
|
22
|
-
webSearchPreview
|
|
23
|
-
} from "@ai-sdk/openai/internal";
|
|
24
|
-
var azureOpenaiTools = {
|
|
25
|
-
codeInterpreter,
|
|
26
|
-
fileSearch,
|
|
27
|
-
imageGeneration,
|
|
28
|
-
webSearchPreview
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// src/version.ts
|
|
32
|
-
var VERSION = true ? "4.0.0-beta.7" : "0.0.0-test";
|
|
33
|
-
|
|
34
|
-
// src/azure-openai-provider.ts
|
|
35
|
-
function createAzure(options = {}) {
|
|
36
|
-
var _a;
|
|
37
|
-
const getHeaders = () => {
|
|
38
|
-
const baseHeaders = {
|
|
39
|
-
"api-key": loadApiKey({
|
|
40
|
-
apiKey: options.apiKey,
|
|
41
|
-
environmentVariableName: "AZURE_API_KEY",
|
|
42
|
-
description: "Azure OpenAI"
|
|
43
|
-
}),
|
|
44
|
-
...options.headers
|
|
45
|
-
};
|
|
46
|
-
return withUserAgentSuffix(baseHeaders, `ai-sdk/azure/${VERSION}`);
|
|
47
|
-
};
|
|
48
|
-
const getResourceName = () => loadSetting({
|
|
49
|
-
settingValue: options.resourceName,
|
|
50
|
-
settingName: "resourceName",
|
|
51
|
-
environmentVariableName: "AZURE_RESOURCE_NAME",
|
|
52
|
-
description: "Azure OpenAI resource name"
|
|
53
|
-
});
|
|
54
|
-
const apiVersion = (_a = options.apiVersion) != null ? _a : "v1";
|
|
55
|
-
const url = ({ path, modelId }) => {
|
|
56
|
-
var _a2;
|
|
57
|
-
const baseUrlPrefix = (_a2 = options.baseURL) != null ? _a2 : `https://${getResourceName()}.openai.azure.com/openai`;
|
|
58
|
-
let fullUrl;
|
|
59
|
-
if (options.useDeploymentBasedUrls) {
|
|
60
|
-
fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path}`);
|
|
61
|
-
} else {
|
|
62
|
-
fullUrl = new URL(`${baseUrlPrefix}/v1${path}`);
|
|
63
|
-
}
|
|
64
|
-
fullUrl.searchParams.set("api-version", apiVersion);
|
|
65
|
-
return fullUrl.toString();
|
|
66
|
-
};
|
|
67
|
-
const createChatModel = (deploymentName) => new OpenAIChatLanguageModel(deploymentName, {
|
|
68
|
-
provider: "azure.chat",
|
|
69
|
-
url,
|
|
70
|
-
headers: getHeaders,
|
|
71
|
-
fetch: options.fetch
|
|
72
|
-
});
|
|
73
|
-
const createCompletionModel = (modelId) => new OpenAICompletionLanguageModel(modelId, {
|
|
74
|
-
provider: "azure.completion",
|
|
75
|
-
url,
|
|
76
|
-
headers: getHeaders,
|
|
77
|
-
fetch: options.fetch
|
|
78
|
-
});
|
|
79
|
-
const createEmbeddingModel = (modelId) => new OpenAIEmbeddingModel(modelId, {
|
|
80
|
-
provider: "azure.embeddings",
|
|
81
|
-
headers: getHeaders,
|
|
82
|
-
url,
|
|
83
|
-
fetch: options.fetch
|
|
84
|
-
});
|
|
85
|
-
const createResponsesModel = (modelId) => new OpenAIResponsesLanguageModel(modelId, {
|
|
86
|
-
provider: "azure.responses",
|
|
87
|
-
url,
|
|
88
|
-
headers: getHeaders,
|
|
89
|
-
fetch: options.fetch,
|
|
90
|
-
fileIdPrefixes: ["assistant-"]
|
|
91
|
-
});
|
|
92
|
-
const createImageModel = (modelId) => new OpenAIImageModel(modelId, {
|
|
93
|
-
provider: "azure.image",
|
|
94
|
-
url,
|
|
95
|
-
headers: getHeaders,
|
|
96
|
-
fetch: options.fetch
|
|
97
|
-
});
|
|
98
|
-
const createTranscriptionModel = (modelId) => new OpenAITranscriptionModel(modelId, {
|
|
99
|
-
provider: "azure.transcription",
|
|
100
|
-
url,
|
|
101
|
-
headers: getHeaders,
|
|
102
|
-
fetch: options.fetch
|
|
103
|
-
});
|
|
104
|
-
const createSpeechModel = (modelId) => new OpenAISpeechModel(modelId, {
|
|
105
|
-
provider: "azure.speech",
|
|
106
|
-
url,
|
|
107
|
-
headers: getHeaders,
|
|
108
|
-
fetch: options.fetch
|
|
109
|
-
});
|
|
110
|
-
const provider = function(deploymentId) {
|
|
111
|
-
if (new.target) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
"The Azure OpenAI model function cannot be called with the new keyword."
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
return createResponsesModel(deploymentId);
|
|
117
|
-
};
|
|
118
|
-
provider.specificationVersion = "v4";
|
|
119
|
-
provider.languageModel = createResponsesModel;
|
|
120
|
-
provider.chat = createChatModel;
|
|
121
|
-
provider.completion = createCompletionModel;
|
|
122
|
-
provider.embedding = createEmbeddingModel;
|
|
123
|
-
provider.embeddingModel = createEmbeddingModel;
|
|
124
|
-
provider.textEmbedding = createEmbeddingModel;
|
|
125
|
-
provider.textEmbeddingModel = createEmbeddingModel;
|
|
126
|
-
provider.image = createImageModel;
|
|
127
|
-
provider.imageModel = createImageModel;
|
|
128
|
-
provider.responses = createResponsesModel;
|
|
129
|
-
provider.transcription = createTranscriptionModel;
|
|
130
|
-
provider.speech = createSpeechModel;
|
|
131
|
-
provider.tools = azureOpenaiTools;
|
|
132
|
-
return provider;
|
|
133
|
-
}
|
|
134
|
-
var azure = createAzure();
|
|
135
|
-
export {
|
|
136
|
-
VERSION,
|
|
137
|
-
azure,
|
|
138
|
-
createAzure
|
|
139
|
-
};
|
|
140
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/azure-openai-provider.ts","../src/azure-openai-tools.ts","../src/version.ts"],"sourcesContent":["import {\n OpenAIChatLanguageModel,\n OpenAICompletionLanguageModel,\n OpenAIEmbeddingModel,\n OpenAIImageModel,\n OpenAIResponsesLanguageModel,\n OpenAISpeechModel,\n OpenAITranscriptionModel,\n} from '@ai-sdk/openai/internal';\nimport {\n EmbeddingModelV4,\n LanguageModelV4,\n ProviderV4,\n ImageModelV4,\n SpeechModelV4,\n TranscriptionModelV4,\n} from '@ai-sdk/provider';\nimport {\n FetchFunction,\n loadApiKey,\n loadSetting,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { azureOpenaiTools } from './azure-openai-tools';\nimport { VERSION } from './version';\n\nexport interface AzureOpenAIProvider extends ProviderV4 {\n (deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI responses API model for text generation.\n */\n languageModel(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI chat model for text generation.\n */\n chat(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI responses API model for text generation.\n */\n responses(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI completion model for text generation.\n */\n completion(deploymentId: string): LanguageModelV4;\n\n /**\n * Creates an Azure OpenAI model for text embeddings.\n */\n embedding(deploymentId: string): EmbeddingModelV4;\n\n /**\n * Creates an Azure OpenAI model for text embeddings.\n */\n embeddingModel(deploymentId: string): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embedding` instead.\n */\n textEmbedding(deploymentId: string): EmbeddingModelV4;\n\n /**\n * @deprecated Use `embeddingModel` instead.\n */\n textEmbeddingModel(deploymentId: string): EmbeddingModelV4;\n\n /**\n * Creates an Azure OpenAI DALL-E model for image generation.\n */\n image(deploymentId: string): ImageModelV4;\n\n /**\n * Creates an Azure OpenAI DALL-E model for image generation.\n */\n imageModel(deploymentId: string): ImageModelV4;\n\n /**\n * Creates an Azure OpenAI model for audio transcription.\n */\n transcription(deploymentId: string): TranscriptionModelV4;\n\n /**\n * Creates an Azure OpenAI model for speech generation.\n */\n speech(deploymentId: string): SpeechModelV4;\n\n /**\n * AzureOpenAI-specific tools.\n */\n tools: typeof azureOpenaiTools;\n}\n\nexport interface AzureOpenAIProviderSettings {\n /**\n * Name of the Azure OpenAI resource. Either this or `baseURL` can be used.\n *\n * The resource name is used in the assembled URL: `https://{resourceName}.openai.azure.com/openai/v1{path}`.\n */\n resourceName?: string;\n\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers. Either this or `resourceName` can be used.\n * When a baseURL is provided, the resourceName is ignored.\n *\n * With a baseURL, the resolved URL is `{baseURL}/v1{path}`.\n */\n baseURL?: string;\n\n /**\n * API key for authenticating requests.\n */\n apiKey?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * Custom api version to use. Defaults to `preview`.\n */\n apiVersion?: string;\n\n /**\n * Use deployment-based URLs for specific model types. Set to true to use legacy deployment format:\n * `{baseURL}/deployments/{deploymentId}{path}?api-version={apiVersion}` instead of\n * `{baseURL}/v1{path}?api-version={apiVersion}`.\n */\n useDeploymentBasedUrls?: boolean;\n}\n\n/**\n * Create an Azure OpenAI provider instance.\n */\nexport function createAzure(\n options: AzureOpenAIProviderSettings = {},\n): AzureOpenAIProvider {\n const getHeaders = () => {\n const baseHeaders = {\n 'api-key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'AZURE_API_KEY',\n description: 'Azure OpenAI',\n }),\n ...options.headers,\n };\n return withUserAgentSuffix(baseHeaders, `ai-sdk/azure/${VERSION}`);\n };\n\n const getResourceName = () =>\n loadSetting({\n settingValue: options.resourceName,\n settingName: 'resourceName',\n environmentVariableName: 'AZURE_RESOURCE_NAME',\n description: 'Azure OpenAI resource name',\n });\n\n const apiVersion = options.apiVersion ?? 'v1';\n\n const url = ({ path, modelId }: { path: string; modelId: string }) => {\n const baseUrlPrefix =\n options.baseURL ?? `https://${getResourceName()}.openai.azure.com/openai`;\n\n let fullUrl: URL;\n if (options.useDeploymentBasedUrls) {\n // Use deployment-based format for compatibility with certain Azure OpenAI models\n fullUrl = new URL(`${baseUrlPrefix}/deployments/${modelId}${path}`);\n } else {\n // Use v1 API format - no deployment ID in URL\n fullUrl = new URL(`${baseUrlPrefix}/v1${path}`);\n }\n\n fullUrl.searchParams.set('api-version', apiVersion);\n return fullUrl.toString();\n };\n\n const createChatModel = (deploymentName: string) =>\n new OpenAIChatLanguageModel(deploymentName, {\n provider: 'azure.chat',\n url,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createCompletionModel = (modelId: string) =>\n new OpenAICompletionLanguageModel(modelId, {\n provider: 'azure.completion',\n url,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createEmbeddingModel = (modelId: string) =>\n new OpenAIEmbeddingModel(modelId, {\n provider: 'azure.embeddings',\n headers: getHeaders,\n url,\n fetch: options.fetch,\n });\n\n const createResponsesModel = (modelId: string) =>\n new OpenAIResponsesLanguageModel(modelId, {\n provider: 'azure.responses',\n url,\n headers: getHeaders,\n fetch: options.fetch,\n fileIdPrefixes: ['assistant-'],\n });\n\n const createImageModel = (modelId: string) =>\n new OpenAIImageModel(modelId, {\n provider: 'azure.image',\n url,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createTranscriptionModel = (modelId: string) =>\n new OpenAITranscriptionModel(modelId, {\n provider: 'azure.transcription',\n url,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const createSpeechModel = (modelId: string) =>\n new OpenAISpeechModel(modelId, {\n provider: 'azure.speech',\n url,\n headers: getHeaders,\n fetch: options.fetch,\n });\n\n const provider = function (deploymentId: string) {\n if (new.target) {\n throw new Error(\n 'The Azure OpenAI model function cannot be called with the new keyword.',\n );\n }\n\n return createResponsesModel(deploymentId);\n };\n\n provider.specificationVersion = 'v4' as const;\n provider.languageModel = createResponsesModel;\n provider.chat = createChatModel;\n provider.completion = createCompletionModel;\n provider.embedding = createEmbeddingModel;\n provider.embeddingModel = createEmbeddingModel;\n provider.textEmbedding = createEmbeddingModel;\n provider.textEmbeddingModel = createEmbeddingModel;\n provider.image = createImageModel;\n provider.imageModel = createImageModel;\n provider.responses = createResponsesModel;\n provider.transcription = createTranscriptionModel;\n provider.speech = createSpeechModel;\n provider.tools = azureOpenaiTools;\n return provider;\n}\n\n/**\n * Default Azure OpenAI provider instance.\n */\nexport const azure = createAzure();\n","import {\n codeInterpreter,\n fileSearch,\n imageGeneration,\n webSearchPreview,\n} from '@ai-sdk/openai/internal';\n\nexport const azureOpenaiTools: {\n codeInterpreter: typeof codeInterpreter;\n fileSearch: typeof fileSearch;\n imageGeneration: typeof imageGeneration;\n webSearchPreview: typeof webSearchPreview;\n} = {\n codeInterpreter,\n fileSearch,\n imageGeneration,\n webSearchPreview,\n};\n","// Version string of this package injected at build time.\ndeclare const __PACKAGE_VERSION__: string | undefined;\nexport const VERSION: string =\n typeof __PACKAGE_VERSION__ !== 'undefined'\n ? __PACKAGE_VERSION__\n : '0.0.0-test';\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC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