@sixb/azure-ai-foundry 0.1.1 → 0.1.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/README.md +44 -2
- package/dist/catalog.d.ts +8 -0
- package/dist/catalog.d.ts.map +1 -1
- package/dist/embedding.d.ts +31 -0
- package/dist/embedding.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +275 -28
- package/dist/index.js.map +7 -6
- package/dist/provider.d.ts +4 -0
- package/dist/provider.d.ts.map +1 -1
- package/dist/transport.d.ts +3 -3
- package/dist/transport.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/catalog.ts +43 -4
- package/src/embedding.ts +377 -0
- package/src/index.ts +5 -0
- package/src/provider.ts +51 -1
- package/src/transport.ts +19 -9
package/dist/provider.d.ts
CHANGED
|
@@ -2,10 +2,13 @@ import { type LanguageModel, type LanguageModelDefinition, type LanguageModelPro
|
|
|
2
2
|
import { type AzureAIFoundryCatalogOptions } from "./catalog";
|
|
3
3
|
import { type ChatRequestOptions } from "./chat-request";
|
|
4
4
|
import { type AzureAIFoundryCatalog, type AzureAIFoundryDeployment, type AzureAIFoundryDiscoveryOptions } from "./discovery";
|
|
5
|
+
import { type AzureAIFoundryEmbeddingModel, type AzureAIFoundryEmbeddingOptions, type AzureAIFoundryEmbeddingTransportOptions } from "./embedding";
|
|
5
6
|
import { type MessagesRequestOptions } from "./messages-request";
|
|
6
7
|
import { type RequestOptions } from "./request";
|
|
7
8
|
import { type FoundryProtocol, type TransportOptions } from "./transport";
|
|
8
9
|
export interface AzureAIFoundryOptions extends TransportOptions {
|
|
10
|
+
/** Explicit resource transport: project endpoints do not route embeddings. */
|
|
11
|
+
readonly embeddings?: AzureAIFoundryEmbeddingTransportOptions;
|
|
9
12
|
/** Public model capabilities and reference pricing from models.dev. */
|
|
10
13
|
readonly catalog?: AzureAIFoundryCatalogOptions;
|
|
11
14
|
/** Namespace bindings from different resources/projects in a single Sixb catalog. */
|
|
@@ -57,6 +60,7 @@ export interface AzureAIFoundryProvider extends LanguageModelProvider {
|
|
|
57
60
|
(deploymentName: string, options?: AzureAIFoundryModelOptions): AzureAIFoundryModel;
|
|
58
61
|
responses(deploymentName: string, options?: AzureAIFoundryModelOptions): AzureAIFoundryModel<"responses">;
|
|
59
62
|
messages(deploymentName: string, options?: AzureAIFoundryMessagesOptions): AzureAIFoundryModel<"messages">;
|
|
63
|
+
embedding(deploymentName: string, options: AzureAIFoundryEmbeddingOptions): AzureAIFoundryEmbeddingModel;
|
|
60
64
|
readonly catalog: AzureAIFoundryCatalog;
|
|
61
65
|
chat(deploymentName: string, options?: AzureAIFoundryChatOptions): AzureAIFoundryModel<"chat">;
|
|
62
66
|
}
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,qBAAqB,EAK1B,KAAK,kBAAkB,EAGxB,MAAM,mBAAmB,CAAA;AAK1B,OAAO,EACL,KAAK,4BAA4B,EAGlC,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,KAAK,kBAAkB,EAA2C,MAAM,gBAAgB,CAAA;AACjG,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,wBAAwB,EAC7B,KAAK,8BAA8B,EAGpC,MAAM,aAAa,CAAA;AAEpB,OAAO,EAEL,KAAK,sBAAsB,EAE5B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,KAAK,cAAc,EAAqC,MAAM,WAAW,CAAA;AAElF,OAAO,EAEL,KAAK,eAAe,EAGpB,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAA;AAGpB,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC7D,uEAAuE;IACvE,QAAQ,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|
private readonly options;
|
|
18
|
-
constructor(options: TransportOptions);
|
|
19
|
-
post(body: string, signal: AbortSignal, providerId: string, modelId: string, protocol?: FoundryProtocol): Promise<Response>;
|
|
18
|
+
constructor(options: TransportOptions, target?: "project" | "resource");
|
|
19
|
+
post(body: string, signal: AbortSignal, providerId: string, modelId: string, protocol?: FoundryProtocol | "embeddings"): Promise<Response>;
|
|
20
20
|
redactText(response: Response, value: string | undefined): string | undefined;
|
|
21
21
|
redactError(response: Response, error: ModelProviderError): ModelProviderError;
|
|
22
22
|
redactFailure(response: Response, error: unknown): unknown;
|
|
23
23
|
headers(signal: AbortSignal, diagnostics: RequestDiagnostics, keyHeader?: "api-key" | "x-api-key"): Promise<Headers>;
|
|
24
24
|
fetch(url: string, init: RequestInit): Promise<Response>;
|
|
25
|
-
url(protocol: FoundryProtocol): string;
|
|
25
|
+
url(protocol: FoundryProtocol | "embeddings"): string;
|
|
26
26
|
}
|
|
27
27
|
export declare function requestId(response: Response): string | undefined;
|
|
28
28
|
/** Bound credential/transport work even when an injected implementation ignores the signal. */
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAGlD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,WAAW,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAC1E,MAAM,MAAM,eAAe,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAA;AAE/D,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,GAAG,SAAS,CAAC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,QAAQ,EAAE,eAAe,GAAG,YAAY,GAAG,MAAM;CAMtD;AAED,wBAAgB,SAAS,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAOhE;AAWD,+FAA+F;AAC/F,wBAAgB,SAAS,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,CAgB7F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/azure-ai-foundry",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Azure AI Foundry model provider for Sixb",
|
|
5
5
|
"homepage": "https://sixb.ai",
|
|
6
6
|
"bugs": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"prepack": "bun run build"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@sixb/core": "^0.1.
|
|
34
|
+
"@sixb/core": "^0.1.16",
|
|
35
35
|
"@sixb/model-protocols": "0.1.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
package/src/catalog.ts
CHANGED
|
@@ -18,6 +18,7 @@ export interface AzureAIFoundryCatalogOptions {
|
|
|
18
18
|
readonly fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>
|
|
19
19
|
}
|
|
20
20
|
export interface CatalogModel {
|
|
21
|
+
readonly kind: "language"
|
|
21
22
|
readonly catalogProvider: "azure" | "fireworks-ai"
|
|
22
23
|
readonly modelName: string
|
|
23
24
|
readonly protocol?: FoundryProtocol
|
|
@@ -25,11 +26,20 @@ export interface CatalogModel {
|
|
|
25
26
|
readonly rateCard?: LanguageModelRateCard
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
export interface CatalogEmbeddingModel {
|
|
30
|
+
readonly kind: "embedding"
|
|
31
|
+
readonly catalogProvider: "azure" | "fireworks-ai"
|
|
32
|
+
readonly modelName: string
|
|
33
|
+
readonly rateCard?: LanguageModelRateCard
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type CatalogEntry = CatalogModel | CatalogEmbeddingModel
|
|
37
|
+
|
|
28
38
|
/** Provider-scoped models.dev snapshot. Construction and offline reads never perform I/O. */
|
|
29
39
|
export class RemoteModelsDevCatalog {
|
|
30
|
-
private snapshot: readonly
|
|
40
|
+
private snapshot: readonly CatalogEntry[] = []
|
|
31
41
|
private loadedAt = 0
|
|
32
|
-
private pending?: Promise<readonly
|
|
42
|
+
private pending?: Promise<readonly CatalogEntry[]>
|
|
33
43
|
private readonly options: AzureAIFoundryCatalogOptions
|
|
34
44
|
constructor(options: AzureAIFoundryCatalogOptions = {}) {
|
|
35
45
|
this.options = { ...options }
|
|
@@ -49,9 +59,21 @@ export class RemoteModelsDevCatalog {
|
|
|
49
59
|
async get(name: string, offline = false): Promise<CatalogModel | undefined> {
|
|
50
60
|
return (await this.lookup(offline))(name)
|
|
51
61
|
}
|
|
62
|
+
async getEmbedding(name: string, offline = false): Promise<CatalogEmbeddingModel | undefined> {
|
|
63
|
+
const models = offline ? this.snapshot : await this.load()
|
|
64
|
+
const matches = models.filter(
|
|
65
|
+
(m): m is CatalogEmbeddingModel =>
|
|
66
|
+
m.kind === "embedding" &&
|
|
67
|
+
m.catalogProvider === "azure" &&
|
|
68
|
+
m.modelName.toLowerCase() === name.toLowerCase()
|
|
69
|
+
)
|
|
70
|
+
return matches.length === 1 ? matches[0] : undefined
|
|
71
|
+
}
|
|
52
72
|
/** Capture one snapshot so a batch of lookups cannot expire between deployments. */
|
|
53
73
|
async lookup(offline = false): Promise<(name: string) => CatalogModel | undefined> {
|
|
54
|
-
const models = offline ? this.snapshot : await this.load()
|
|
74
|
+
const models = (offline ? this.snapshot : await this.load()).filter(
|
|
75
|
+
(m): m is CatalogModel => m.kind === "language"
|
|
76
|
+
)
|
|
55
77
|
return (name) => {
|
|
56
78
|
// Azure deployment names preserve publisher casing; models.dev IDs are lowercase.
|
|
57
79
|
// Only a unique exact case-insensitive ID match is accepted, never fuzzy name matching.
|
|
@@ -126,11 +148,27 @@ export class RemoteModelsDevCatalog {
|
|
|
126
148
|
const models = object(object(providerData)?.models)
|
|
127
149
|
if (!models)
|
|
128
150
|
throw new TypeError(`${PREFIX} models.dev response is missing ${catalogProvider}.models.`)
|
|
129
|
-
return Object.entries(models).flatMap(([id, value]) => {
|
|
151
|
+
return Object.entries(models).flatMap<CatalogEntry>(([id, value]) => {
|
|
130
152
|
const raw = object(value)
|
|
131
153
|
if (!raw || raw.id !== id)
|
|
132
154
|
throw new TypeError(`${PREFIX} Invalid models.dev model identity.`)
|
|
133
155
|
const modalities = object(raw.modalities)
|
|
156
|
+
if (
|
|
157
|
+
raw.type === "embedding" ||
|
|
158
|
+
raw.family === "text-embedding" ||
|
|
159
|
+
raw.family === "cohere-embed" ||
|
|
160
|
+
/^(text-embedding-|cohere-embed)/i.test(id) ||
|
|
161
|
+
strings(modalities?.output).includes("embedding")
|
|
162
|
+
) {
|
|
163
|
+
return [
|
|
164
|
+
{
|
|
165
|
+
kind: "embedding",
|
|
166
|
+
catalogProvider,
|
|
167
|
+
modelName: id,
|
|
168
|
+
rateCard: rates(object(raw.cost), undefined),
|
|
169
|
+
},
|
|
170
|
+
]
|
|
171
|
+
}
|
|
134
172
|
if (!strings(modalities?.output).includes("text")) return []
|
|
135
173
|
const limits = object(raw.limit)
|
|
136
174
|
const provider = object(raw.provider)
|
|
@@ -144,6 +182,7 @@ export class RemoteModelsDevCatalog {
|
|
|
144
182
|
: undefined
|
|
145
183
|
return [
|
|
146
184
|
{
|
|
185
|
+
kind: "language",
|
|
147
186
|
catalogProvider,
|
|
148
187
|
modelName: id,
|
|
149
188
|
protocol,
|
package/src/embedding.ts
ADDED
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineModelRateCard,
|
|
3
|
+
type EmbeddingModel,
|
|
4
|
+
type EmbeddingModelDefinition,
|
|
5
|
+
type EmbeddingModelRequest,
|
|
6
|
+
EmbeddingModelResponseError,
|
|
7
|
+
type EmbeddingModelResponseMetadata,
|
|
8
|
+
type EmbeddingModelResult,
|
|
9
|
+
type JsonObject,
|
|
10
|
+
type LanguageModelRateCard,
|
|
11
|
+
ModelCatalogUnavailableError,
|
|
12
|
+
type ModelCostEstimator,
|
|
13
|
+
type ModelUsage,
|
|
14
|
+
UnsupportedModelFeatureError,
|
|
15
|
+
} from "@sixb/core/models"
|
|
16
|
+
import { tokenEstimator } from "./accounting"
|
|
17
|
+
import type { CatalogEmbeddingModel, RemoteModelsDevCatalog } from "./catalog"
|
|
18
|
+
import type { AzureAIFoundryDeployment, FoundryDeployments, ResolvedDeployment } from "./discovery"
|
|
19
|
+
import type { AzureAIFoundryModelMetadata } from "./provider"
|
|
20
|
+
import { abortable, type FoundryTransport, requestId, type TransportOptions } from "./transport"
|
|
21
|
+
import { counter, object, PREFIX } from "./util"
|
|
22
|
+
|
|
23
|
+
export type AzureAIFoundryEmbeddingTransportOptions = Pick<
|
|
24
|
+
TransportOptions,
|
|
25
|
+
"endpoint" | "apiKey" | "headers" | "fetch"
|
|
26
|
+
>
|
|
27
|
+
|
|
28
|
+
export interface AzureAIFoundryEmbeddingOptions {
|
|
29
|
+
/** Pin the actual model behind the deployment; discovery must match before inference. */
|
|
30
|
+
readonly model: { readonly name: string; readonly version: string }
|
|
31
|
+
/** Expected output size; sent to text-embedding-3 models, validated locally for ada-002. */
|
|
32
|
+
readonly dimensions: number
|
|
33
|
+
readonly rateCard?: LanguageModelRateCard
|
|
34
|
+
readonly costEstimator?: ModelCostEstimator
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface AzureAIFoundryEmbeddingModel extends EmbeddingModel {
|
|
38
|
+
readonly metadata: AzureAIFoundryModelMetadata
|
|
39
|
+
resolve(options?: { readonly offline?: boolean }): Promise<AzureAIFoundryEmbeddingModel>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface EmbeddingResolution extends ResolvedDeployment {
|
|
43
|
+
readonly costEstimator: ModelCostEstimator
|
|
44
|
+
readonly configurableDimensions: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Discovery uses project credentials; inference uses only the explicit resource transport. */
|
|
48
|
+
export function createFoundryEmbedding(
|
|
49
|
+
providerId: string,
|
|
50
|
+
modelId: string,
|
|
51
|
+
options: AzureAIFoundryEmbeddingOptions,
|
|
52
|
+
transport: FoundryTransport,
|
|
53
|
+
deployments: FoundryDeployments,
|
|
54
|
+
catalog: RemoteModelsDevCatalog,
|
|
55
|
+
resolution?: EmbeddingResolution
|
|
56
|
+
): AzureAIFoundryEmbeddingModel {
|
|
57
|
+
const dimensions = options.dimensions
|
|
58
|
+
const expected = options.model
|
|
59
|
+
if (
|
|
60
|
+
!expected ||
|
|
61
|
+
[expected.name, expected.version].some(
|
|
62
|
+
(value) => typeof value !== "string" || !value || value.trim() !== value
|
|
63
|
+
)
|
|
64
|
+
) {
|
|
65
|
+
throw new TypeError(
|
|
66
|
+
`${PREFIX} Embedding deployments require an expected model name and version.`
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
const representation = Object.freeze({ name: expected.name, version: expected.version })
|
|
70
|
+
const definition = Object.freeze({
|
|
71
|
+
kind: "embedding" as const,
|
|
72
|
+
providerId,
|
|
73
|
+
modelId,
|
|
74
|
+
dimensions,
|
|
75
|
+
representation,
|
|
76
|
+
})
|
|
77
|
+
if (
|
|
78
|
+
!modelId ||
|
|
79
|
+
modelId.trim() !== modelId ||
|
|
80
|
+
!Number.isSafeInteger(dimensions) ||
|
|
81
|
+
dimensions < 1 ||
|
|
82
|
+
dimensions > 16000
|
|
83
|
+
)
|
|
84
|
+
throw new TypeError(
|
|
85
|
+
`${PREFIX} Embedding models require a nonempty deployment name and dimensions between 1 and 16000.`
|
|
86
|
+
)
|
|
87
|
+
if (options.rateCard && options.costEstimator)
|
|
88
|
+
throw new TypeError(`${PREFIX} Configure either rateCard or costEstimator, not both.`)
|
|
89
|
+
const settings = Object.freeze({
|
|
90
|
+
model: representation,
|
|
91
|
+
dimensions,
|
|
92
|
+
rateCard: options.rateCard && defineModelRateCard(options.rateCard),
|
|
93
|
+
costEstimator: options.costEstimator,
|
|
94
|
+
})
|
|
95
|
+
const deployment = resolution?.deployment
|
|
96
|
+
const metadata = Object.freeze(
|
|
97
|
+
deployment
|
|
98
|
+
? {
|
|
99
|
+
deployment,
|
|
100
|
+
modelName: deployment.modelName,
|
|
101
|
+
modelVersion: deployment.modelVersion,
|
|
102
|
+
publisher: deployment.modelPublisher,
|
|
103
|
+
sku: deployment.sku.name,
|
|
104
|
+
discoveredAt: resolution.discoveredAt,
|
|
105
|
+
}
|
|
106
|
+
: {}
|
|
107
|
+
)
|
|
108
|
+
let pending: Promise<AzureAIFoundryEmbeddingModel> | undefined
|
|
109
|
+
const binding: AzureAIFoundryEmbeddingModel = Object.freeze({
|
|
110
|
+
providerId,
|
|
111
|
+
modelId,
|
|
112
|
+
definition,
|
|
113
|
+
// OpenAI byte-level tokenization emits at most one token per UTF-8 byte.
|
|
114
|
+
// These conservative bounds avoid requiring a tokenizer for projection batching.
|
|
115
|
+
batching: Object.freeze({ maxInputs: 2048, maxInputBytes: 8191, maxTotalInputBytes: 300000 }),
|
|
116
|
+
metadata,
|
|
117
|
+
costEstimator: resolution?.costEstimator,
|
|
118
|
+
async resolve(input?: { readonly offline?: boolean }) {
|
|
119
|
+
if (resolution) return binding
|
|
120
|
+
const resolved = await deployments.resolve(modelId, input?.offline === true)
|
|
121
|
+
if (
|
|
122
|
+
resolved.deployment.modelName !== representation.name ||
|
|
123
|
+
resolved.deployment.modelVersion !== representation.version
|
|
124
|
+
) {
|
|
125
|
+
throw new TypeError(
|
|
126
|
+
`${PREFIX} Embedding deployment '${modelId}' resolved to ${resolved.deployment.modelName}@${resolved.deployment.modelVersion}; expected ${representation.name}@${representation.version}.`
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
const configurableDimensions = validateDeployment(resolved, dimensions)
|
|
130
|
+
let entry: CatalogEmbeddingModel | undefined
|
|
131
|
+
try {
|
|
132
|
+
entry = await catalog.getEmbedding(resolved.deployment.modelName, input?.offline)
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (!(error instanceof ModelCatalogUnavailableError)) throw error
|
|
135
|
+
entry = await catalog.getEmbedding(resolved.deployment.modelName, true)
|
|
136
|
+
console.warn(
|
|
137
|
+
`${PREFIX} Embedding pricing catalog unavailable; using cached or explicit pricing when available.`
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
const costEstimator =
|
|
141
|
+
settings.costEstimator ??
|
|
142
|
+
tokenEstimator(
|
|
143
|
+
settings.rateCard ?? entry?.rateCard,
|
|
144
|
+
undefined,
|
|
145
|
+
[],
|
|
146
|
+
(raw) =>
|
|
147
|
+
!raw ||
|
|
148
|
+
Object.keys(raw).every(
|
|
149
|
+
(key) =>
|
|
150
|
+
["prompt_tokens", "total_tokens"].includes(key) && counter(raw[key]) !== undefined
|
|
151
|
+
),
|
|
152
|
+
resolved.deployment.modelName,
|
|
153
|
+
resolved.deployment.modelVersion,
|
|
154
|
+
[
|
|
155
|
+
modelId,
|
|
156
|
+
resolved.deployment.modelName,
|
|
157
|
+
`${resolved.deployment.modelName}-${resolved.deployment.modelVersion}`,
|
|
158
|
+
]
|
|
159
|
+
)
|
|
160
|
+
return createFoundryEmbedding(
|
|
161
|
+
providerId,
|
|
162
|
+
modelId,
|
|
163
|
+
settings,
|
|
164
|
+
transport,
|
|
165
|
+
deployments,
|
|
166
|
+
catalog,
|
|
167
|
+
{
|
|
168
|
+
...resolved,
|
|
169
|
+
configurableDimensions,
|
|
170
|
+
costEstimator,
|
|
171
|
+
}
|
|
172
|
+
)
|
|
173
|
+
},
|
|
174
|
+
async embed(input: EmbeddingModelRequest): Promise<EmbeddingModelResult> {
|
|
175
|
+
const signal = input.signal ?? AbortSignal.timeout(30_000)
|
|
176
|
+
signal.throwIfAborted()
|
|
177
|
+
if (
|
|
178
|
+
!Array.isArray(input.texts) ||
|
|
179
|
+
input.texts.length > 2048 ||
|
|
180
|
+
Array.from(input.texts).some((text) => typeof text !== "string" || !text.trim())
|
|
181
|
+
)
|
|
182
|
+
throw new TypeError(
|
|
183
|
+
`${PREFIX} Embedding inputs must contain at most 2048 nonempty strings.`
|
|
184
|
+
)
|
|
185
|
+
const texts = [...input.texts]
|
|
186
|
+
if (!texts.length) return { vectors: [] }
|
|
187
|
+
if (!resolution) {
|
|
188
|
+
pending ??= binding.resolve().catch((error) => {
|
|
189
|
+
pending = undefined
|
|
190
|
+
throw error
|
|
191
|
+
})
|
|
192
|
+
const resolved = await abortable(() => pending!, signal)
|
|
193
|
+
return resolved.embed({ texts, purpose: input.purpose, signal })
|
|
194
|
+
}
|
|
195
|
+
const response = await transport.post(
|
|
196
|
+
JSON.stringify({
|
|
197
|
+
model: modelId,
|
|
198
|
+
input: texts,
|
|
199
|
+
encoding_format: "float",
|
|
200
|
+
...(resolution.configurableDimensions ? { dimensions } : {}),
|
|
201
|
+
}),
|
|
202
|
+
signal,
|
|
203
|
+
providerId,
|
|
204
|
+
modelId,
|
|
205
|
+
"embeddings"
|
|
206
|
+
)
|
|
207
|
+
return readEmbeddingResult(response, transport, signal, {
|
|
208
|
+
...definition,
|
|
209
|
+
count: texts.length,
|
|
210
|
+
deployment: resolution.deployment,
|
|
211
|
+
})
|
|
212
|
+
},
|
|
213
|
+
})
|
|
214
|
+
return binding
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function validateDeployment(resolved: ResolvedDeployment, dimensions: number): boolean {
|
|
218
|
+
const deployment = resolved.deployment
|
|
219
|
+
const name = deployment.modelName.toLowerCase()
|
|
220
|
+
const maxDimensions =
|
|
221
|
+
name === "text-embedding-3-small"
|
|
222
|
+
? 1536
|
|
223
|
+
: name === "text-embedding-3-large"
|
|
224
|
+
? 3072
|
|
225
|
+
: name === "text-embedding-ada-002"
|
|
226
|
+
? 1536
|
|
227
|
+
: undefined
|
|
228
|
+
if (
|
|
229
|
+
deployment.modelPublisher.toLowerCase() !== "openai" ||
|
|
230
|
+
!maxDimensions ||
|
|
231
|
+
deployment.capabilities.embeddings === "false" ||
|
|
232
|
+
deployment.capabilities.embedding === "false"
|
|
233
|
+
)
|
|
234
|
+
throw new UnsupportedModelFeatureError(
|
|
235
|
+
`${PREFIX} This embedding deployment is not supported. Use an OpenAI text-embedding-3-small, text-embedding-3-large, or text-embedding-ada-002 deployment.`
|
|
236
|
+
)
|
|
237
|
+
const configurable = name !== "text-embedding-ada-002"
|
|
238
|
+
if (dimensions > maxDimensions || (!configurable && dimensions !== maxDimensions))
|
|
239
|
+
throw new TypeError(
|
|
240
|
+
`${PREFIX} ${name} requires ${configurable ? `1–${maxDimensions}` : maxDimensions} dimensions.`
|
|
241
|
+
)
|
|
242
|
+
return configurable
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function parseVectors(
|
|
246
|
+
data: unknown,
|
|
247
|
+
count: number,
|
|
248
|
+
dimensions: number,
|
|
249
|
+
invalid: () => Error
|
|
250
|
+
): number[][] {
|
|
251
|
+
if (!Array.isArray(data) || data.length !== count) throw invalid()
|
|
252
|
+
const vectors: number[][] = new Array(count)
|
|
253
|
+
for (const value of data) {
|
|
254
|
+
const entry = record(value)
|
|
255
|
+
const index = counter(entry?.index)
|
|
256
|
+
const embedding = entry?.embedding
|
|
257
|
+
if (
|
|
258
|
+
index === undefined ||
|
|
259
|
+
index >= count ||
|
|
260
|
+
vectors[index] !== undefined ||
|
|
261
|
+
!Array.isArray(embedding) ||
|
|
262
|
+
embedding.length !== dimensions
|
|
263
|
+
)
|
|
264
|
+
throw invalid()
|
|
265
|
+
const vector: number[] = []
|
|
266
|
+
for (const n of embedding) {
|
|
267
|
+
if (typeof n !== "number" || !Number.isFinite(Math.fround(n))) throw invalid()
|
|
268
|
+
vector.push(n)
|
|
269
|
+
}
|
|
270
|
+
if (!vector.some((n) => Math.fround(n) !== 0)) throw invalid()
|
|
271
|
+
vectors[index] = vector
|
|
272
|
+
}
|
|
273
|
+
return vectors
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function invalidResponse(
|
|
277
|
+
providerId: string,
|
|
278
|
+
modelId: string,
|
|
279
|
+
metadata: EmbeddingModelResponseMetadata
|
|
280
|
+
) {
|
|
281
|
+
return new EmbeddingModelResponseError(
|
|
282
|
+
`${PREFIX} Invalid embedding response: expected the resolved model and one finite, nonzero vector of the configured dimension per input, with unique indices.`,
|
|
283
|
+
providerId,
|
|
284
|
+
modelId,
|
|
285
|
+
metadata
|
|
286
|
+
)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
async function readResponse(response: Response, signal: AbortSignal): Promise<unknown> {
|
|
290
|
+
const reader = response.body?.getReader()
|
|
291
|
+
if (!reader) throw new Error("Empty embedding response")
|
|
292
|
+
const chunks: Uint8Array[] = []
|
|
293
|
+
let bytes = 0
|
|
294
|
+
try {
|
|
295
|
+
for (;;) {
|
|
296
|
+
const chunk = await abortable(() => reader.read(), signal)
|
|
297
|
+
if (chunk.done) break
|
|
298
|
+
bytes += chunk.value.length
|
|
299
|
+
if (bytes > 128 * 1024 * 1024) throw new Error("Embedding response exceeds 128 MiB")
|
|
300
|
+
chunks.push(chunk.value)
|
|
301
|
+
}
|
|
302
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"))
|
|
303
|
+
} finally {
|
|
304
|
+
void reader.cancel().catch(() => {})
|
|
305
|
+
reader.releaseLock()
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function embeddingUsage(raw: JsonObject | undefined): ModelUsage {
|
|
310
|
+
const inputTokens = counter(raw?.prompt_tokens)
|
|
311
|
+
const totalTokens = counter(raw?.total_tokens)
|
|
312
|
+
const knownInput =
|
|
313
|
+
inputTokens !== undefined && (raw?.total_tokens === undefined || totalTokens === inputTokens)
|
|
314
|
+
// Retain numeric billing evidence only; unexpected meters prevent automatic pricing.
|
|
315
|
+
const unsupported =
|
|
316
|
+
raw &&
|
|
317
|
+
Object.entries(raw).some(
|
|
318
|
+
([key, value]) =>
|
|
319
|
+
!["prompt_tokens", "total_tokens"].includes(key) || counter(value) === undefined
|
|
320
|
+
)
|
|
321
|
+
return {
|
|
322
|
+
...(knownInput ? { inputTokens, uncachedInputTokens: inputTokens } : {}),
|
|
323
|
+
outputTokens: 0,
|
|
324
|
+
...(raw
|
|
325
|
+
? {
|
|
326
|
+
raw: {
|
|
327
|
+
...(inputTokens === undefined ? {} : { prompt_tokens: inputTokens }),
|
|
328
|
+
...(totalTokens === undefined ? {} : { total_tokens: totalTokens }),
|
|
329
|
+
...(unsupported ? { unsupported: true } : {}),
|
|
330
|
+
},
|
|
331
|
+
}
|
|
332
|
+
: {}),
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function record(value: unknown): Record<string, unknown> | undefined {
|
|
337
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
338
|
+
? (value as Record<string, unknown>)
|
|
339
|
+
: undefined
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async function readEmbeddingResult(
|
|
343
|
+
response: Response,
|
|
344
|
+
transport: FoundryTransport,
|
|
345
|
+
signal: AbortSignal,
|
|
346
|
+
expected: EmbeddingModelDefinition & { count: number; deployment: AzureAIFoundryDeployment }
|
|
347
|
+
): Promise<EmbeddingModelResult> {
|
|
348
|
+
const { providerId, modelId, dimensions } = expected
|
|
349
|
+
const facts: EmbeddingModelResponseMetadata = {
|
|
350
|
+
providerIds: { requestId: transport.redactText(response, requestId(response)) },
|
|
351
|
+
}
|
|
352
|
+
let body: Record<string, unknown> | undefined
|
|
353
|
+
try {
|
|
354
|
+
body = record(await readResponse(response, signal))
|
|
355
|
+
} catch {
|
|
356
|
+
if (signal.aborted) throw signal.reason
|
|
357
|
+
throw invalidResponse(providerId, modelId, facts)
|
|
358
|
+
}
|
|
359
|
+
const resultMetadata: EmbeddingModelResponseMetadata = {
|
|
360
|
+
...facts,
|
|
361
|
+
usage: embeddingUsage(object(body?.usage)),
|
|
362
|
+
responseModelId:
|
|
363
|
+
typeof body?.model === "string" ? transport.redactText(response, body.model) : undefined,
|
|
364
|
+
}
|
|
365
|
+
const name = expected.deployment.modelName
|
|
366
|
+
if (
|
|
367
|
+
!body ||
|
|
368
|
+
![modelId, name, `${name}-${expected.deployment.modelVersion}`].includes(String(body.model))
|
|
369
|
+
)
|
|
370
|
+
throw invalidResponse(providerId, modelId, resultMetadata)
|
|
371
|
+
return {
|
|
372
|
+
...resultMetadata,
|
|
373
|
+
vectors: parseVectors(body.data, expected.count, dimensions, () =>
|
|
374
|
+
invalidResponse(providerId, modelId, resultMetadata)
|
|
375
|
+
),
|
|
376
|
+
}
|
|
377
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,11 @@ export type {
|
|
|
4
4
|
AzureAIFoundryDeployment,
|
|
5
5
|
AzureAIFoundryDiscoveryOptions,
|
|
6
6
|
} from "./discovery"
|
|
7
|
+
export type {
|
|
8
|
+
AzureAIFoundryEmbeddingModel,
|
|
9
|
+
AzureAIFoundryEmbeddingOptions,
|
|
10
|
+
AzureAIFoundryEmbeddingTransportOptions,
|
|
11
|
+
} from "./embedding"
|
|
7
12
|
export type {
|
|
8
13
|
AzureAIFoundryChatOptions,
|
|
9
14
|
AzureAIFoundryMessagesOptions,
|
package/src/provider.ts
CHANGED
|
@@ -31,6 +31,12 @@ import {
|
|
|
31
31
|
FoundryDeployments,
|
|
32
32
|
type ResolvedDeployment,
|
|
33
33
|
} from "./discovery"
|
|
34
|
+
import {
|
|
35
|
+
type AzureAIFoundryEmbeddingModel,
|
|
36
|
+
type AzureAIFoundryEmbeddingOptions,
|
|
37
|
+
type AzureAIFoundryEmbeddingTransportOptions,
|
|
38
|
+
createFoundryEmbedding,
|
|
39
|
+
} from "./embedding"
|
|
34
40
|
import { foundryMessagesEstimator, foundryMessagesUsage } from "./messages-accounting"
|
|
35
41
|
import {
|
|
36
42
|
foundryMessagesRequest,
|
|
@@ -49,6 +55,8 @@ import {
|
|
|
49
55
|
import { object, PREFIX } from "./util"
|
|
50
56
|
|
|
51
57
|
export interface AzureAIFoundryOptions extends TransportOptions {
|
|
58
|
+
/** Explicit resource transport: project endpoints do not route embeddings. */
|
|
59
|
+
readonly embeddings?: AzureAIFoundryEmbeddingTransportOptions
|
|
52
60
|
/** Public model capabilities and reference pricing from models.dev. */
|
|
53
61
|
readonly catalog?: AzureAIFoundryCatalogOptions
|
|
54
62
|
/** Namespace bindings from different resources/projects in a single Sixb catalog. */
|
|
@@ -111,6 +119,10 @@ export interface AzureAIFoundryProvider extends LanguageModelProvider {
|
|
|
111
119
|
deploymentName: string,
|
|
112
120
|
options?: AzureAIFoundryMessagesOptions
|
|
113
121
|
): AzureAIFoundryModel<"messages">
|
|
122
|
+
embedding(
|
|
123
|
+
deploymentName: string,
|
|
124
|
+
options: AzureAIFoundryEmbeddingOptions
|
|
125
|
+
): AzureAIFoundryEmbeddingModel
|
|
114
126
|
readonly catalog: AzureAIFoundryCatalog
|
|
115
127
|
chat(deploymentName: string, options?: AzureAIFoundryChatOptions): AzureAIFoundryModel<"chat">
|
|
116
128
|
}
|
|
@@ -121,6 +133,23 @@ export function createAzureAIFoundry(options: AzureAIFoundryOptions): AzureAIFou
|
|
|
121
133
|
if (!providerId.trim()) throw new TypeError(`${PREFIX} providerId must not be empty.`)
|
|
122
134
|
const deployments = new FoundryDeployments(providerId, transport, options.discovery)
|
|
123
135
|
const modelCatalog = new RemoteModelsDevCatalog(options.catalog)
|
|
136
|
+
const embeddingTransport = options.embeddings
|
|
137
|
+
? new FoundryTransport(options.embeddings, "resource")
|
|
138
|
+
: undefined
|
|
139
|
+
const embedding = (name: string, input: AzureAIFoundryEmbeddingOptions) => {
|
|
140
|
+
if (!embeddingTransport)
|
|
141
|
+
throw new TypeError(
|
|
142
|
+
`${PREFIX} Configure embeddings.endpoint and embeddings.apiKey before declaring an embedding model.`
|
|
143
|
+
)
|
|
144
|
+
return createFoundryEmbedding(
|
|
145
|
+
providerId,
|
|
146
|
+
name,
|
|
147
|
+
input,
|
|
148
|
+
embeddingTransport,
|
|
149
|
+
deployments,
|
|
150
|
+
modelCatalog
|
|
151
|
+
)
|
|
152
|
+
}
|
|
124
153
|
const model = <P extends FoundryProtocol = FoundryProtocol>(
|
|
125
154
|
protocol: P | undefined,
|
|
126
155
|
deploymentName: string,
|
|
@@ -153,6 +182,11 @@ export function createAzureAIFoundry(options: AzureAIFoundryOptions): AzureAIFou
|
|
|
153
182
|
const results: LanguageModelDefinition[] = []
|
|
154
183
|
for (const deployment of records) {
|
|
155
184
|
const name = deployment.name
|
|
185
|
+
if (
|
|
186
|
+
isEmbeddingDeployment(deployment) ||
|
|
187
|
+
(await modelCatalog.getEmbedding(deployment.modelName, true))
|
|
188
|
+
)
|
|
189
|
+
continue
|
|
156
190
|
try {
|
|
157
191
|
const profile = resolveModel({
|
|
158
192
|
providerId,
|
|
@@ -185,7 +219,7 @@ export function createAzureAIFoundry(options: AzureAIFoundryOptions): AzureAIFou
|
|
|
185
219
|
}
|
|
186
220
|
const auto = (name: string, options: AzureAIFoundryModelOptions = {}) =>
|
|
187
221
|
model(undefined, name, options)
|
|
188
|
-
return Object.assign(auto, { providerId, catalog, responses, messages, chat })
|
|
222
|
+
return Object.assign(auto, { providerId, catalog, responses, messages, chat, embedding })
|
|
189
223
|
}
|
|
190
224
|
|
|
191
225
|
class FoundryModel<Protocol extends FoundryProtocol> implements AzureAIFoundryModel<Protocol> {
|
|
@@ -275,6 +309,10 @@ class FoundryModel<Protocol extends FoundryProtocol> implements AzureAIFoundryMo
|
|
|
275
309
|
async resolve(options?: { readonly offline?: boolean }): Promise<FoundryModel<Protocol>> {
|
|
276
310
|
if (this.resolution) return this
|
|
277
311
|
const resolution = await this.deployments.resolve(this.modelId, options?.offline === true)
|
|
312
|
+
if (isEmbeddingDeployment(resolution.deployment))
|
|
313
|
+
throw new UnsupportedModelFeatureError(
|
|
314
|
+
`${PREFIX} Use foundry.embedding() for an embedding deployment.`
|
|
315
|
+
)
|
|
278
316
|
let catalogModel: CatalogModel | undefined
|
|
279
317
|
try {
|
|
280
318
|
catalogModel = await this.modelCatalog.get(resolution.deployment.modelName, options?.offline)
|
|
@@ -285,6 +323,10 @@ class FoundryModel<Protocol extends FoundryProtocol> implements AzureAIFoundryMo
|
|
|
285
323
|
catalogModel = await this.modelCatalog.get(resolution.deployment.modelName, true)
|
|
286
324
|
if (!catalogModel && !this.options.definition) throw error
|
|
287
325
|
}
|
|
326
|
+
if (await this.modelCatalog.getEmbedding(resolution.deployment.modelName, true))
|
|
327
|
+
throw new UnsupportedModelFeatureError(
|
|
328
|
+
`${PREFIX} Use foundry.embedding() for an embedding deployment.`
|
|
329
|
+
)
|
|
288
330
|
return new FoundryModel(
|
|
289
331
|
this.requestedProtocol,
|
|
290
332
|
this.transport,
|
|
@@ -414,3 +456,11 @@ class FoundryModel<Protocol extends FoundryProtocol> implements AzureAIFoundryMo
|
|
|
414
456
|
}
|
|
415
457
|
}
|
|
416
458
|
}
|
|
459
|
+
|
|
460
|
+
function isEmbeddingDeployment(deployment: AzureAIFoundryDeployment): boolean {
|
|
461
|
+
return (
|
|
462
|
+
deployment.capabilities.embeddings === "true" ||
|
|
463
|
+
deployment.capabilities.embedding === "true" ||
|
|
464
|
+
/^(text-embedding-|cohere-embed)/i.test(deployment.modelName)
|
|
465
|
+
)
|
|
466
|
+
}
|