@economic/agents 2.3.2 → 2.3.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/dist/providers.d.mts +4 -4
- package/dist/providers.mjs +11 -7
- package/package.json +1 -1
package/dist/providers.d.mts
CHANGED
|
@@ -14,7 +14,7 @@ interface AnthropicVertexProviderOptions {
|
|
|
14
14
|
location?: string;
|
|
15
15
|
anthropicVersion?: string;
|
|
16
16
|
}
|
|
17
|
-
declare function
|
|
17
|
+
declare function createAnthropicProvider(options: AnthropicVertexProviderOptions): (modelId: AnthropicVertexModelId, metadata?: Record<string, unknown>) => AnthropicMessagesLanguageModel;
|
|
18
18
|
//#endregion
|
|
19
19
|
//#region src/providers/gemini.d.ts
|
|
20
20
|
type GeminiModelId = Parameters<GoogleGenerativeAIProvider>[0];
|
|
@@ -25,13 +25,13 @@ interface GeminiProviderOptions {
|
|
|
25
25
|
googleCloudProjectId: string;
|
|
26
26
|
location?: string;
|
|
27
27
|
}
|
|
28
|
-
declare function createGeminiProvider(options: GeminiProviderOptions): GoogleGenerativeAIProvider;
|
|
28
|
+
declare function createGeminiProvider(options: GeminiProviderOptions, metadata?: Record<string, unknown>): GoogleGenerativeAIProvider;
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region src/providers/index.d.ts
|
|
31
31
|
interface AiGatewayVertexProvidersOptions extends AnthropicVertexProviderOptions, GeminiProviderOptions {}
|
|
32
32
|
declare function createAiGatewayVertexProviders(options: AiGatewayVertexProvidersOptions): {
|
|
33
|
-
anthropic: (modelId: AnthropicVertexModelId) => _$_ai_sdk_anthropic_internal0.AnthropicMessagesLanguageModel;
|
|
33
|
+
anthropic: (modelId: AnthropicVertexModelId, metadata?: Record<string, unknown>) => _$_ai_sdk_anthropic_internal0.AnthropicMessagesLanguageModel;
|
|
34
34
|
gemini: _$_ai_sdk_google0.GoogleGenerativeAIProvider;
|
|
35
35
|
};
|
|
36
36
|
//#endregion
|
|
37
|
-
export { AiGatewayVertexProvidersOptions, type AnthropicVertexModelId, type AnthropicVertexProviderOptions, type GeminiModelId, type GeminiProviderOptions, createAiGatewayVertexProviders,
|
|
37
|
+
export { AiGatewayVertexProvidersOptions, type AnthropicVertexModelId, type AnthropicVertexProviderOptions, type GeminiModelId, type GeminiProviderOptions, createAiGatewayVertexProviders, createAnthropicProvider, createGeminiProvider };
|
package/dist/providers.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { AnthropicMessagesLanguageModel } from "@ai-sdk/anthropic/internal";
|
|
2
2
|
import { createGoogleGenerativeAI } from "@ai-sdk/google";
|
|
3
3
|
//#region src/providers/anthropic.ts
|
|
4
|
-
function
|
|
4
|
+
function createAnthropicProvider(options) {
|
|
5
5
|
const { anthropicVersion = "vertex-2023-10-16", cloudflareAccountId, cloudflareAiGatewayId, cloudflareApiToken, googleCloudProjectId, location = "europe-west1" } = options;
|
|
6
6
|
const anthropicBaseURL = `${`${`https://gateway.ai.cloudflare.com/v1/${cloudflareAccountId}/${cloudflareAiGatewayId}/`}google-vertex-ai/v1/projects/${googleCloudProjectId}/locations/${location}/publishers/`}anthropic/models/`;
|
|
7
|
-
return function anthropic(modelId) {
|
|
7
|
+
return function anthropic(modelId, metadata) {
|
|
8
|
+
const headers = { "cf-aig-authorization": `Bearer ${cloudflareApiToken}` };
|
|
9
|
+
if (metadata) headers["cf-aig-metadata"] = JSON.stringify(metadata);
|
|
8
10
|
return new AnthropicMessagesLanguageModel(modelId, {
|
|
9
11
|
provider: "vertex.anthropic.messages",
|
|
10
12
|
baseURL: anthropicBaseURL,
|
|
11
|
-
headers
|
|
13
|
+
headers,
|
|
12
14
|
buildRequestUrl: (baseURL, isStreaming) => `${baseURL}${modelId}:${isStreaming ? "streamRawPredict" : "rawPredict"}`,
|
|
13
15
|
transformRequestBody: (args) => {
|
|
14
16
|
const { model, ...rest } = args;
|
|
@@ -25,12 +27,14 @@ function createAnthropicVertexProvider(options) {
|
|
|
25
27
|
}
|
|
26
28
|
//#endregion
|
|
27
29
|
//#region src/providers/gemini.ts
|
|
28
|
-
function createGeminiProvider(options) {
|
|
30
|
+
function createGeminiProvider(options, metadata) {
|
|
29
31
|
const { cloudflareAccountId, cloudflareAiGatewayId, cloudflareApiToken, googleCloudProjectId, location = "europe-west1" } = options;
|
|
32
|
+
const headers = { "cf-aig-authorization": `Bearer ${cloudflareApiToken}` };
|
|
33
|
+
if (metadata) headers["cf-aig-metadata"] = JSON.stringify(metadata);
|
|
30
34
|
return createGoogleGenerativeAI({
|
|
31
35
|
apiKey: "unused",
|
|
32
36
|
baseURL: `https://gateway.ai.cloudflare.com/v1/${cloudflareAccountId}/${cloudflareAiGatewayId}/google-vertex-ai/v1/projects/${googleCloudProjectId}/locations/${location}/publishers/google/models`,
|
|
33
|
-
headers
|
|
37
|
+
headers,
|
|
34
38
|
name: "gateway.google.vertex-ai"
|
|
35
39
|
});
|
|
36
40
|
}
|
|
@@ -38,9 +42,9 @@ function createGeminiProvider(options) {
|
|
|
38
42
|
//#region src/providers/index.ts
|
|
39
43
|
function createAiGatewayVertexProviders(options) {
|
|
40
44
|
return {
|
|
41
|
-
anthropic:
|
|
45
|
+
anthropic: createAnthropicProvider(options),
|
|
42
46
|
gemini: createGeminiProvider(options)
|
|
43
47
|
};
|
|
44
48
|
}
|
|
45
49
|
//#endregion
|
|
46
|
-
export { createAiGatewayVertexProviders,
|
|
50
|
+
export { createAiGatewayVertexProviders, createAnthropicProvider, createGeminiProvider };
|