@core-ai/azure-openai 0.10.3
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 +21 -0
- package/README.md +67 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +38 -0
- package/package.json +61 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Omnifact (https://omnifact.ai)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# @core-ai/azure-openai
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@core-ai/azure-openai)
|
|
4
|
+
|
|
5
|
+
Azure OpenAI provider package for `@core-ai/core-ai`. It uses the Azure OpenAI v1 Chat Completions API by default and can opt into the classic API.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @core-ai/core-ai @core-ai/azure-openai zod
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { generate } from '@core-ai/core-ai';
|
|
17
|
+
import { createAzureOpenAI } from '@core-ai/azure-openai';
|
|
18
|
+
|
|
19
|
+
const azure = createAzureOpenAI({
|
|
20
|
+
apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
21
|
+
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
// Use your Azure OpenAI deployment name as the model id.
|
|
25
|
+
const model = azure.chatModel('gpt-5-mini-deployment');
|
|
26
|
+
|
|
27
|
+
const result = await generate({
|
|
28
|
+
model,
|
|
29
|
+
messages: [{ role: 'user', content: 'Hello!' }],
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
console.log(result.content);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Authentication
|
|
36
|
+
|
|
37
|
+
Use an Azure OpenAI API key with the v1 API:
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const azure = createAzureOpenAI({
|
|
41
|
+
apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
42
|
+
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Set `api: 'classic'` to use the classic Azure API surface:
|
|
47
|
+
|
|
48
|
+
```ts
|
|
49
|
+
const azure = createAzureOpenAI({
|
|
50
|
+
api: 'classic',
|
|
51
|
+
apiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
52
|
+
endpoint: process.env.AZURE_OPENAI_ENDPOINT,
|
|
53
|
+
apiVersion: '2025-04-01-preview',
|
|
54
|
+
});
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Classic mode also accepts an Entra ID token provider via `azureADTokenProvider`.
|
|
58
|
+
|
|
59
|
+
## Model IDs
|
|
60
|
+
|
|
61
|
+
Pass your Azure OpenAI deployment name to `chatModel()`. The provider sends it as the Chat Completions `model` field.
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const model = azure.chatModel('customer-support-gpt-5-mini');
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
This package supports chat models only. Use `@core-ai/openai` for OpenAI Responses API, embeddings, and image generation.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ChatModel } from '@core-ai/core-ai';
|
|
2
|
+
import { OpenAIChatClient } from '@core-ai/openai/compat';
|
|
3
|
+
|
|
4
|
+
type AzureOpenAIV1Options = {
|
|
5
|
+
api?: 'v1';
|
|
6
|
+
apiKey?: string;
|
|
7
|
+
endpoint?: string;
|
|
8
|
+
client?: OpenAIChatClient;
|
|
9
|
+
};
|
|
10
|
+
type AzureOpenAIClassicOptions = {
|
|
11
|
+
api: 'classic';
|
|
12
|
+
apiKey?: string;
|
|
13
|
+
endpoint?: string;
|
|
14
|
+
apiVersion: string;
|
|
15
|
+
deployment?: string;
|
|
16
|
+
azureADTokenProvider?: () => Promise<string>;
|
|
17
|
+
client?: OpenAIChatClient;
|
|
18
|
+
};
|
|
19
|
+
type AzureOpenAIProviderOptions = AzureOpenAIV1Options | AzureOpenAIClassicOptions;
|
|
20
|
+
type AzureOpenAIProvider = {
|
|
21
|
+
chatModel(modelId: string): ChatModel;
|
|
22
|
+
};
|
|
23
|
+
declare function createAzureOpenAI(options?: AzureOpenAIProviderOptions): AzureOpenAIProvider;
|
|
24
|
+
|
|
25
|
+
export { type AzureOpenAIProvider, type AzureOpenAIProviderOptions, createAzureOpenAI };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/provider.ts
|
|
2
|
+
import OpenAI, { AzureOpenAI } from "openai";
|
|
3
|
+
import {
|
|
4
|
+
createOpenAICompatChatProvider
|
|
5
|
+
} from "@core-ai/openai/compat";
|
|
6
|
+
var PROVIDER_ID = "azure-openai";
|
|
7
|
+
function createAzureOpenAI(options = {}) {
|
|
8
|
+
const client = options.client ?? createAzureOpenAIClient(options);
|
|
9
|
+
return createOpenAICompatChatProvider({ client }, PROVIDER_ID);
|
|
10
|
+
}
|
|
11
|
+
function createAzureOpenAIClient(options) {
|
|
12
|
+
if (options.api === "classic") {
|
|
13
|
+
return new AzureOpenAI({
|
|
14
|
+
apiKey: options.apiKey,
|
|
15
|
+
endpoint: options.endpoint,
|
|
16
|
+
apiVersion: options.apiVersion,
|
|
17
|
+
deployment: options.deployment,
|
|
18
|
+
azureADTokenProvider: options.azureADTokenProvider
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return new OpenAI({
|
|
22
|
+
apiKey: options.apiKey,
|
|
23
|
+
baseURL: getAzureOpenAIV1BaseURL(options.endpoint)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function getAzureOpenAIV1BaseURL(endpoint) {
|
|
27
|
+
if (!endpoint) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const baseURL = endpoint.replace(/\/+$/, "");
|
|
31
|
+
if (baseURL.endsWith("/openai/v1")) {
|
|
32
|
+
return baseURL;
|
|
33
|
+
}
|
|
34
|
+
return `${baseURL}/openai/v1`;
|
|
35
|
+
}
|
|
36
|
+
export {
|
|
37
|
+
createAzureOpenAI
|
|
38
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@core-ai/azure-openai",
|
|
3
|
+
"version": "0.10.3",
|
|
4
|
+
"description": "Azure OpenAI provider package for @core-ai/core-ai",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Omnifact (https://omnifact.ai)",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/agdevhq/core-ai.git",
|
|
10
|
+
"directory": "packages/azure-openai"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"llm",
|
|
14
|
+
"ai",
|
|
15
|
+
"azure",
|
|
16
|
+
"azure-openai",
|
|
17
|
+
"openai",
|
|
18
|
+
"provider",
|
|
19
|
+
"sdk"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"import": "./dist/index.js"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"dist",
|
|
32
|
+
"README.md",
|
|
33
|
+
"LICENSE"
|
|
34
|
+
],
|
|
35
|
+
"publishConfig": {
|
|
36
|
+
"access": "public",
|
|
37
|
+
"provenance": true
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"lint": "eslint src/ --max-warnings 0",
|
|
42
|
+
"check-types": "tsc --noEmit",
|
|
43
|
+
"test": "vitest run",
|
|
44
|
+
"test:watch": "vitest"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@core-ai/core-ai": "^0.10.3",
|
|
48
|
+
"@core-ai/openai": "^0.10.3",
|
|
49
|
+
"openai": "^6.1.0"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"zod": "^4.0.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@core-ai/eslint-config": "*",
|
|
56
|
+
"@core-ai/testing": "*",
|
|
57
|
+
"@core-ai/typescript-config": "*",
|
|
58
|
+
"typescript": "^5.7.3",
|
|
59
|
+
"vitest": "^3.2.4"
|
|
60
|
+
}
|
|
61
|
+
}
|