@llumiverse/drivers 0.18.0 → 0.20.0
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/lib/cjs/bedrock/converse.js +181 -123
- package/lib/cjs/bedrock/converse.js.map +1 -1
- package/lib/cjs/bedrock/index.js +168 -89
- package/lib/cjs/bedrock/index.js.map +1 -1
- package/lib/cjs/huggingface_ie.js +1 -1
- package/lib/cjs/huggingface_ie.js.map +1 -1
- package/lib/cjs/mistral/index.js +1 -1
- package/lib/cjs/mistral/index.js.map +1 -1
- package/lib/cjs/openai/index.js +10 -14
- package/lib/cjs/openai/index.js.map +1 -1
- package/lib/cjs/togetherai/index.js +1 -1
- package/lib/cjs/togetherai/index.js.map +1 -1
- package/lib/cjs/vertexai/index.js +82 -18
- package/lib/cjs/vertexai/index.js.map +1 -1
- package/lib/cjs/vertexai/models/claude.js +248 -159
- package/lib/cjs/vertexai/models/claude.js.map +1 -1
- package/lib/cjs/vertexai/models/gemini.js +496 -123
- package/lib/cjs/vertexai/models/gemini.js.map +1 -1
- package/lib/cjs/vertexai/models/imagen.js +2 -2
- package/lib/cjs/vertexai/models/imagen.js.map +1 -1
- package/lib/cjs/vertexai/models/llama.js +182 -0
- package/lib/cjs/vertexai/models/llama.js.map +1 -0
- package/lib/cjs/vertexai/models.js +4 -0
- package/lib/cjs/vertexai/models.js.map +1 -1
- package/lib/cjs/watsonx/index.js +11 -11
- package/lib/cjs/watsonx/index.js.map +1 -1
- package/lib/cjs/xai/index.js +1 -1
- package/lib/cjs/xai/index.js.map +1 -1
- package/lib/esm/bedrock/converse.js +180 -122
- package/lib/esm/bedrock/converse.js.map +1 -1
- package/lib/esm/bedrock/index.js +169 -90
- package/lib/esm/bedrock/index.js.map +1 -1
- package/lib/esm/huggingface_ie.js +1 -1
- package/lib/esm/huggingface_ie.js.map +1 -1
- package/lib/esm/mistral/index.js +1 -1
- package/lib/esm/mistral/index.js.map +1 -1
- package/lib/esm/openai/index.js +12 -16
- package/lib/esm/openai/index.js.map +1 -1
- package/lib/esm/togetherai/index.js +1 -1
- package/lib/esm/togetherai/index.js.map +1 -1
- package/lib/esm/vertexai/index.js +82 -18
- package/lib/esm/vertexai/index.js.map +1 -1
- package/lib/esm/vertexai/models/claude.js +249 -160
- package/lib/esm/vertexai/models/claude.js.map +1 -1
- package/lib/esm/vertexai/models/gemini.js +491 -119
- package/lib/esm/vertexai/models/gemini.js.map +1 -1
- package/lib/esm/vertexai/models/imagen.js +2 -2
- package/lib/esm/vertexai/models/imagen.js.map +1 -1
- package/lib/esm/vertexai/models/llama.js +178 -0
- package/lib/esm/vertexai/models/llama.js.map +1 -0
- package/lib/esm/vertexai/models.js +4 -0
- package/lib/esm/vertexai/models.js.map +1 -1
- package/lib/esm/watsonx/index.js +11 -11
- package/lib/esm/watsonx/index.js.map +1 -1
- package/lib/esm/xai/index.js +1 -1
- package/lib/esm/xai/index.js.map +1 -1
- package/lib/types/bedrock/converse.d.ts +2 -2
- package/lib/types/bedrock/converse.d.ts.map +1 -1
- package/lib/types/bedrock/index.d.ts +5 -5
- package/lib/types/bedrock/index.d.ts.map +1 -1
- package/lib/types/groq/index.d.ts +1 -1
- package/lib/types/groq/index.d.ts.map +1 -1
- package/lib/types/huggingface_ie.d.ts +1 -1
- package/lib/types/huggingface_ie.d.ts.map +1 -1
- package/lib/types/mistral/index.d.ts +1 -1
- package/lib/types/mistral/index.d.ts.map +1 -1
- package/lib/types/openai/index.d.ts.map +1 -1
- package/lib/types/togetherai/index.d.ts +1 -1
- package/lib/types/togetherai/index.d.ts.map +1 -1
- package/lib/types/vertexai/index.d.ts +16 -7
- package/lib/types/vertexai/index.d.ts.map +1 -1
- package/lib/types/vertexai/models/claude.d.ts +5 -7
- package/lib/types/vertexai/models/claude.d.ts.map +1 -1
- package/lib/types/vertexai/models/gemini.d.ts +12 -7
- package/lib/types/vertexai/models/gemini.d.ts.map +1 -1
- package/lib/types/vertexai/models/llama.d.ts +20 -0
- package/lib/types/vertexai/models/llama.d.ts.map +1 -0
- package/lib/types/vertexai/models.d.ts +7 -3
- package/lib/types/vertexai/models.d.ts.map +1 -1
- package/lib/types/watsonx/index.d.ts +1 -1
- package/lib/types/watsonx/index.d.ts.map +1 -1
- package/lib/types/xai/index.d.ts +1 -1
- package/lib/types/xai/index.d.ts.map +1 -1
- package/package.json +16 -16
- package/src/bedrock/converse.ts +194 -129
- package/src/bedrock/index.ts +193 -101
- package/src/groq/index.ts +1 -1
- package/src/huggingface_ie.ts +1 -1
- package/src/mistral/index.ts +1 -1
- package/src/openai/index.ts +12 -16
- package/src/togetherai/index.ts +1 -1
- package/src/vertexai/index.ts +95 -22
- package/src/vertexai/models/claude.ts +291 -176
- package/src/vertexai/models/gemini.ts +561 -138
- package/src/vertexai/models/imagen.ts +3 -3
- package/src/vertexai/models/llama.ts +261 -0
- package/src/vertexai/models.ts +7 -3
- package/src/watsonx/index.ts +13 -13
- package/src/xai/index.ts +1 -1
package/src/vertexai/index.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { GenerateContentRequest, VertexAI } from "@google-cloud/vertexai";
|
|
2
1
|
import {
|
|
3
2
|
AIModel,
|
|
4
3
|
AbstractDriver,
|
|
5
4
|
Completion,
|
|
6
|
-
|
|
5
|
+
CompletionChunk,
|
|
7
6
|
DriverOptions,
|
|
8
7
|
EmbeddingsResult,
|
|
9
8
|
ExecutionOptions,
|
|
@@ -14,7 +13,7 @@ import {
|
|
|
14
13
|
getModelCapabilities,
|
|
15
14
|
modelModalitiesToArray,
|
|
16
15
|
} from "@llumiverse/core";
|
|
17
|
-
import { FetchClient } from "api-fetch-client";
|
|
16
|
+
import { FetchClient } from "@vertesia/api-fetch-client";
|
|
18
17
|
import { GoogleAuth, GoogleAuthOptions } from "google-auth-library";
|
|
19
18
|
import { JSONClient } from "google-auth-library/build/src/auth/googleauth.js";
|
|
20
19
|
import { TextEmbeddingsOptions, getEmbeddingsForText } from "./embeddings/embeddings-text.js";
|
|
@@ -24,6 +23,7 @@ import { getEmbeddingsForImages } from "./embeddings/embeddings-image.js";
|
|
|
24
23
|
import { v1beta1 } from "@google-cloud/aiplatform";
|
|
25
24
|
import { AnthropicVertex } from "@anthropic-ai/vertex-sdk";
|
|
26
25
|
import { ImagenModelDefinition, ImagenPrompt } from "./models/imagen.js";
|
|
26
|
+
import { GoogleGenAI, Content } from "@google/genai";
|
|
27
27
|
|
|
28
28
|
export interface VertexAIDriverOptions extends DriverOptions {
|
|
29
29
|
project: string;
|
|
@@ -31,8 +31,13 @@ export interface VertexAIDriverOptions extends DriverOptions {
|
|
|
31
31
|
googleAuthOptions?: GoogleAuthOptions;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
export interface GenerateContentPrompt {
|
|
35
|
+
contents: Content[];
|
|
36
|
+
system?: Content;
|
|
37
|
+
}
|
|
38
|
+
|
|
34
39
|
//General Prompt type for VertexAI
|
|
35
|
-
export type VertexAIPrompt =
|
|
40
|
+
export type VertexAIPrompt = ImagenPrompt | GenerateContentPrompt;
|
|
36
41
|
|
|
37
42
|
export function trimModelName(model: string) {
|
|
38
43
|
const i = model.lastIndexOf("@");
|
|
@@ -46,8 +51,9 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
46
51
|
aiplatform: v1beta1.ModelServiceClient | undefined;
|
|
47
52
|
anthropicClient: AnthropicVertex | undefined;
|
|
48
53
|
fetchClient: FetchClient | undefined;
|
|
54
|
+
googleGenAI: GoogleGenAI | undefined;
|
|
55
|
+
llamaClient: FetchClient & { region?: string } | undefined;
|
|
49
56
|
modelGarden: v1beta1.ModelGardenServiceClient | undefined;
|
|
50
|
-
vertexai: VertexAI | undefined;
|
|
51
57
|
|
|
52
58
|
authClient: JSONClient | GoogleAuth<JSONClient>;
|
|
53
59
|
|
|
@@ -57,12 +63,28 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
57
63
|
this.aiplatform = undefined;
|
|
58
64
|
this.anthropicClient = undefined;
|
|
59
65
|
this.fetchClient = undefined
|
|
66
|
+
this.googleGenAI = undefined;
|
|
60
67
|
this.modelGarden = undefined;
|
|
61
|
-
this.
|
|
68
|
+
this.llamaClient = undefined;
|
|
62
69
|
|
|
63
70
|
this.authClient = options.googleAuthOptions?.authClient ?? new GoogleAuth(options.googleAuthOptions);
|
|
64
71
|
}
|
|
65
72
|
|
|
73
|
+
public getGoogleGenAIClient(): GoogleGenAI {
|
|
74
|
+
//Lazy initialisation
|
|
75
|
+
if (!this.googleGenAI) {
|
|
76
|
+
this.googleGenAI = new GoogleGenAI({
|
|
77
|
+
project: this.options.project,
|
|
78
|
+
location: this.options.region,
|
|
79
|
+
vertexai: true,
|
|
80
|
+
googleAuthOptions: {
|
|
81
|
+
authClient: this.authClient as JSONClient,
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return this.googleGenAI;
|
|
86
|
+
}
|
|
87
|
+
|
|
66
88
|
public getFetchClient(): FetchClient {
|
|
67
89
|
//Lazy initialisation
|
|
68
90
|
if (!this.fetchClient) {
|
|
@@ -78,10 +100,29 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
78
100
|
return this.fetchClient;
|
|
79
101
|
}
|
|
80
102
|
|
|
103
|
+
public getLLamaClient(region: string = "us-central1"): FetchClient {
|
|
104
|
+
//Lazy initialisation
|
|
105
|
+
if (!this.llamaClient || this.llamaClient["region"] !== region) {
|
|
106
|
+
this.llamaClient = createFetchClient({
|
|
107
|
+
region: region,
|
|
108
|
+
project: this.options.project,
|
|
109
|
+
apiVersion: "v1beta1",
|
|
110
|
+
}).withAuthCallback(async () => {
|
|
111
|
+
const accessTokenResponse = await this.authClient.getAccessToken();
|
|
112
|
+
const token = typeof accessTokenResponse === 'string' ? accessTokenResponse : accessTokenResponse?.token;
|
|
113
|
+
return `Bearer ${token}`;
|
|
114
|
+
});
|
|
115
|
+
// Store the region for potential client reuse
|
|
116
|
+
this.llamaClient["region"] = region;
|
|
117
|
+
}
|
|
118
|
+
return this.llamaClient;
|
|
119
|
+
}
|
|
120
|
+
|
|
81
121
|
public getAnthropicClient(): AnthropicVertex {
|
|
82
122
|
//Lazy initialisation
|
|
83
123
|
if (!this.anthropicClient) {
|
|
84
124
|
this.anthropicClient = new AnthropicVertex({
|
|
125
|
+
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
|
|
85
126
|
region: "us-east5",
|
|
86
127
|
projectId: process.env.GOOGLE_PROJECT_ID,
|
|
87
128
|
});
|
|
@@ -89,18 +130,6 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
89
130
|
return this.anthropicClient;
|
|
90
131
|
}
|
|
91
132
|
|
|
92
|
-
public getVertexAIClient(): VertexAI {
|
|
93
|
-
//Lazy initialisation
|
|
94
|
-
if (!this.vertexai) {
|
|
95
|
-
this.vertexai = new VertexAI({
|
|
96
|
-
project: this.options.project,
|
|
97
|
-
location: this.options.region,
|
|
98
|
-
googleAuthOptions: this.options.googleAuthOptions,
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
return this.vertexai;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
133
|
public getAIPlatformClient(): v1beta1.ModelServiceClient {
|
|
105
134
|
//Lazy initialisation
|
|
106
135
|
if (!this.aiplatform) {
|
|
@@ -125,6 +154,18 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
125
154
|
return this.modelGarden;
|
|
126
155
|
}
|
|
127
156
|
|
|
157
|
+
validateResult(result: Completion, options: ExecutionOptions) {
|
|
158
|
+
// Optionally preprocess the result before validation
|
|
159
|
+
const modelDef = getModelDefinition(options.model);
|
|
160
|
+
if (typeof modelDef.preValidationProcessing === "function") {
|
|
161
|
+
const processed = modelDef.preValidationProcessing(result, options);
|
|
162
|
+
result = processed.result;
|
|
163
|
+
options = processed.options;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
super.validateResult(result, options);
|
|
167
|
+
}
|
|
168
|
+
|
|
128
169
|
protected canStream(options: ExecutionOptions): Promise<boolean> {
|
|
129
170
|
if (options.output_modality == Modalities.image) {
|
|
130
171
|
return Promise.resolve(false);
|
|
@@ -145,7 +186,7 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
145
186
|
async requestTextCompletionStream(
|
|
146
187
|
prompt: VertexAIPrompt,
|
|
147
188
|
options: ExecutionOptions,
|
|
148
|
-
): Promise<AsyncIterable<
|
|
189
|
+
): Promise<AsyncIterable<CompletionChunk>> {
|
|
149
190
|
return getModelDefinition(options.model).requestTextCompletionStream(this, prompt, options);
|
|
150
191
|
}
|
|
151
192
|
|
|
@@ -178,14 +219,31 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
178
219
|
);
|
|
179
220
|
|
|
180
221
|
//Model Garden Publisher models - Pretrained models
|
|
181
|
-
const publishers = ["google", "anthropic"];
|
|
182
|
-
|
|
222
|
+
const publishers = ["google", "anthropic", "meta"];
|
|
223
|
+
// Meta "maas" models are LLama Models-As-A-Service. Non-maas models are not pre-deployed.
|
|
224
|
+
const supportedModels = { google: ["gemini", "imagen"], anthropic: ["claude"], meta: ["maas"] };
|
|
225
|
+
// Additional models not in the listings, but we want to include
|
|
226
|
+
// TODO: Remove once the models are available in the listing API, or no longer needed
|
|
227
|
+
const additionalModels = {
|
|
228
|
+
google: ["imagen-3.0-fast-generate-001"],
|
|
229
|
+
anthropic: [],
|
|
230
|
+
meta: [
|
|
231
|
+
"llama-4-maverick-17b-128e-instruct-maas",
|
|
232
|
+
"llama-4-scout-17b-16e-instruct-maas",
|
|
233
|
+
"llama-3.3-70b-instruct-maas",
|
|
234
|
+
"llama-3.2-90b-vision-instruct-maas",
|
|
235
|
+
"llama-3.1-405b-instruct-maas",
|
|
236
|
+
"llama-3.1-70b-instruct-maas",
|
|
237
|
+
"llama-3.1-8b-instruct-maas",
|
|
238
|
+
],
|
|
239
|
+
}
|
|
183
240
|
|
|
184
241
|
//Used to exclude retired models that are still in the listing API but not available for use.
|
|
185
242
|
//Or models we do not support yet
|
|
186
243
|
const unsupportedModelsByPublisher = {
|
|
187
244
|
google: ["gemini-pro", "gemini-ultra"],
|
|
188
245
|
anthropic: [],
|
|
246
|
+
meta: [],
|
|
189
247
|
};
|
|
190
248
|
|
|
191
249
|
for (const publisher of publishers) {
|
|
@@ -228,13 +286,28 @@ export class VertexAIDriver extends AbstractDriver<VertexAIDriverOptions, Vertex
|
|
|
228
286
|
tool_support: modelCapability.tool_support,
|
|
229
287
|
} satisfies AIModel<string>;
|
|
230
288
|
}));
|
|
289
|
+
|
|
290
|
+
// Add additional models that are not in the listing
|
|
291
|
+
for (const additionalModel of additionalModels[publisher as keyof typeof additionalModels]) {
|
|
292
|
+
const publisherModelName = `publishers/${publisher}/models/${additionalModel}`;
|
|
293
|
+
const modelCapability = getModelCapabilities(additionalModel, "vertexai");
|
|
294
|
+
models.push({
|
|
295
|
+
id: publisherModelName,
|
|
296
|
+
name: additionalModel,
|
|
297
|
+
provider: 'vertexai',
|
|
298
|
+
owner: publisher,
|
|
299
|
+
input_modalities: modelModalitiesToArray(modelCapability.input),
|
|
300
|
+
output_modalities: modelModalitiesToArray(modelCapability.output),
|
|
301
|
+
tool_support: modelCapability.tool_support,
|
|
302
|
+
} satisfies AIModel<string>);
|
|
303
|
+
}
|
|
231
304
|
}
|
|
232
305
|
|
|
233
306
|
//Remove duplicates
|
|
234
307
|
const uniqueModels = Array.from(new Set(models.map(a => a.id)))
|
|
235
308
|
.map(id => {
|
|
236
309
|
return models.find(a => a.id === id) ?? {} as AIModel<string>;
|
|
237
|
-
});
|
|
310
|
+
}).sort((a, b) => a.id.localeCompare(b.id));
|
|
238
311
|
|
|
239
312
|
return uniqueModels;
|
|
240
313
|
}
|