@llumiverse/drivers 0.22.1 → 0.23.0-dev.20251121
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 +1 -1
- package/lib/esm/src/adobe/firefly.js +2 -2
- package/lib/esm/src/adobe/firefly.js.map +1 -1
- package/lib/esm/src/azure/azure_foundry.js +11 -11
- package/lib/esm/src/azure/azure_foundry.js.map +1 -1
- package/lib/esm/src/bedrock/index.js +4 -4
- package/lib/esm/src/bedrock/index.js.map +1 -1
- package/lib/esm/src/groq/index.js +2 -2
- package/lib/esm/src/groq/index.js.map +1 -1
- package/lib/esm/src/huggingface_ie.js +2 -2
- package/lib/esm/src/huggingface_ie.js.map +1 -1
- package/lib/esm/src/mistral/index.js +2 -2
- package/lib/esm/src/mistral/index.js.map +1 -1
- package/lib/esm/src/openai/azure_openai.js +1 -1
- package/lib/esm/src/openai/azure_openai.js.map +1 -1
- package/lib/esm/src/openai/index.js +3 -3
- package/lib/esm/src/openai/index.js.map +1 -1
- package/lib/esm/src/replicate.js +3 -3
- package/lib/esm/src/replicate.js.map +1 -1
- package/lib/esm/src/togetherai/index.js +2 -2
- package/lib/esm/src/togetherai/index.js.map +1 -1
- package/lib/esm/src/vertexai/models/claude.js +2 -2
- package/lib/esm/src/vertexai/models/claude.js.map +1 -1
- package/lib/esm/src/vertexai/models/imagen.js +1 -1
- package/lib/esm/src/vertexai/models/imagen.js.map +1 -1
- package/lib/esm/src/watsonx/index.js +3 -3
- package/lib/esm/src/watsonx/index.js.map +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/src/bedrock/nova-image-payload.d.ts +1 -1
- package/lib/types/src/huggingface_ie.d.ts +4 -4
- package/package.json +85 -85
- package/src/adobe/firefly.ts +2 -2
- package/src/azure/azure_foundry.ts +11 -11
- package/src/bedrock/index.ts +4 -4
- package/src/groq/index.ts +2 -2
- package/src/huggingface_ie.ts +9 -10
- package/src/index.ts +2 -2
- package/src/mistral/index.ts +2 -2
- package/src/openai/azure_openai.ts +5 -5
- package/src/openai/index.ts +3 -3
- package/src/replicate.ts +7 -7
- package/src/togetherai/index.ts +2 -2
- package/src/vertexai/index.ts +41 -37
- package/src/vertexai/models/claude.ts +4 -4
- package/src/vertexai/models/imagen.ts +4 -4
- package/src/watsonx/index.ts +3 -3
- /package/src/{test → test-driver}/TestErrorCompletionStream.ts +0 -0
- /package/src/{test → test-driver}/TestValidationErrorCompletionStream.ts +0 -0
- /package/src/{test → test-driver}/index.ts +0 -0
- /package/src/{test → test-driver}/utils.ts +0 -0
package/src/vertexai/index.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
|
|
2
|
+
import { PredictionServiceClient, v1beta1 } from "@google-cloud/aiplatform";
|
|
3
|
+
import { Content, GoogleGenAI, Model } from "@google/genai";
|
|
1
4
|
import {
|
|
2
5
|
AIModel,
|
|
3
6
|
AbstractDriver,
|
|
4
7
|
Completion,
|
|
5
8
|
CompletionChunkObject,
|
|
6
9
|
DriverOptions,
|
|
10
|
+
EmbeddingsOptions,
|
|
7
11
|
EmbeddingsResult,
|
|
8
12
|
ExecutionOptions,
|
|
9
13
|
Modalities,
|
|
@@ -13,17 +17,12 @@ import {
|
|
|
13
17
|
modelModalitiesToArray,
|
|
14
18
|
} from "@llumiverse/core";
|
|
15
19
|
import { FetchClient } from "@vertesia/api-fetch-client";
|
|
16
|
-
import { GoogleAuth, GoogleAuthOptions } from "google-auth-library";
|
|
17
|
-
import {
|
|
20
|
+
import { GoogleAuth, GoogleAuthOptions, AuthClient } from "google-auth-library";
|
|
21
|
+
import { getEmbeddingsForImages } from "./embeddings/embeddings-image.js";
|
|
18
22
|
import { TextEmbeddingsOptions, getEmbeddingsForText } from "./embeddings/embeddings-text.js";
|
|
19
23
|
import { getModelDefinition } from "./models.js";
|
|
20
|
-
import {
|
|
21
|
-
import { getEmbeddingsForImages } from "./embeddings/embeddings-image.js";
|
|
22
|
-
import { PredictionServiceClient, v1beta1 } from "@google-cloud/aiplatform";
|
|
23
|
-
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
|
|
24
|
+
import { ANTHROPIC_REGIONS, NON_GLOBAL_ANTHROPIC_MODELS } from "./models/claude.js";
|
|
24
25
|
import { ImagenModelDefinition, ImagenPrompt } from "./models/imagen.js";
|
|
25
|
-
import { GoogleGenAI, Content, Model } from "@google/genai";
|
|
26
|
-
import { NON_GLOBAL_ANTHROPIC_MODELS, ANTHROPIC_REGIONS } from "./models/claude.js";
|
|
27
26
|
|
|
28
27
|
export interface VertexAIDriverOptions extends DriverOptions {
|
|
29
28
|
project: string;
|
|
@@ -56,7 +55,8 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
56
55
|
modelGarden: v1beta1.ModelGardenServiceClient | undefined;
|
|
57
56
|
imagenClient: PredictionServiceClient | undefined;
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
googleAuth: GoogleAuth<any>;
|
|
59
|
+
private authClientPromise: Promise<AuthClient> | undefined;
|
|
60
60
|
|
|
61
61
|
constructor(options: VertexAIDriverOptions) {
|
|
62
62
|
super(options);
|
|
@@ -69,7 +69,15 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
69
69
|
this.llamaClient = undefined;
|
|
70
70
|
this.imagenClient = undefined;
|
|
71
71
|
|
|
72
|
-
this.
|
|
72
|
+
this.googleAuth = new GoogleAuth(options.googleAuthOptions) as GoogleAuth<any>;
|
|
73
|
+
this.authClientPromise = undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private async getAuthClient(): Promise<AuthClient> {
|
|
77
|
+
if (!this.authClientPromise) {
|
|
78
|
+
this.authClientPromise = this.googleAuth.getClient();
|
|
79
|
+
}
|
|
80
|
+
return this.authClientPromise;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
public getGoogleGenAIClient(region: string = this.options.region): GoogleGenAI {
|
|
@@ -80,8 +88,8 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
80
88
|
project: this.options.project,
|
|
81
89
|
location: region,
|
|
82
90
|
vertexai: true,
|
|
83
|
-
googleAuthOptions: {
|
|
84
|
-
|
|
91
|
+
googleAuthOptions: this.options.googleAuthOptions || {
|
|
92
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
85
93
|
}
|
|
86
94
|
});
|
|
87
95
|
}
|
|
@@ -90,8 +98,8 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
90
98
|
project: this.options.project,
|
|
91
99
|
location: region,
|
|
92
100
|
vertexai: true,
|
|
93
|
-
googleAuthOptions: {
|
|
94
|
-
|
|
101
|
+
googleAuthOptions: this.options.googleAuthOptions || {
|
|
102
|
+
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
95
103
|
}
|
|
96
104
|
});
|
|
97
105
|
}
|
|
@@ -105,8 +113,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
105
113
|
region: this.options.region,
|
|
106
114
|
project: this.options.project,
|
|
107
115
|
}).withAuthCallback(async () => {
|
|
108
|
-
const
|
|
109
|
-
const token = typeof accessTokenResponse === 'string' ? accessTokenResponse : accessTokenResponse?.token;
|
|
116
|
+
const token = await this.googleAuth.getAccessToken();
|
|
110
117
|
return `Bearer ${token}`;
|
|
111
118
|
});
|
|
112
119
|
}
|
|
@@ -121,8 +128,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
121
128
|
project: this.options.project,
|
|
122
129
|
apiVersion: "v1beta1",
|
|
123
130
|
}).withAuthCallback(async () => {
|
|
124
|
-
const
|
|
125
|
-
const token = typeof accessTokenResponse === 'string' ? accessTokenResponse : accessTokenResponse?.token;
|
|
131
|
+
const token = await this.googleAuth.getAccessToken();
|
|
126
132
|
return `Bearer ${token}`;
|
|
127
133
|
});
|
|
128
134
|
// Store the region for potential client reuse
|
|
@@ -131,7 +137,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
131
137
|
return this.llamaClient;
|
|
132
138
|
}
|
|
133
139
|
|
|
134
|
-
public getAnthropicClient(region: string = this.options.region): AnthropicVertex {
|
|
140
|
+
public async getAnthropicClient(region: string = this.options.region): Promise<AnthropicVertex> {
|
|
135
141
|
// Extract region prefix and map if it exists in ANTHROPIC_REGIONS, otherwise use as-is
|
|
136
142
|
const getRegionPrefix = (r: string) => r.split('-')[0];
|
|
137
143
|
const regionPrefix = getRegionPrefix(region);
|
|
@@ -140,17 +146,16 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
140
146
|
const defaultRegionPrefix = getRegionPrefix(this.options.region);
|
|
141
147
|
const defaultMappedRegion = ANTHROPIC_REGIONS[defaultRegionPrefix] || this.options.region;
|
|
142
148
|
|
|
149
|
+
// Get auth client to avoid version mismatch with GoogleAuth generic types
|
|
150
|
+
const authClient = await this.getAuthClient();
|
|
151
|
+
|
|
143
152
|
// If mapped region is different from default mapped region, create one-off client
|
|
144
153
|
if (mappedRegion !== defaultMappedRegion) {
|
|
145
154
|
return new AnthropicVertex({
|
|
146
155
|
timeout: 20 * 60 * 10000, // Set to 20 minutes, 10 minute default, setting this disables long request error: https://github.com/anthropics/anthropic-sdk-typescript?#long-requests
|
|
147
156
|
region: mappedRegion,
|
|
148
157
|
projectId: this.options.project,
|
|
149
|
-
|
|
150
|
-
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
151
|
-
authClient: this.authClient as JSONClient,
|
|
152
|
-
projectId: this.options.project,
|
|
153
|
-
}),
|
|
158
|
+
authClient,
|
|
154
159
|
});
|
|
155
160
|
}
|
|
156
161
|
|
|
@@ -160,48 +165,47 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
160
165
|
timeout: 20 * 60 * 10000, // Set to 20 minutes, 10 minute default, setting this disables long request error: https://github.com/anthropics/anthropic-sdk-typescript?#long-requests
|
|
161
166
|
region: mappedRegion,
|
|
162
167
|
projectId: this.options.project,
|
|
163
|
-
|
|
164
|
-
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
165
|
-
authClient: this.authClient as JSONClient,
|
|
166
|
-
projectId: this.options.project,
|
|
167
|
-
}),
|
|
168
|
+
authClient,
|
|
168
169
|
});
|
|
169
170
|
}
|
|
170
171
|
return this.anthropicClient;
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
public getAIPlatformClient(): v1beta1.ModelServiceClient {
|
|
174
|
+
public async getAIPlatformClient(): Promise<v1beta1.ModelServiceClient> {
|
|
174
175
|
//Lazy initialization
|
|
175
176
|
if (!this.aiplatform) {
|
|
177
|
+
const authClient = await this.getAuthClient();
|
|
176
178
|
this.aiplatform = new v1beta1.ModelServiceClient({
|
|
177
179
|
projectId: this.options.project,
|
|
178
180
|
apiEndpoint: `${this.options.region}-${API_BASE_PATH}`,
|
|
179
|
-
authClient
|
|
181
|
+
authClient,
|
|
180
182
|
});
|
|
181
183
|
}
|
|
182
184
|
return this.aiplatform;
|
|
183
185
|
}
|
|
184
186
|
|
|
185
|
-
public getModelGardenClient(): v1beta1.ModelGardenServiceClient {
|
|
187
|
+
public async getModelGardenClient(): Promise<v1beta1.ModelGardenServiceClient> {
|
|
186
188
|
//Lazy initialization
|
|
187
189
|
if (!this.modelGarden) {
|
|
190
|
+
const authClient = await this.getAuthClient();
|
|
188
191
|
this.modelGarden = new v1beta1.ModelGardenServiceClient({
|
|
189
192
|
projectId: this.options.project,
|
|
190
193
|
apiEndpoint: `${this.options.region}-${API_BASE_PATH}`,
|
|
191
|
-
authClient
|
|
194
|
+
authClient,
|
|
192
195
|
});
|
|
193
196
|
}
|
|
194
197
|
return this.modelGarden;
|
|
195
198
|
}
|
|
196
199
|
|
|
197
|
-
public getImagenClient(): PredictionServiceClient {
|
|
200
|
+
public async getImagenClient(): Promise<PredictionServiceClient> {
|
|
198
201
|
//Lazy initialization
|
|
199
202
|
if (!this.imagenClient) {
|
|
200
203
|
// TODO: make location configurable, fixed to us-central1 for now
|
|
204
|
+
const authClient = await this.getAuthClient();
|
|
201
205
|
this.imagenClient = new PredictionServiceClient({
|
|
202
206
|
projectId: this.options.project,
|
|
203
207
|
apiEndpoint: `us-central1-${API_BASE_PATH}`,
|
|
204
|
-
authClient
|
|
208
|
+
authClient,
|
|
205
209
|
});
|
|
206
210
|
}
|
|
207
211
|
return this.imagenClient;
|
|
@@ -263,8 +267,8 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
263
267
|
|
|
264
268
|
async listModels(_params?: ModelSearchPayload): Promise<AIModel<string>[]> {
|
|
265
269
|
// Get clients
|
|
266
|
-
const modelGarden = this.getModelGardenClient();
|
|
267
|
-
const aiplatform = this.getAIPlatformClient();
|
|
270
|
+
const modelGarden = await this.getModelGardenClient();
|
|
271
|
+
const aiplatform = await this.getAIPlatformClient();
|
|
268
272
|
const globalGenAiClient = this.getGoogleGenAIClient("global");
|
|
269
273
|
|
|
270
274
|
let models: AIModel<string>[] = [];
|
|
@@ -269,11 +269,11 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
269
269
|
const modelName = splits[splits.length - 1];
|
|
270
270
|
options = { ...options, model: modelName };
|
|
271
271
|
|
|
272
|
-
const client = driver.getAnthropicClient(region);
|
|
272
|
+
const client = await driver.getAnthropicClient(region);
|
|
273
273
|
options.model_options = options.model_options as VertexAIClaudeOptions;
|
|
274
274
|
|
|
275
275
|
if (options.model_options?._option_id !== "vertexai-claude") {
|
|
276
|
-
driver.logger.warn(
|
|
276
|
+
driver.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
let conversation = updateConversation(options.conversation as ClaudePrompt, prompt);
|
|
@@ -314,11 +314,11 @@ export class ClaudeModelDefinition implements ModelDefinition<ClaudePrompt> {
|
|
|
314
314
|
const modelName = splits[splits.length - 1];
|
|
315
315
|
options = { ...options, model: modelName };
|
|
316
316
|
|
|
317
|
-
const client = driver.getAnthropicClient(region);
|
|
317
|
+
const client = await driver.getAnthropicClient(region);
|
|
318
318
|
const model_options = options.model_options as VertexAIClaudeOptions | undefined;
|
|
319
319
|
|
|
320
320
|
if (model_options?._option_id !== "vertexai-claude") {
|
|
321
|
-
driver.logger.warn(
|
|
321
|
+
driver.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
const { payload, requestOptions } = getClaudePayload(options, prompt);
|
|
@@ -324,7 +324,7 @@ export class ImagenModelDefinition {
|
|
|
324
324
|
|
|
325
325
|
async requestImageGeneration(driver: VertexAIDriver, prompt: ImagenPrompt, options: ExecutionOptions): Promise<Completion> {
|
|
326
326
|
if (options.model_options?._option_id !== "vertexai-imagen") {
|
|
327
|
-
driver.logger.warn(
|
|
327
|
+
driver.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
328
328
|
}
|
|
329
329
|
options.model_options = options.model_options as ImagenOptions | undefined;
|
|
330
330
|
|
|
@@ -336,7 +336,7 @@ export class ImagenModelDefinition {
|
|
|
336
336
|
|
|
337
337
|
driver.logger.info("Task type: " + taskType);
|
|
338
338
|
|
|
339
|
-
|
|
339
|
+
const modelName = options.model.split("/").pop() ?? '';
|
|
340
340
|
|
|
341
341
|
// Configure the parent resource
|
|
342
342
|
// TODO: make location configurable, fixed to us-central1 for now
|
|
@@ -348,7 +348,7 @@ export class ImagenModelDefinition {
|
|
|
348
348
|
}
|
|
349
349
|
const instances = [instanceValue];
|
|
350
350
|
|
|
351
|
-
let parameter: any = getImagenParameters(taskType, options.model_options ?? {_option_id: "vertexai-imagen"});
|
|
351
|
+
let parameter: any = getImagenParameters(taskType, options.model_options ?? { _option_id: "vertexai-imagen" });
|
|
352
352
|
parameter.negativePrompt = prompt.negativePrompt ?? undefined;
|
|
353
353
|
|
|
354
354
|
const numberOfImages = options.model_options?.number_of_images ?? 1;
|
|
@@ -366,7 +366,7 @@ export class ImagenModelDefinition {
|
|
|
366
366
|
parameters,
|
|
367
367
|
};
|
|
368
368
|
|
|
369
|
-
const client = driver.getImagenClient();
|
|
369
|
+
const client = await driver.getImagenClient();
|
|
370
370
|
|
|
371
371
|
// Predict request
|
|
372
372
|
const [response] = await client.predict(request, { timeout: 120000 * numberOfImages }); //Extended timeout for image generation
|
package/src/watsonx/index.ts
CHANGED
|
@@ -31,7 +31,7 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
31
31
|
|
|
32
32
|
async requestTextCompletion(prompt: string, options: ExecutionOptions): Promise<Completion> {
|
|
33
33
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
34
|
-
this.logger.warn(
|
|
34
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
35
35
|
}
|
|
36
36
|
options.model_options = options.model_options as TextFallbackOptions | undefined;
|
|
37
37
|
|
|
@@ -66,7 +66,7 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
66
66
|
|
|
67
67
|
async requestTextCompletionStream(prompt: string, options: ExecutionOptions): Promise<AsyncIterable<CompletionChunkObject>> {
|
|
68
68
|
if (options.model_options?._option_id !== "text-fallback") {
|
|
69
|
-
this.logger.warn(
|
|
69
|
+
this.logger.warn({ options: options.model_options }, "Invalid model options");
|
|
70
70
|
}
|
|
71
71
|
options.model_options = options.model_options as TextFallbackOptions | undefined;
|
|
72
72
|
const payload: WatsonxTextGenerationPayload = {
|
|
@@ -152,7 +152,7 @@ export class WatsonxDriver extends AbstractDriver<WatsonxDriverOptions, string>
|
|
|
152
152
|
return this.listModels()
|
|
153
153
|
.then(() => true)
|
|
154
154
|
.catch((err) => {
|
|
155
|
-
this.logger.warn("Failed to connect to WatsonX"
|
|
155
|
+
this.logger.warn({ error: err }, "Failed to connect to WatsonX");
|
|
156
156
|
return false
|
|
157
157
|
});
|
|
158
158
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|