@ai-sdk/azure 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2023 Vercel, Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Vercel AI SDK - Azure OpenAI Provider
2
+
3
+ The **[Azure provider](https://sdk.vercel.ai/providers/ai-sdk-providers/azure)** for the [Vercel AI SDK](https://sdk.vercel.ai/docs) contains language model support for the Azure OpenAI API.
4
+
5
+ ## Setup
6
+
7
+ The Azure provider is available in the `@ai-sdk/azure` module. You can install it with
8
+
9
+ ```bash
10
+ npm i @ai-sdk/azure
11
+ ```
12
+
13
+ ## Provider Instance
14
+
15
+ You can import the default provider instance `azure` from `@ai-sdk/azure`:
16
+
17
+ ```ts
18
+ import { azure } from '@ai-sdk/azure';
19
+ ```
20
+
21
+ ## Example
22
+
23
+ ```ts
24
+ import { azure } from '@ai-sdk/azure';
25
+ import { generateText } from 'ai';
26
+
27
+ const { text } = await generateText({
28
+ model: azure('gpt-4o'), // your deployment name
29
+ prompt: 'Write a vegetarian lasagna recipe for 4 people.',
30
+ });
31
+ ```
32
+
33
+ ## Documentation
34
+
35
+ Please check out the **[Azure provider](https://sdk.vercel.ai/providers/ai-sdk-providers/azure)** for more information.
@@ -0,0 +1,29 @@
1
+ import { OpenAIChatSettings, OpenAIChatLanguageModel } from '@ai-sdk/openai/internal';
2
+
3
+ interface AzureOpenAIProvider {
4
+ (deploymentId: string, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
5
+ /**
6
+ Creates an Azure OpenAI chat model for text generation.
7
+ */
8
+ chat(deploymentId: string, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
9
+ }
10
+ interface AzureOpenAIProviderSettings {
11
+ /**
12
+ Name of the Azure OpenAI resource.
13
+ */
14
+ resourceName?: string;
15
+ /**
16
+ API key for authenticating requests.
17
+ */
18
+ apiKey?: string;
19
+ }
20
+ /**
21
+ Create an Azure OpenAI provider instance.
22
+ */
23
+ declare function createAzure(options?: AzureOpenAIProviderSettings): AzureOpenAIProvider;
24
+ /**
25
+ Default Azure OpenAI provider instance.
26
+ */
27
+ declare const azure: AzureOpenAIProvider;
28
+
29
+ export { type AzureOpenAIProvider, type AzureOpenAIProviderSettings, azure, createAzure };
@@ -0,0 +1,29 @@
1
+ import { OpenAIChatSettings, OpenAIChatLanguageModel } from '@ai-sdk/openai/internal';
2
+
3
+ interface AzureOpenAIProvider {
4
+ (deploymentId: string, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
5
+ /**
6
+ Creates an Azure OpenAI chat model for text generation.
7
+ */
8
+ chat(deploymentId: string, settings?: OpenAIChatSettings): OpenAIChatLanguageModel;
9
+ }
10
+ interface AzureOpenAIProviderSettings {
11
+ /**
12
+ Name of the Azure OpenAI resource.
13
+ */
14
+ resourceName?: string;
15
+ /**
16
+ API key for authenticating requests.
17
+ */
18
+ apiKey?: string;
19
+ }
20
+ /**
21
+ Create an Azure OpenAI provider instance.
22
+ */
23
+ declare function createAzure(options?: AzureOpenAIProviderSettings): AzureOpenAIProvider;
24
+ /**
25
+ Default Azure OpenAI provider instance.
26
+ */
27
+ declare const azure: AzureOpenAIProvider;
28
+
29
+ export { type AzureOpenAIProvider, type AzureOpenAIProviderSettings, azure, createAzure };
package/dist/index.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ azure: () => azure,
24
+ createAzure: () => createAzure
25
+ });
26
+ module.exports = __toCommonJS(src_exports);
27
+
28
+ // src/azure-openai-provider.ts
29
+ var import_internal = require("@ai-sdk/openai/internal");
30
+ var import_provider_utils = require("@ai-sdk/provider-utils");
31
+ function createAzure(options = {}) {
32
+ const getHeaders = () => ({
33
+ "api-key": (0, import_provider_utils.loadApiKey)({
34
+ apiKey: options.apiKey,
35
+ environmentVariableName: "AZURE_API_KEY",
36
+ description: "Azure OpenAI"
37
+ })
38
+ });
39
+ const getResourceName = () => (0, import_provider_utils.loadSetting)({
40
+ settingValue: options.resourceName,
41
+ settingName: "resourceName",
42
+ environmentVariableName: "AZURE_RESOURCE_NAME",
43
+ description: "Azure OpenAI resource name"
44
+ });
45
+ const createChatModel = (deploymentName, settings = {}) => new import_internal.OpenAIChatLanguageModel(deploymentName, settings, {
46
+ provider: "azure-openai.chat",
47
+ headers: getHeaders,
48
+ url: ({ path, modelId }) => `https://${getResourceName()}.openai.azure.com/openai/deployments/${modelId}${path}?api-version=2024-05-01-preview`,
49
+ compatibility: "compatible"
50
+ });
51
+ const provider = function(deploymentId, settings) {
52
+ if (new.target) {
53
+ throw new Error(
54
+ "The Azure OpenAI model function cannot be called with the new keyword."
55
+ );
56
+ }
57
+ return createChatModel(deploymentId, settings);
58
+ };
59
+ provider.chat = createChatModel;
60
+ return provider;
61
+ }
62
+ var azure = createAzure({});
63
+ // Annotate the CommonJS export names for ESM import in node:
64
+ 0 && (module.exports = {
65
+ azure,
66
+ createAzure
67
+ });
68
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/azure-openai-provider.ts"],"sourcesContent":["export * from './azure-openai-provider';\n","import {\n OpenAIChatLanguageModel,\n OpenAIChatSettings,\n} from '@ai-sdk/openai/internal';\nimport { loadApiKey, loadSetting } from '@ai-sdk/provider-utils';\n\nexport interface AzureOpenAIProvider {\n (\n deploymentId: string,\n settings?: OpenAIChatSettings,\n ): OpenAIChatLanguageModel;\n\n /**\nCreates an Azure OpenAI chat model for text generation.\n */\n chat(\n deploymentId: string,\n settings?: OpenAIChatSettings,\n ): OpenAIChatLanguageModel;\n}\n\nexport interface AzureOpenAIProviderSettings {\n /**\nName of the Azure OpenAI resource.\n */\n resourceName?: string;\n\n /**\nAPI key for authenticating requests.\n */\n apiKey?: string;\n}\n\n/**\nCreate an Azure OpenAI provider instance.\n */\nexport function createAzure(\n options: AzureOpenAIProviderSettings = {},\n): AzureOpenAIProvider {\n const getHeaders = () => ({\n 'api-key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'AZURE_API_KEY',\n description: 'Azure OpenAI',\n }),\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 createChatModel = (\n deploymentName: string,\n settings: OpenAIChatSettings = {},\n ) =>\n new OpenAIChatLanguageModel(deploymentName, settings, {\n provider: 'azure-openai.chat',\n headers: getHeaders,\n url: ({ path, modelId }) =>\n `https://${getResourceName()}.openai.azure.com/openai/deployments/${modelId}${path}?api-version=2024-05-01-preview`,\n compatibility: 'compatible',\n });\n\n const provider = function (\n deploymentId: string,\n settings?: OpenAIChatSettings,\n ) {\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 createChatModel(deploymentId, settings as OpenAIChatSettings);\n };\n\n provider.chat = createChatModel;\n\n return provider as AzureOpenAIProvider;\n}\n\n/**\nDefault Azure OpenAI provider instance.\n */\nexport const azure = createAzure({});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,sBAGO;AACP,4BAAwC;AAgCjC,SAAS,YACd,UAAuC,CAAC,GACnB;AACrB,QAAM,aAAa,OAAO;AAAA,IACxB,eAAW,kCAAW;AAAA,MACpB,QAAQ,QAAQ;AAAA,MAChB,yBAAyB;AAAA,MACzB,aAAa;AAAA,IACf,CAAC;AAAA,EACH;AAEA,QAAM,kBAAkB,UACtB,mCAAY;AAAA,IACV,cAAc,QAAQ;AAAA,IACtB,aAAa;AAAA,IACb,yBAAyB;AAAA,IACzB,aAAa;AAAA,EACf,CAAC;AAEH,QAAM,kBAAkB,CACtB,gBACA,WAA+B,CAAC,MAEhC,IAAI,wCAAwB,gBAAgB,UAAU;AAAA,IACpD,UAAU;AAAA,IACV,SAAS;AAAA,IACT,KAAK,CAAC,EAAE,MAAM,QAAQ,MACpB,WAAW,gBAAgB,CAAC,wCAAwC,OAAO,GAAG,IAAI;AAAA,IACpF,eAAe;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,SACf,cACA,UACA;AACA,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,cAAc,QAA8B;AAAA,EACrE;AAEA,WAAS,OAAO;AAEhB,SAAO;AACT;AAKO,IAAM,QAAQ,YAAY,CAAC,CAAC;","names":[]}
package/dist/index.mjs ADDED
@@ -0,0 +1,42 @@
1
+ // src/azure-openai-provider.ts
2
+ import {
3
+ OpenAIChatLanguageModel
4
+ } from "@ai-sdk/openai/internal";
5
+ import { loadApiKey, loadSetting } from "@ai-sdk/provider-utils";
6
+ function createAzure(options = {}) {
7
+ const getHeaders = () => ({
8
+ "api-key": loadApiKey({
9
+ apiKey: options.apiKey,
10
+ environmentVariableName: "AZURE_API_KEY",
11
+ description: "Azure OpenAI"
12
+ })
13
+ });
14
+ const getResourceName = () => loadSetting({
15
+ settingValue: options.resourceName,
16
+ settingName: "resourceName",
17
+ environmentVariableName: "AZURE_RESOURCE_NAME",
18
+ description: "Azure OpenAI resource name"
19
+ });
20
+ const createChatModel = (deploymentName, settings = {}) => new OpenAIChatLanguageModel(deploymentName, settings, {
21
+ provider: "azure-openai.chat",
22
+ headers: getHeaders,
23
+ url: ({ path, modelId }) => `https://${getResourceName()}.openai.azure.com/openai/deployments/${modelId}${path}?api-version=2024-05-01-preview`,
24
+ compatibility: "compatible"
25
+ });
26
+ const provider = function(deploymentId, settings) {
27
+ if (new.target) {
28
+ throw new Error(
29
+ "The Azure OpenAI model function cannot be called with the new keyword."
30
+ );
31
+ }
32
+ return createChatModel(deploymentId, settings);
33
+ };
34
+ provider.chat = createChatModel;
35
+ return provider;
36
+ }
37
+ var azure = createAzure({});
38
+ export {
39
+ azure,
40
+ createAzure
41
+ };
42
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/azure-openai-provider.ts"],"sourcesContent":["import {\n OpenAIChatLanguageModel,\n OpenAIChatSettings,\n} from '@ai-sdk/openai/internal';\nimport { loadApiKey, loadSetting } from '@ai-sdk/provider-utils';\n\nexport interface AzureOpenAIProvider {\n (\n deploymentId: string,\n settings?: OpenAIChatSettings,\n ): OpenAIChatLanguageModel;\n\n /**\nCreates an Azure OpenAI chat model for text generation.\n */\n chat(\n deploymentId: string,\n settings?: OpenAIChatSettings,\n ): OpenAIChatLanguageModel;\n}\n\nexport interface AzureOpenAIProviderSettings {\n /**\nName of the Azure OpenAI resource.\n */\n resourceName?: string;\n\n /**\nAPI key for authenticating requests.\n */\n apiKey?: string;\n}\n\n/**\nCreate an Azure OpenAI provider instance.\n */\nexport function createAzure(\n options: AzureOpenAIProviderSettings = {},\n): AzureOpenAIProvider {\n const getHeaders = () => ({\n 'api-key': loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'AZURE_API_KEY',\n description: 'Azure OpenAI',\n }),\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 createChatModel = (\n deploymentName: string,\n settings: OpenAIChatSettings = {},\n ) =>\n new OpenAIChatLanguageModel(deploymentName, settings, {\n provider: 'azure-openai.chat',\n headers: getHeaders,\n url: ({ path, modelId }) =>\n `https://${getResourceName()}.openai.azure.com/openai/deployments/${modelId}${path}?api-version=2024-05-01-preview`,\n compatibility: 'compatible',\n });\n\n const provider = function (\n deploymentId: string,\n settings?: OpenAIChatSettings,\n ) {\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 createChatModel(deploymentId, settings as OpenAIChatSettings);\n };\n\n provider.chat = createChatModel;\n\n return provider as AzureOpenAIProvider;\n}\n\n/**\nDefault Azure OpenAI provider instance.\n */\nexport const azure = createAzure({});\n"],"mappings":";AAAA;AAAA,EACE;AAAA,OAEK;AACP,SAAS,YAAY,mBAAmB;AAgCjC,SAAS,YACd,UAAuC,CAAC,GACnB;AACrB,QAAM,aAAa,OAAO;AAAA,IACxB,WAAW,WAAW;AAAA,MACpB,QAAQ,QAAQ;AAAA,MAChB,yBAAyB;AAAA,MACzB,aAAa;AAAA,IACf,CAAC;AAAA,EACH;AAEA,QAAM,kBAAkB,MACtB,YAAY;AAAA,IACV,cAAc,QAAQ;AAAA,IACtB,aAAa;AAAA,IACb,yBAAyB;AAAA,IACzB,aAAa;AAAA,EACf,CAAC;AAEH,QAAM,kBAAkB,CACtB,gBACA,WAA+B,CAAC,MAEhC,IAAI,wBAAwB,gBAAgB,UAAU;AAAA,IACpD,UAAU;AAAA,IACV,SAAS;AAAA,IACT,KAAK,CAAC,EAAE,MAAM,QAAQ,MACpB,WAAW,gBAAgB,CAAC,wCAAwC,OAAO,GAAG,IAAI;AAAA,IACpF,eAAe;AAAA,EACjB,CAAC;AAEH,QAAM,WAAW,SACf,cACA,UACA;AACA,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,gBAAgB,cAAc,QAA8B;AAAA,EACrE;AAEA,WAAS,OAAO;AAEhB,SAAO;AACT;AAKO,IAAM,QAAQ,YAAY,CAAC,CAAC;","names":[]}
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@ai-sdk/azure",
3
+ "version": "0.0.1",
4
+ "license": "Apache-2.0",
5
+ "sideEffects": false,
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.mjs",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist/**/*"
11
+ ],
12
+ "exports": {
13
+ "./package.json": "./package.json",
14
+ ".": {
15
+ "types": "./dist/index.d.ts",
16
+ "import": "./dist/index.mjs",
17
+ "require": "./dist/index.js"
18
+ }
19
+ },
20
+ "dependencies": {
21
+ "@ai-sdk/openai": "0.0.25",
22
+ "@ai-sdk/provider": "0.0.10",
23
+ "@ai-sdk/provider-utils": "0.0.13"
24
+ },
25
+ "devDependencies": {
26
+ "@types/node": "^18",
27
+ "tsup": "^8",
28
+ "typescript": "5.1.3",
29
+ "zod": "3.23.8",
30
+ "@vercel/ai-tsconfig": "0.0.0"
31
+ },
32
+ "peerDependencies": {
33
+ "zod": "^3.0.0"
34
+ },
35
+ "engines": {
36
+ "node": ">=18"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "homepage": "https://sdk.vercel.ai/docs",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/vercel/ai.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/vercel/ai/issues"
48
+ },
49
+ "keywords": [
50
+ "ai"
51
+ ],
52
+ "scripts": {
53
+ "build": "tsup",
54
+ "clean": "rm -rf dist",
55
+ "dev": "tsup --watch",
56
+ "lint": "eslint \"./**/*.ts*\"",
57
+ "type-check": "tsc --noEmit",
58
+ "prettier-check": "prettier --check \"./**/*.ts*\"",
59
+ "test": "pnpm test:node && pnpm test:edge",
60
+ "test:edge": "vitest --config vitest.edge.config.js --run",
61
+ "test:node": "vitest --config vitest.node.config.js --run"
62
+ }
63
+ }