@sixb/azure-ai-foundry 0.1.1 → 0.1.2
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/README.md
CHANGED
|
@@ -26,7 +26,7 @@ The full project URL and API key are required. The provider uses the same key to
|
|
|
26
26
|
deployments and call inference. Keys may be strings or synchronous/asynchronous functions;
|
|
27
27
|
functions receive an abort signal and are evaluated for each Azure HTTP attempt.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Language model resolution follows this sequence:
|
|
30
30
|
|
|
31
31
|
1. Find the deployment in the Azure project and read its model name, version, and publisher.
|
|
32
32
|
2. Look up the underlying model in models.dev.
|
|
@@ -40,6 +40,48 @@ If models.dev is unavailable after successful Azure discovery, resolution uses c
|
|
|
40
40
|
facts or an explicit `definition`. Without either, it fails. Malformed catalog data still fails;
|
|
41
41
|
missing capabilities and prices remain unknown. Catalog listings and refresh report outages.
|
|
42
42
|
|
|
43
|
+
## Embeddings
|
|
44
|
+
|
|
45
|
+
Configure the resource endpoint separately: Foundry project endpoints do not route embeddings.
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
const foundry = createAzureAIFoundry({
|
|
49
|
+
endpoint: "https://my-resource.services.ai.azure.com/api/projects/my-project",
|
|
50
|
+
apiKey: () => process.env.AZURE_AI_FOUNDRY_API_KEY,
|
|
51
|
+
embeddings: {
|
|
52
|
+
endpoint: "https://my-resource.openai.azure.com/openai/v1",
|
|
53
|
+
apiKey: () => process.env.AZURE_OPENAI_API_KEY,
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
export const productEmbedding = foundry.embedding("product-embedding", {
|
|
58
|
+
model: { name: "text-embedding-3-small", version: "1" },
|
|
59
|
+
dimensions: 1536,
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Register this binding under `models.embedding` and use it in an ObjectType's vector profile.
|
|
64
|
+
Set `model` to your deployment's actual model name and version. A mismatch blocks inference;
|
|
65
|
+
changing the declared model or version excludes previously stored vectors from search.
|
|
66
|
+
The deployment name must exist in the project and refer to the same deployment on the configured
|
|
67
|
+
resource. For connected deployments, supply the owning resource's endpoint and key.
|
|
68
|
+
|
|
69
|
+
| Deployed model | Dimensions |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `text-embedding-3-small` | 1–1536 |
|
|
72
|
+
| `text-embedding-3-large` | 1–3072 |
|
|
73
|
+
| `text-embedding-ada-002` | Exactly 1536 |
|
|
74
|
+
|
|
75
|
+
Text batches accept up to 2048 nonempty strings; Azure enforces token limits. Other model families,
|
|
76
|
+
including Cohere, are rejected. Calls return vectors in input order and propagate cancellation.
|
|
77
|
+
|
|
78
|
+
Sixb object indexing and text search apply [usage accounting and limits](../../docs/models/usage-and-limits.md).
|
|
79
|
+
Direct `productEmbedding.embed({ texts: ["running shoes"] })` bypasses Sixb accounting.
|
|
80
|
+
Reference prices come from models.dev; use `rateCard` or `costEstimator` for deployment-specific
|
|
81
|
+
pricing. Missing pricing remains unknown and blocks cost-limited calls before inference.
|
|
82
|
+
|
|
83
|
+
See [embedding internals](./docs/embeddings.md) for resolution, transport, and failure handling.
|
|
84
|
+
|
|
43
85
|
## Stream a response
|
|
44
86
|
|
|
45
87
|
```ts
|
|
@@ -79,7 +121,7 @@ const cached = await model.resolve({ offline: true })
|
|
|
79
121
|
|
|
80
122
|
| Behavior | Rule |
|
|
81
123
|
| --- | --- |
|
|
82
|
-
| Catalog listings | Supported
|
|
124
|
+
| Catalog listings | Supported language deployments |
|
|
83
125
|
| Azure matching | Unique case-insensitive model ID match |
|
|
84
126
|
| `FW-` fallback | Unique normalized match in the models.dev Fireworks catalog |
|
|
85
127
|
| Fireworks normalization | Removes namespace/`FW-`; normalizes casing and numeric `5p3` → `5.3` |
|
package/dist/catalog.d.ts
CHANGED
|
@@ -6,12 +6,19 @@ export interface AzureAIFoundryCatalogOptions {
|
|
|
6
6
|
readonly fetch?: (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
7
7
|
}
|
|
8
8
|
export interface CatalogModel {
|
|
9
|
+
readonly kind: "language";
|
|
9
10
|
readonly catalogProvider: "azure" | "fireworks-ai";
|
|
10
11
|
readonly modelName: string;
|
|
11
12
|
readonly protocol?: FoundryProtocol;
|
|
12
13
|
readonly definition: ReturnType<typeof defineLanguageModel>;
|
|
13
14
|
readonly rateCard?: LanguageModelRateCard;
|
|
14
15
|
}
|
|
16
|
+
export interface CatalogEmbeddingModel {
|
|
17
|
+
readonly kind: "embedding";
|
|
18
|
+
readonly catalogProvider: "azure" | "fireworks-ai";
|
|
19
|
+
readonly modelName: string;
|
|
20
|
+
readonly rateCard?: LanguageModelRateCard;
|
|
21
|
+
}
|
|
15
22
|
/** Provider-scoped models.dev snapshot. Construction and offline reads never perform I/O. */
|
|
16
23
|
export declare class RemoteModelsDevCatalog {
|
|
17
24
|
private snapshot;
|
|
@@ -21,6 +28,7 @@ export declare class RemoteModelsDevCatalog {
|
|
|
21
28
|
constructor(options?: AzureAIFoundryCatalogOptions);
|
|
22
29
|
invalidate(): void;
|
|
23
30
|
get(name: string, offline?: boolean): Promise<CatalogModel | undefined>;
|
|
31
|
+
getEmbedding(name: string, offline?: boolean): Promise<CatalogEmbeddingModel | undefined>;
|
|
24
32
|
/** Capture one snapshot so a batch of lookups cannot expire between deployments. */
|
|
25
33
|
lookup(offline?: boolean): Promise<(name: string) => CatalogModel | undefined>;
|
|
26
34
|
private load;
|
package/dist/catalog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEnB,KAAK,qBAAqB,EAI3B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC1F;AACD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,eAAe,EAAE,OAAO,GAAG,cAAc,CAAA;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAA;IACnC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAA;CAC1C;AAED,6FAA6F;AAC7F,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,QAAQ,CAAI;IACpB,OAAO,CAAC,OAAO,CAAC,CAAkC;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;gBAC1C,OAAO,GAAE,4BAAiC;IAYtD,UAAU;IAGJ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EAEnB,KAAK,qBAAqB,EAI3B,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAKlD,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC1F;AACD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IACzB,QAAQ,CAAC,eAAe,EAAE,OAAO,GAAG,cAAc,CAAA;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAA;IACnC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,mBAAmB,CAAC,CAAA;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAA;CAC1C;AAED,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;IAC1B,QAAQ,CAAC,eAAe,EAAE,OAAO,GAAG,cAAc,CAAA;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAA;CAC1C;AAID,6FAA6F;AAC7F,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,QAAQ,CAAI;IACpB,OAAO,CAAC,OAAO,CAAC,CAAkC;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA8B;gBAC1C,OAAO,GAAE,4BAAiC;IAYtD,UAAU;IAGJ,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAGrE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,UAAQ,GAAG,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAAC;IAU7F,oFAAoF;IAC9E,MAAM,CAAC,OAAO,UAAQ,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,YAAY,GAAG,SAAS,CAAC;IA2BlF,OAAO,CAAC,IAAI;YAcE,WAAW;CA+G1B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type EmbeddingModel, type LanguageModelRateCard, type ModelCostEstimator } from "@sixb/core/models";
|
|
2
|
+
import type { RemoteModelsDevCatalog } from "./catalog";
|
|
3
|
+
import type { FoundryDeployments, ResolvedDeployment } from "./discovery";
|
|
4
|
+
import type { AzureAIFoundryModelMetadata } from "./provider";
|
|
5
|
+
import { type FoundryTransport, type TransportOptions } from "./transport";
|
|
6
|
+
export type AzureAIFoundryEmbeddingTransportOptions = Pick<TransportOptions, "endpoint" | "apiKey" | "headers" | "fetch">;
|
|
7
|
+
export interface AzureAIFoundryEmbeddingOptions {
|
|
8
|
+
/** Pin the actual model behind the deployment; discovery must match before inference. */
|
|
9
|
+
readonly model: {
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly version: string;
|
|
12
|
+
};
|
|
13
|
+
/** Expected output size; sent to text-embedding-3 models, validated locally for ada-002. */
|
|
14
|
+
readonly dimensions: number;
|
|
15
|
+
readonly rateCard?: LanguageModelRateCard;
|
|
16
|
+
readonly costEstimator?: ModelCostEstimator;
|
|
17
|
+
}
|
|
18
|
+
export interface AzureAIFoundryEmbeddingModel extends EmbeddingModel {
|
|
19
|
+
readonly metadata: AzureAIFoundryModelMetadata;
|
|
20
|
+
resolve(options?: {
|
|
21
|
+
readonly offline?: boolean;
|
|
22
|
+
}): Promise<AzureAIFoundryEmbeddingModel>;
|
|
23
|
+
}
|
|
24
|
+
interface EmbeddingResolution extends ResolvedDeployment {
|
|
25
|
+
readonly costEstimator: ModelCostEstimator;
|
|
26
|
+
readonly configurableDimensions: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** Discovery uses project credentials; inference uses only the explicit resource transport. */
|
|
29
|
+
export declare function createFoundryEmbedding(providerId: string, modelId: string, options: AzureAIFoundryEmbeddingOptions, transport: FoundryTransport, deployments: FoundryDeployments, catalog: RemoteModelsDevCatalog, resolution?: EmbeddingResolution): AzureAIFoundryEmbeddingModel;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=embedding.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedding.d.ts","sourceRoot":"","sources":["../src/embedding.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EAOnB,KAAK,qBAAqB,EAE1B,KAAK,kBAAkB,EAGxB,MAAM,mBAAmB,CAAA;AAE1B,OAAO,KAAK,EAAyB,sBAAsB,EAAE,MAAM,WAAW,CAAA;AAC9E,OAAO,KAAK,EAA4B,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AACnG,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAC7D,OAAO,EAAa,KAAK,gBAAgB,EAAa,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAGhG,MAAM,MAAM,uCAAuC,GAAG,IAAI,CACxD,gBAAgB,EAChB,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAC5C,CAAA;AAED,MAAM,WAAW,8BAA8B;IAC7C,yFAAyF;IACzF,QAAQ,CAAC,KAAK,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAA;IACnE,4FAA4F;IAC5F,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,qBAAqB,CAAA;IACzC,QAAQ,CAAC,aAAa,CAAC,EAAE,kBAAkB,CAAA;CAC5C;AAED,MAAM,WAAW,4BAA6B,SAAQ,cAAc;IAClE,QAAQ,CAAC,QAAQ,EAAE,2BAA2B,CAAA;IAC9C,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAA;CACzF;AAED,UAAU,mBAAoB,SAAQ,kBAAkB;IACtD,QAAQ,CAAC,aAAa,EAAE,kBAAkB,CAAA;IAC1C,QAAQ,CAAC,sBAAsB,EAAE,OAAO,CAAA;CACzC;AAED,+FAA+F;AAC/F,wBAAgB,sBAAsB,CACpC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,8BAA8B,EACvC,SAAS,EAAE,gBAAgB,EAC3B,WAAW,EAAE,kBAAkB,EAC/B,OAAO,EAAE,sBAAsB,EAC/B,UAAU,CAAC,EAAE,mBAAmB,GAC/B,4BAA4B,CA+J9B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { AzureAIFoundryCatalogOptions } from "./catalog";
|
|
2
2
|
export type { AzureAIFoundryCatalog, AzureAIFoundryDeployment, AzureAIFoundryDiscoveryOptions, } from "./discovery";
|
|
3
|
+
export type { AzureAIFoundryEmbeddingModel, AzureAIFoundryEmbeddingOptions, AzureAIFoundryEmbeddingTransportOptions, } from "./embedding";
|
|
3
4
|
export type { AzureAIFoundryChatOptions, AzureAIFoundryMessagesOptions, AzureAIFoundryModel, AzureAIFoundryModelMetadata, AzureAIFoundryModelOptions, AzureAIFoundryOptions, AzureAIFoundryProvider, } from "./provider";
|
|
4
5
|
export { createAzureAIFoundry } from "./provider";
|
|
5
6
|
export type { FoundryProtocol } from "./transport";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAA;AAC7D,YAAY,EACV,qBAAqB,EACrB,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,aAAa,CAAA;AACpB,YAAY,EACV,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAA;AAC7D,YAAY,EACV,qBAAqB,EACrB,wBAAwB,EACxB,8BAA8B,GAC/B,MAAM,aAAa,CAAA;AACpB,YAAY,EACV,4BAA4B,EAC5B,8BAA8B,EAC9B,uCAAuC,GACxC,MAAM,aAAa,CAAA;AACpB,YAAY,EACV,yBAAyB,EACzB,6BAA6B,EAC7B,mBAAmB,EACnB,2BAA2B,EAC3B,0BAA0B,EAC1B,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,YAAY,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// src/provider.ts
|
|
3
3
|
import {
|
|
4
4
|
assertJsonObject,
|
|
5
|
-
ModelCatalogUnavailableError as
|
|
5
|
+
ModelCatalogUnavailableError as ModelCatalogUnavailableError4,
|
|
6
6
|
ModelProviderError as ModelProviderError4,
|
|
7
|
-
UnsupportedModelFeatureError as
|
|
7
|
+
UnsupportedModelFeatureError as UnsupportedModelFeatureError6
|
|
8
8
|
} from "@sixb/core/models";
|
|
9
9
|
import { chatEvents } from "@sixb/model-protocols/chat";
|
|
10
10
|
import { messagesEvents } from "@sixb/model-protocols/messages";
|
|
@@ -159,18 +159,20 @@ class FoundryTransport {
|
|
|
159
159
|
baseUrl;
|
|
160
160
|
projectUrl;
|
|
161
161
|
options;
|
|
162
|
-
constructor(options) {
|
|
162
|
+
constructor(options, target = "project") {
|
|
163
163
|
if (!URL.canParse(options.endpoint))
|
|
164
|
-
throw new TypeError(`${PREFIX} endpoint must be a valid
|
|
164
|
+
throw new TypeError(`${PREFIX} endpoint must be a valid ${target} URL.`);
|
|
165
165
|
const url = new URL(options.endpoint);
|
|
166
166
|
if (!["https:", "http:"].includes(url.protocol) || url.username || url.password || url.search || url.hash) {
|
|
167
|
-
throw new TypeError(`${PREFIX} endpoint must be an HTTP(S)
|
|
167
|
+
throw new TypeError(`${PREFIX} endpoint must be an HTTP(S) ${target} URL without credentials, query, or fragment.`);
|
|
168
168
|
}
|
|
169
169
|
const path = url.pathname.replace(/\/+$/, "");
|
|
170
|
-
if (!/^\/api\/projects\/[^/]+$/.test(path))
|
|
170
|
+
if (target === "project" && !/^\/api\/projects\/[^/]+$/.test(path))
|
|
171
171
|
throw new TypeError(`${PREFIX} endpoint must be a Foundry project URL: https://<resource>.services.ai.azure.com/api/projects/<project>.`);
|
|
172
|
+
if (target === "resource" && path !== "" && path !== "/openai/v1")
|
|
173
|
+
throw new TypeError(`${PREFIX} embeddings.endpoint must be a resource origin or /openai/v1 URL.`);
|
|
172
174
|
this.projectUrl = `${url.origin}${path}`;
|
|
173
|
-
this.baseUrl = `${this.projectUrl}/openai/v1`;
|
|
175
|
+
this.baseUrl = target === "project" ? `${this.projectUrl}/openai/v1` : `${url.origin}/openai/v1`;
|
|
174
176
|
if (typeof options.apiKey !== "function" && (typeof options.apiKey !== "string" || !options.apiKey.trim()))
|
|
175
177
|
throw new TypeError(`${PREFIX} apiKey is required.`);
|
|
176
178
|
if (options.maxRetries !== undefined && (!Number.isSafeInteger(options.maxRetries) || options.maxRetries < 0)) {
|
|
@@ -189,7 +191,7 @@ class FoundryTransport {
|
|
|
189
191
|
signal.throwIfAborted();
|
|
190
192
|
const headers = await this.headers(signal, diagnostics, protocol === "messages" ? "x-api-key" : "api-key");
|
|
191
193
|
headers.set("content-type", "application/json");
|
|
192
|
-
headers.set("accept", "text/event-stream");
|
|
194
|
+
headers.set("accept", protocol === "embeddings" ? "application/json" : "text/event-stream");
|
|
193
195
|
if (protocol === "messages")
|
|
194
196
|
headers.set("anthropic-version", "2023-06-01");
|
|
195
197
|
signal.throwIfAborted();
|
|
@@ -217,7 +219,7 @@ class FoundryTransport {
|
|
|
217
219
|
if (response.ok)
|
|
218
220
|
return response;
|
|
219
221
|
const error = this.redactError(response, await httpError(response, providerId, modelId, signal));
|
|
220
|
-
if (!error.retryable || attempt >= (this.options.maxRetries ?? 2))
|
|
222
|
+
if (protocol === "embeddings" || !error.retryable || attempt >= (this.options.maxRetries ?? 2))
|
|
221
223
|
throw error;
|
|
222
224
|
await wait(Math.min(error.retryAfterMs ?? 250 * 2 ** attempt, this.options.maxRetryDelayMs ?? 60000), signal);
|
|
223
225
|
}
|
|
@@ -249,6 +251,8 @@ class FoundryTransport {
|
|
|
249
251
|
return (this.options.fetch ?? fetch)(url, init);
|
|
250
252
|
}
|
|
251
253
|
url(protocol) {
|
|
254
|
+
if (protocol === "embeddings")
|
|
255
|
+
return `${this.baseUrl}/embeddings`;
|
|
252
256
|
if (protocol === "responses")
|
|
253
257
|
return `${this.baseUrl}/responses`;
|
|
254
258
|
if (protocol === "chat")
|
|
@@ -364,8 +368,13 @@ class RemoteModelsDevCatalog {
|
|
|
364
368
|
async get(name, offline = false) {
|
|
365
369
|
return (await this.lookup(offline))(name);
|
|
366
370
|
}
|
|
367
|
-
async
|
|
371
|
+
async getEmbedding(name, offline = false) {
|
|
368
372
|
const models = offline ? this.snapshot : await this.load();
|
|
373
|
+
const matches = models.filter((m) => m.kind === "embedding" && m.catalogProvider === "azure" && m.modelName.toLowerCase() === name.toLowerCase());
|
|
374
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
375
|
+
}
|
|
376
|
+
async lookup(offline = false) {
|
|
377
|
+
const models = (offline ? this.snapshot : await this.load()).filter((m) => m.kind === "language");
|
|
369
378
|
return (name) => {
|
|
370
379
|
const matches = models.filter((m) => m.catalogProvider === "azure" && m.modelName.toLowerCase() === name.toLowerCase());
|
|
371
380
|
if (matches.length)
|
|
@@ -437,6 +446,16 @@ class RemoteModelsDevCatalog {
|
|
|
437
446
|
if (!raw || raw.id !== id)
|
|
438
447
|
throw new TypeError(`${PREFIX} Invalid models.dev model identity.`);
|
|
439
448
|
const modalities = object(raw.modalities);
|
|
449
|
+
if (raw.type === "embedding" || raw.family === "text-embedding" || raw.family === "cohere-embed" || /^(text-embedding-|cohere-embed)/i.test(id) || strings(modalities?.output).includes("embedding")) {
|
|
450
|
+
return [
|
|
451
|
+
{
|
|
452
|
+
kind: "embedding",
|
|
453
|
+
catalogProvider,
|
|
454
|
+
modelName: id,
|
|
455
|
+
rateCard: rates(object(raw.cost), undefined)
|
|
456
|
+
}
|
|
457
|
+
];
|
|
458
|
+
}
|
|
440
459
|
if (!strings(modalities?.output).includes("text"))
|
|
441
460
|
return [];
|
|
442
461
|
const limits = object(raw.limit);
|
|
@@ -444,6 +463,7 @@ class RemoteModelsDevCatalog {
|
|
|
444
463
|
const protocol = catalogProvider === "fireworks-ai" ? "chat" : provider?.npm === "@ai-sdk/anthropic" ? "messages" : provider?.shape === "completions" || provider?.npm === "@ai-sdk/openai-compatible" ? "chat" : undefined;
|
|
445
464
|
return [
|
|
446
465
|
{
|
|
466
|
+
kind: "language",
|
|
447
467
|
catalogProvider,
|
|
448
468
|
modelName: id,
|
|
449
469
|
protocol,
|
|
@@ -1314,6 +1334,218 @@ function deploymentRecord(raw, invalid) {
|
|
|
1314
1334
|
});
|
|
1315
1335
|
}
|
|
1316
1336
|
|
|
1337
|
+
// src/embedding.ts
|
|
1338
|
+
import {
|
|
1339
|
+
defineModelRateCard as defineModelRateCard3,
|
|
1340
|
+
EmbeddingModelResponseError,
|
|
1341
|
+
ModelCatalogUnavailableError as ModelCatalogUnavailableError3,
|
|
1342
|
+
UnsupportedModelFeatureError as UnsupportedModelFeatureError3
|
|
1343
|
+
} from "@sixb/core/models";
|
|
1344
|
+
function createFoundryEmbedding(providerId, modelId, options, transport, deployments, catalog, resolution) {
|
|
1345
|
+
const dimensions = options.dimensions;
|
|
1346
|
+
const expected = options.model;
|
|
1347
|
+
if (!expected || [expected.name, expected.version].some((value) => typeof value !== "string" || !value || value.trim() !== value)) {
|
|
1348
|
+
throw new TypeError(`${PREFIX} Embedding deployments require an expected model name and version.`);
|
|
1349
|
+
}
|
|
1350
|
+
const representation = Object.freeze({ name: expected.name, version: expected.version });
|
|
1351
|
+
const definition = Object.freeze({
|
|
1352
|
+
kind: "embedding",
|
|
1353
|
+
providerId,
|
|
1354
|
+
modelId,
|
|
1355
|
+
dimensions,
|
|
1356
|
+
representation
|
|
1357
|
+
});
|
|
1358
|
+
if (!modelId || modelId.trim() !== modelId || !Number.isSafeInteger(dimensions) || dimensions < 1 || dimensions > 16000)
|
|
1359
|
+
throw new TypeError(`${PREFIX} Embedding models require a nonempty deployment name and dimensions between 1 and 16000.`);
|
|
1360
|
+
if (options.rateCard && options.costEstimator)
|
|
1361
|
+
throw new TypeError(`${PREFIX} Configure either rateCard or costEstimator, not both.`);
|
|
1362
|
+
const settings = Object.freeze({
|
|
1363
|
+
model: representation,
|
|
1364
|
+
dimensions,
|
|
1365
|
+
rateCard: options.rateCard && defineModelRateCard3(options.rateCard),
|
|
1366
|
+
costEstimator: options.costEstimator
|
|
1367
|
+
});
|
|
1368
|
+
const deployment = resolution?.deployment;
|
|
1369
|
+
const metadata = Object.freeze(deployment ? {
|
|
1370
|
+
deployment,
|
|
1371
|
+
modelName: deployment.modelName,
|
|
1372
|
+
modelVersion: deployment.modelVersion,
|
|
1373
|
+
publisher: deployment.modelPublisher,
|
|
1374
|
+
sku: deployment.sku.name,
|
|
1375
|
+
discoveredAt: resolution.discoveredAt
|
|
1376
|
+
} : {});
|
|
1377
|
+
let pending;
|
|
1378
|
+
const binding = Object.freeze({
|
|
1379
|
+
providerId,
|
|
1380
|
+
modelId,
|
|
1381
|
+
definition,
|
|
1382
|
+
batching: Object.freeze({ maxInputs: 2048, maxInputBytes: 8191, maxTotalInputBytes: 300000 }),
|
|
1383
|
+
metadata,
|
|
1384
|
+
costEstimator: resolution?.costEstimator,
|
|
1385
|
+
async resolve(input) {
|
|
1386
|
+
if (resolution)
|
|
1387
|
+
return binding;
|
|
1388
|
+
const resolved = await deployments.resolve(modelId, input?.offline === true);
|
|
1389
|
+
if (resolved.deployment.modelName !== representation.name || resolved.deployment.modelVersion !== representation.version) {
|
|
1390
|
+
throw new TypeError(`${PREFIX} Embedding deployment '${modelId}' resolved to ${resolved.deployment.modelName}@${resolved.deployment.modelVersion}; expected ${representation.name}@${representation.version}.`);
|
|
1391
|
+
}
|
|
1392
|
+
const configurableDimensions = validateDeployment(resolved, dimensions);
|
|
1393
|
+
let entry;
|
|
1394
|
+
try {
|
|
1395
|
+
entry = await catalog.getEmbedding(resolved.deployment.modelName, input?.offline);
|
|
1396
|
+
} catch (error) {
|
|
1397
|
+
if (!(error instanceof ModelCatalogUnavailableError3))
|
|
1398
|
+
throw error;
|
|
1399
|
+
entry = await catalog.getEmbedding(resolved.deployment.modelName, true);
|
|
1400
|
+
console.warn(`${PREFIX} Embedding pricing catalog unavailable; using cached or explicit pricing when available.`);
|
|
1401
|
+
}
|
|
1402
|
+
const costEstimator = settings.costEstimator ?? tokenEstimator(settings.rateCard ?? entry?.rateCard, undefined, [], (raw) => !raw || Object.keys(raw).every((key) => ["prompt_tokens", "total_tokens"].includes(key) && counter(raw[key]) !== undefined), resolved.deployment.modelName, resolved.deployment.modelVersion, [
|
|
1403
|
+
modelId,
|
|
1404
|
+
resolved.deployment.modelName,
|
|
1405
|
+
`${resolved.deployment.modelName}-${resolved.deployment.modelVersion}`
|
|
1406
|
+
]);
|
|
1407
|
+
return createFoundryEmbedding(providerId, modelId, settings, transport, deployments, catalog, {
|
|
1408
|
+
...resolved,
|
|
1409
|
+
configurableDimensions,
|
|
1410
|
+
costEstimator
|
|
1411
|
+
});
|
|
1412
|
+
},
|
|
1413
|
+
async embed(input) {
|
|
1414
|
+
const signal = input.signal ?? AbortSignal.timeout(30000);
|
|
1415
|
+
signal.throwIfAborted();
|
|
1416
|
+
if (!Array.isArray(input.texts) || input.texts.length > 2048 || Array.from(input.texts).some((text) => typeof text !== "string" || !text.trim()))
|
|
1417
|
+
throw new TypeError(`${PREFIX} Embedding inputs must contain at most 2048 nonempty strings.`);
|
|
1418
|
+
const texts = [...input.texts];
|
|
1419
|
+
if (!texts.length)
|
|
1420
|
+
return { vectors: [] };
|
|
1421
|
+
if (!resolution) {
|
|
1422
|
+
pending ??= binding.resolve().catch((error) => {
|
|
1423
|
+
pending = undefined;
|
|
1424
|
+
throw error;
|
|
1425
|
+
});
|
|
1426
|
+
const resolved = await abortable(() => pending, signal);
|
|
1427
|
+
return resolved.embed({ texts, signal });
|
|
1428
|
+
}
|
|
1429
|
+
const response = await transport.post(JSON.stringify({
|
|
1430
|
+
model: modelId,
|
|
1431
|
+
input: texts,
|
|
1432
|
+
encoding_format: "float",
|
|
1433
|
+
...resolution.configurableDimensions ? { dimensions } : {}
|
|
1434
|
+
}), signal, providerId, modelId, "embeddings");
|
|
1435
|
+
return readEmbeddingResult(response, transport, signal, {
|
|
1436
|
+
...definition,
|
|
1437
|
+
count: texts.length,
|
|
1438
|
+
deployment: resolution.deployment
|
|
1439
|
+
});
|
|
1440
|
+
}
|
|
1441
|
+
});
|
|
1442
|
+
return binding;
|
|
1443
|
+
}
|
|
1444
|
+
function validateDeployment(resolved, dimensions) {
|
|
1445
|
+
const deployment = resolved.deployment;
|
|
1446
|
+
const name = deployment.modelName.toLowerCase();
|
|
1447
|
+
const maxDimensions = name === "text-embedding-3-small" ? 1536 : name === "text-embedding-3-large" ? 3072 : name === "text-embedding-ada-002" ? 1536 : undefined;
|
|
1448
|
+
if (deployment.modelPublisher.toLowerCase() !== "openai" || !maxDimensions || deployment.capabilities.embeddings === "false" || deployment.capabilities.embedding === "false")
|
|
1449
|
+
throw new UnsupportedModelFeatureError3(`${PREFIX} This embedding deployment is not supported. Use an OpenAI text-embedding-3-small, text-embedding-3-large, or text-embedding-ada-002 deployment.`);
|
|
1450
|
+
const configurable = name !== "text-embedding-ada-002";
|
|
1451
|
+
if (dimensions > maxDimensions || !configurable && dimensions !== maxDimensions)
|
|
1452
|
+
throw new TypeError(`${PREFIX} ${name} requires ${configurable ? `1\u2013${maxDimensions}` : maxDimensions} dimensions.`);
|
|
1453
|
+
return configurable;
|
|
1454
|
+
}
|
|
1455
|
+
function parseVectors(data, count, dimensions, invalid) {
|
|
1456
|
+
if (!Array.isArray(data) || data.length !== count)
|
|
1457
|
+
throw invalid();
|
|
1458
|
+
const vectors = new Array(count);
|
|
1459
|
+
for (const value of data) {
|
|
1460
|
+
const entry = record(value);
|
|
1461
|
+
const index = counter(entry?.index);
|
|
1462
|
+
const embedding = entry?.embedding;
|
|
1463
|
+
if (index === undefined || index >= count || vectors[index] !== undefined || !Array.isArray(embedding) || embedding.length !== dimensions)
|
|
1464
|
+
throw invalid();
|
|
1465
|
+
const vector = [];
|
|
1466
|
+
for (const n of embedding) {
|
|
1467
|
+
if (typeof n !== "number" || !Number.isFinite(Math.fround(n)))
|
|
1468
|
+
throw invalid();
|
|
1469
|
+
vector.push(n);
|
|
1470
|
+
}
|
|
1471
|
+
if (!vector.some((n) => Math.fround(n) !== 0))
|
|
1472
|
+
throw invalid();
|
|
1473
|
+
vectors[index] = vector;
|
|
1474
|
+
}
|
|
1475
|
+
return vectors;
|
|
1476
|
+
}
|
|
1477
|
+
function invalidResponse(providerId, modelId, metadata) {
|
|
1478
|
+
return new EmbeddingModelResponseError(`${PREFIX} Invalid embedding response: expected the resolved model and one finite, nonzero vector of the configured dimension per input, with unique indices.`, providerId, modelId, metadata);
|
|
1479
|
+
}
|
|
1480
|
+
async function readResponse(response, signal) {
|
|
1481
|
+
const reader = response.body?.getReader();
|
|
1482
|
+
if (!reader)
|
|
1483
|
+
throw new Error("Empty embedding response");
|
|
1484
|
+
const chunks = [];
|
|
1485
|
+
let bytes = 0;
|
|
1486
|
+
try {
|
|
1487
|
+
for (;; ) {
|
|
1488
|
+
const chunk = await abortable(() => reader.read(), signal);
|
|
1489
|
+
if (chunk.done)
|
|
1490
|
+
break;
|
|
1491
|
+
bytes += chunk.value.length;
|
|
1492
|
+
if (bytes > 128 * 1024 * 1024)
|
|
1493
|
+
throw new Error("Embedding response exceeds 128 MiB");
|
|
1494
|
+
chunks.push(chunk.value);
|
|
1495
|
+
}
|
|
1496
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
1497
|
+
} finally {
|
|
1498
|
+
reader.cancel().catch(() => {});
|
|
1499
|
+
reader.releaseLock();
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
function embeddingUsage(raw) {
|
|
1503
|
+
const inputTokens = counter(raw?.prompt_tokens);
|
|
1504
|
+
const totalTokens = counter(raw?.total_tokens);
|
|
1505
|
+
const knownInput = inputTokens !== undefined && (raw?.total_tokens === undefined || totalTokens === inputTokens);
|
|
1506
|
+
const unsupported = raw && Object.entries(raw).some(([key, value]) => !["prompt_tokens", "total_tokens"].includes(key) || counter(value) === undefined);
|
|
1507
|
+
return {
|
|
1508
|
+
...knownInput ? { inputTokens, uncachedInputTokens: inputTokens } : {},
|
|
1509
|
+
outputTokens: 0,
|
|
1510
|
+
...raw ? {
|
|
1511
|
+
raw: {
|
|
1512
|
+
...inputTokens === undefined ? {} : { prompt_tokens: inputTokens },
|
|
1513
|
+
...totalTokens === undefined ? {} : { total_tokens: totalTokens },
|
|
1514
|
+
...unsupported ? { unsupported: true } : {}
|
|
1515
|
+
}
|
|
1516
|
+
} : {}
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
function record(value) {
|
|
1520
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) ? value : undefined;
|
|
1521
|
+
}
|
|
1522
|
+
async function readEmbeddingResult(response, transport, signal, expected) {
|
|
1523
|
+
const { providerId, modelId, dimensions } = expected;
|
|
1524
|
+
const facts = {
|
|
1525
|
+
providerIds: { requestId: transport.redactText(response, requestId(response)) }
|
|
1526
|
+
};
|
|
1527
|
+
let body;
|
|
1528
|
+
try {
|
|
1529
|
+
body = record(await readResponse(response, signal));
|
|
1530
|
+
} catch {
|
|
1531
|
+
if (signal.aborted)
|
|
1532
|
+
throw signal.reason;
|
|
1533
|
+
throw invalidResponse(providerId, modelId, facts);
|
|
1534
|
+
}
|
|
1535
|
+
const resultMetadata = {
|
|
1536
|
+
...facts,
|
|
1537
|
+
usage: embeddingUsage(object(body?.usage)),
|
|
1538
|
+
responseModelId: typeof body?.model === "string" ? transport.redactText(response, body.model) : undefined
|
|
1539
|
+
};
|
|
1540
|
+
const name = expected.deployment.modelName;
|
|
1541
|
+
if (!body || ![modelId, name, `${name}-${expected.deployment.modelVersion}`].includes(String(body.model)))
|
|
1542
|
+
throw invalidResponse(providerId, modelId, resultMetadata);
|
|
1543
|
+
return {
|
|
1544
|
+
...resultMetadata,
|
|
1545
|
+
vectors: parseVectors(body.data, expected.count, dimensions, () => invalidResponse(providerId, modelId, resultMetadata))
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
|
|
1317
1549
|
// src/messages-accounting.ts
|
|
1318
1550
|
function foundryMessagesUsage(raw) {
|
|
1319
1551
|
const uncached = counter(raw.input_tokens);
|
|
@@ -1382,7 +1614,7 @@ function tokenMeters2(raw) {
|
|
|
1382
1614
|
// src/messages-request.ts
|
|
1383
1615
|
import {
|
|
1384
1616
|
modelReasoningSupportIssue as modelReasoningSupportIssue3,
|
|
1385
|
-
UnsupportedModelFeatureError as
|
|
1617
|
+
UnsupportedModelFeatureError as UnsupportedModelFeatureError4
|
|
1386
1618
|
} from "@sixb/core/models";
|
|
1387
1619
|
import { messagesInput } from "@sixb/model-protocols/messages";
|
|
1388
1620
|
|
|
@@ -1498,7 +1730,7 @@ function foundryMessagesRequest(request, definition, options, scope) {
|
|
|
1498
1730
|
let conversation = false;
|
|
1499
1731
|
for (const message of request.messages) {
|
|
1500
1732
|
if (message.role === "system" && conversation)
|
|
1501
|
-
throw new
|
|
1733
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} Messages system instructions must precede the conversation.`);
|
|
1502
1734
|
if (message.role !== "system")
|
|
1503
1735
|
conversation = true;
|
|
1504
1736
|
}
|
|
@@ -1506,13 +1738,13 @@ function foundryMessagesRequest(request, definition, options, scope) {
|
|
|
1506
1738
|
throw new TypeError(`${PREFIX} Native Messages requires maxOutputTokens in the definition, binding, or request.`);
|
|
1507
1739
|
const caps = definition.capabilities;
|
|
1508
1740
|
if (request.tools.length && caps.localTools !== true)
|
|
1509
|
-
throw new
|
|
1741
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} Configure localTools capability before using Messages tools.`);
|
|
1510
1742
|
const schema = request.responseFormat && messagesOutputSchema(request.responseFormat.schema);
|
|
1511
1743
|
if (request.responseFormat && (caps.nativeStructuredOutput !== true || !schema))
|
|
1512
|
-
throw new
|
|
1744
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} Messages structured output requires a declared capability and a supported closed-object Claude schema.`);
|
|
1513
1745
|
const thinking = reasoningRequest(request, definition, options, max);
|
|
1514
1746
|
if (thinking.thinking && object(thinking.thinking)?.type !== "disabled" && ["temperature", "top_p", "top_k"].some((key) => options.request?.[key] !== undefined))
|
|
1515
|
-
throw new
|
|
1747
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} Explicit sampling controls cannot be combined with Messages thinking.`);
|
|
1516
1748
|
const mapped = messagesInput(request.messages, definition.providerId, PREFIX);
|
|
1517
1749
|
const output = {
|
|
1518
1750
|
...thinking.effort === undefined ? {} : { effort: thinking.effort },
|
|
@@ -1545,7 +1777,7 @@ function reasoningRequest(request, definition, options, max) {
|
|
|
1545
1777
|
const caps = definition.capabilities.reasoning;
|
|
1546
1778
|
const issue = modelReasoningSupportIssue3(caps, reasoning);
|
|
1547
1779
|
if (caps === undefined || issue)
|
|
1548
|
-
throw new
|
|
1780
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} ${issue ?? "Configure reasoning capabilities for this deployment"}.`);
|
|
1549
1781
|
if (reasoning === "none") {
|
|
1550
1782
|
return {
|
|
1551
1783
|
thinking: { type: "disabled" }
|
|
@@ -1553,21 +1785,21 @@ function reasoningRequest(request, definition, options, max) {
|
|
|
1553
1785
|
}
|
|
1554
1786
|
if (typeof reasoning === "string") {
|
|
1555
1787
|
if (reasoning === "minimal" || options.thinkingMode === "manual")
|
|
1556
|
-
throw new
|
|
1788
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} Named efforts require an adaptive-thinking Claude offering.`);
|
|
1557
1789
|
return { thinking: { type: "adaptive" }, effort: reasoning };
|
|
1558
1790
|
}
|
|
1559
1791
|
if (options.thinkingMode === "adaptive")
|
|
1560
|
-
throw new
|
|
1792
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} This Claude offering only supports adaptive thinking, not manual budgets.`);
|
|
1561
1793
|
if (reasoning.budgetTokens < 1024 || reasoning.budgetTokens >= max)
|
|
1562
|
-
throw new
|
|
1794
|
+
throw new UnsupportedModelFeatureError4(`${PREFIX} Messages reasoning budget must be at least 1024 and below maxOutputTokens (${max}).`);
|
|
1563
1795
|
return { thinking: { type: "enabled", budget_tokens: reasoning.budgetTokens } };
|
|
1564
1796
|
}
|
|
1565
1797
|
|
|
1566
1798
|
// src/resolution.ts
|
|
1567
1799
|
import {
|
|
1568
1800
|
defineLanguageModel as defineLanguageModel2,
|
|
1569
|
-
defineModelRateCard as
|
|
1570
|
-
UnsupportedModelFeatureError as
|
|
1801
|
+
defineModelRateCard as defineModelRateCard4,
|
|
1802
|
+
UnsupportedModelFeatureError as UnsupportedModelFeatureError5
|
|
1571
1803
|
} from "@sixb/core/models";
|
|
1572
1804
|
function resolveModel(input) {
|
|
1573
1805
|
const { deployment, options } = input;
|
|
@@ -1584,10 +1816,10 @@ function resolveModel(input) {
|
|
|
1584
1816
|
const publisher = deploymentPublisher?.id === "fireworks-ai" ? entry?.definition.publisher ?? deploymentPublisher : deploymentPublisher ?? entry?.definition.publisher;
|
|
1585
1817
|
const protocol = input.protocol ?? entry?.protocol ?? (deployment?.capabilities.responses === "true" ? "responses" : deployment?.capabilities.chatCompletion === "true" || deployment?.capabilities.chat_completion === "true" ? "chat" : deployment?.capabilities.messages === "true" ? "messages" : "responses");
|
|
1586
1818
|
if (protocol === "messages" && deployment?.connectionName)
|
|
1587
|
-
throw new
|
|
1819
|
+
throw new UnsupportedModelFeatureError5(`${PREFIX} Native Messages cannot route a deployment from a project connection; use the owning resource's project URL and API key.`);
|
|
1588
1820
|
const flag = deployment?.capabilities[protocol === "chat" ? "chatCompletion" : protocol] ?? (protocol === "chat" ? deployment?.capabilities.chat_completion : undefined);
|
|
1589
1821
|
if (flag === "false")
|
|
1590
|
-
throw new
|
|
1822
|
+
throw new UnsupportedModelFeatureError5(`${PREFIX} Deployment '${input.modelId}' reports that ${protocol === "chat" ? "Chat" : protocol === "responses" ? "Responses" : "Messages"} is unsupported.`);
|
|
1591
1823
|
const definition = defineLanguageModel2({
|
|
1592
1824
|
...entry?.definition,
|
|
1593
1825
|
publisher,
|
|
@@ -1622,7 +1854,7 @@ function resolveModel(input) {
|
|
|
1622
1854
|
})
|
|
1623
1855
|
} : {}
|
|
1624
1856
|
}),
|
|
1625
|
-
rateCard: options.rateCard ?
|
|
1857
|
+
rateCard: options.rateCard ? defineModelRateCard4(options.rateCard) : entry?.rateCard,
|
|
1626
1858
|
aliases: Object.freeze([
|
|
1627
1859
|
...new Set([
|
|
1628
1860
|
input.modelId,
|
|
@@ -1679,6 +1911,12 @@ function createAzureAIFoundry(options) {
|
|
|
1679
1911
|
throw new TypeError(`${PREFIX} providerId must not be empty.`);
|
|
1680
1912
|
const deployments = new FoundryDeployments(providerId, transport, options.discovery);
|
|
1681
1913
|
const modelCatalog = new RemoteModelsDevCatalog(options.catalog);
|
|
1914
|
+
const embeddingTransport = options.embeddings ? new FoundryTransport(options.embeddings, "resource") : undefined;
|
|
1915
|
+
const embedding = (name, input) => {
|
|
1916
|
+
if (!embeddingTransport)
|
|
1917
|
+
throw new TypeError(`${PREFIX} Configure embeddings.endpoint and embeddings.apiKey before declaring an embedding model.`);
|
|
1918
|
+
return createFoundryEmbedding(providerId, name, input, embeddingTransport, deployments, modelCatalog);
|
|
1919
|
+
};
|
|
1682
1920
|
const model = (protocol, deploymentName, modelOptions) => {
|
|
1683
1921
|
if (!deploymentName.trim() || deploymentName !== deploymentName.trim())
|
|
1684
1922
|
throw new TypeError(`${PREFIX} deploymentName must be nonempty without surrounding whitespace.`);
|
|
@@ -1695,6 +1933,8 @@ function createAzureAIFoundry(options) {
|
|
|
1695
1933
|
const results = [];
|
|
1696
1934
|
for (const deployment of records) {
|
|
1697
1935
|
const name = deployment.name;
|
|
1936
|
+
if (isEmbeddingDeployment(deployment) || await modelCatalog.getEmbedding(deployment.modelName, true))
|
|
1937
|
+
continue;
|
|
1698
1938
|
try {
|
|
1699
1939
|
const profile = resolveModel({
|
|
1700
1940
|
providerId,
|
|
@@ -1709,7 +1949,7 @@ function createAzureAIFoundry(options) {
|
|
|
1709
1949
|
if (supported)
|
|
1710
1950
|
results.push(profile.definition);
|
|
1711
1951
|
} catch (error) {
|
|
1712
|
-
if (!(error instanceof
|
|
1952
|
+
if (!(error instanceof UnsupportedModelFeatureError6))
|
|
1713
1953
|
throw error;
|
|
1714
1954
|
}
|
|
1715
1955
|
}
|
|
@@ -1722,7 +1962,7 @@ function createAzureAIFoundry(options) {
|
|
|
1722
1962
|
deployments: () => deployments.list()
|
|
1723
1963
|
};
|
|
1724
1964
|
const auto = (name, options = {}) => model(undefined, name, options);
|
|
1725
|
-
return Object.assign(auto, { providerId, catalog, responses, messages, chat });
|
|
1965
|
+
return Object.assign(auto, { providerId, catalog, responses, messages, chat, embedding });
|
|
1726
1966
|
}
|
|
1727
1967
|
|
|
1728
1968
|
class FoundryModel {
|
|
@@ -1798,16 +2038,20 @@ class FoundryModel {
|
|
|
1798
2038
|
if (this.resolution)
|
|
1799
2039
|
return this;
|
|
1800
2040
|
const resolution = await this.deployments.resolve(this.modelId, options?.offline === true);
|
|
2041
|
+
if (isEmbeddingDeployment(resolution.deployment))
|
|
2042
|
+
throw new UnsupportedModelFeatureError6(`${PREFIX} Use foundry.embedding() for an embedding deployment.`);
|
|
1801
2043
|
let catalogModel;
|
|
1802
2044
|
try {
|
|
1803
2045
|
catalogModel = await this.modelCatalog.get(resolution.deployment.modelName, options?.offline);
|
|
1804
2046
|
} catch (error) {
|
|
1805
|
-
if (!(error instanceof
|
|
2047
|
+
if (!(error instanceof ModelCatalogUnavailableError4))
|
|
1806
2048
|
throw error;
|
|
1807
2049
|
catalogModel = await this.modelCatalog.get(resolution.deployment.modelName, true);
|
|
1808
2050
|
if (!catalogModel && !this.options.definition)
|
|
1809
2051
|
throw error;
|
|
1810
2052
|
}
|
|
2053
|
+
if (await this.modelCatalog.getEmbedding(resolution.deployment.modelName, true))
|
|
2054
|
+
throw new UnsupportedModelFeatureError6(`${PREFIX} Use foundry.embedding() for an embedding deployment.`);
|
|
1811
2055
|
return new FoundryModel(this.requestedProtocol, this.transport, this.deployments, this.providerId, this.modelId, this.options, this.modelCatalog, {
|
|
1812
2056
|
...resolution,
|
|
1813
2057
|
catalogModel
|
|
@@ -1891,8 +2135,11 @@ class FoundryModel {
|
|
|
1891
2135
|
}
|
|
1892
2136
|
}
|
|
1893
2137
|
}
|
|
2138
|
+
function isEmbeddingDeployment(deployment) {
|
|
2139
|
+
return deployment.capabilities.embeddings === "true" || deployment.capabilities.embedding === "true" || /^(text-embedding-|cohere-embed)/i.test(deployment.modelName);
|
|
2140
|
+
}
|
|
1894
2141
|
export {
|
|
1895
2142
|
createAzureAIFoundry
|
|
1896
2143
|
};
|
|
1897
2144
|
|
|
1898
|
-
//# debugId=
|
|
2145
|
+
//# debugId=AD1DAD3BAAC2ACE564756E2164756E21
|