@ai-sdk/google-vertex 5.0.0-beta.5 → 5.0.0-beta.52
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/CHANGELOG.md +430 -8
- package/README.md +65 -1
- package/dist/anthropic/edge/index.d.ts +61 -16
- package/dist/anthropic/edge/index.js +67 -60
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +61 -16
- package/dist/anthropic/index.js +57 -55
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +31 -22
- package/dist/edge/index.js +217 -176
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +31 -22
- package/dist/index.js +208 -173
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.d.ts +76 -0
- package/dist/maas/edge/index.js +196 -0
- package/dist/maas/edge/index.js.map +1 -0
- package/dist/maas/index.d.ts +60 -0
- package/dist/maas/index.js +101 -0
- package/dist/maas/index.js.map +1 -0
- package/docs/16-google-vertex.mdx +226 -6
- package/maas/edge.d.ts +1 -0
- package/maas/index.d.ts +1 -0
- package/package.json +29 -18
- package/src/anthropic/edge/google-vertex-anthropic-provider-edge.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-messages-options.ts +1 -0
- package/src/anthropic/google-vertex-anthropic-provider-node.ts +1 -2
- package/src/anthropic/google-vertex-anthropic-provider.ts +33 -8
- package/src/edge/google-vertex-provider-edge.ts +1 -2
- package/src/google-vertex-config.ts +1 -1
- package/src/google-vertex-embedding-model.ts +23 -6
- package/src/google-vertex-embedding-options.ts +2 -0
- package/src/google-vertex-image-model.ts +38 -18
- package/src/google-vertex-options.ts +0 -1
- package/src/google-vertex-provider-node.ts +1 -2
- package/src/google-vertex-provider.ts +12 -12
- package/src/google-vertex-video-model.ts +7 -7
- package/src/maas/edge/google-vertex-maas-provider-edge.ts +65 -0
- package/src/maas/edge/index.ts +9 -0
- package/src/maas/google-vertex-maas-options.ts +15 -0
- package/src/maas/google-vertex-maas-provider-node.ts +64 -0
- package/src/maas/google-vertex-maas-provider.ts +111 -0
- package/src/maas/index.ts +9 -0
- package/dist/anthropic/edge/index.d.mts +0 -231
- package/dist/anthropic/edge/index.mjs +0 -259
- package/dist/anthropic/edge/index.mjs.map +0 -1
- package/dist/anthropic/index.d.mts +0 -215
- package/dist/anthropic/index.mjs +0 -164
- package/dist/anthropic/index.mjs.map +0 -1
- package/dist/edge/index.d.mts +0 -160
- package/dist/edge/index.mjs +0 -1049
- package/dist/edge/index.mjs.map +0 -1
- package/dist/index.d.mts +0 -219
- package/dist/index.mjs +0 -960
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,960 +0,0 @@
|
|
|
1
|
-
// src/google-vertex-provider-node.ts
|
|
2
|
-
import { loadOptionalSetting as loadOptionalSetting2, resolve as resolve5 } from "@ai-sdk/provider-utils";
|
|
3
|
-
|
|
4
|
-
// src/google-vertex-auth-google-auth-library.ts
|
|
5
|
-
import { GoogleAuth } from "google-auth-library";
|
|
6
|
-
var authInstance = null;
|
|
7
|
-
var authOptions = null;
|
|
8
|
-
function getAuth(options) {
|
|
9
|
-
if (!authInstance || options !== authOptions) {
|
|
10
|
-
authInstance = new GoogleAuth({
|
|
11
|
-
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
|
|
12
|
-
...options
|
|
13
|
-
});
|
|
14
|
-
authOptions = options;
|
|
15
|
-
}
|
|
16
|
-
return authInstance;
|
|
17
|
-
}
|
|
18
|
-
async function generateAuthToken(options) {
|
|
19
|
-
const auth = getAuth(options || {});
|
|
20
|
-
const client = await auth.getClient();
|
|
21
|
-
const token = await client.getAccessToken();
|
|
22
|
-
return (token == null ? void 0 : token.token) || null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/google-vertex-provider.ts
|
|
26
|
-
import { GoogleGenerativeAILanguageModel as GoogleGenerativeAILanguageModel2 } from "@ai-sdk/google/internal";
|
|
27
|
-
import {
|
|
28
|
-
generateId,
|
|
29
|
-
loadOptionalSetting,
|
|
30
|
-
loadSetting,
|
|
31
|
-
normalizeHeaders,
|
|
32
|
-
resolve as resolve4,
|
|
33
|
-
withoutTrailingSlash,
|
|
34
|
-
withUserAgentSuffix
|
|
35
|
-
} from "@ai-sdk/provider-utils";
|
|
36
|
-
|
|
37
|
-
// src/version.ts
|
|
38
|
-
var VERSION = true ? "5.0.0-beta.5" : "0.0.0-test";
|
|
39
|
-
|
|
40
|
-
// src/google-vertex-embedding-model.ts
|
|
41
|
-
import {
|
|
42
|
-
TooManyEmbeddingValuesForCallError
|
|
43
|
-
} from "@ai-sdk/provider";
|
|
44
|
-
import {
|
|
45
|
-
combineHeaders,
|
|
46
|
-
createJsonResponseHandler,
|
|
47
|
-
postJsonToApi,
|
|
48
|
-
resolve,
|
|
49
|
-
parseProviderOptions
|
|
50
|
-
} from "@ai-sdk/provider-utils";
|
|
51
|
-
import { z as z3 } from "zod/v4";
|
|
52
|
-
|
|
53
|
-
// src/google-vertex-error.ts
|
|
54
|
-
import { createJsonErrorResponseHandler } from "@ai-sdk/provider-utils";
|
|
55
|
-
import { z } from "zod/v4";
|
|
56
|
-
var googleVertexErrorDataSchema = z.object({
|
|
57
|
-
error: z.object({
|
|
58
|
-
code: z.number().nullable(),
|
|
59
|
-
message: z.string(),
|
|
60
|
-
status: z.string()
|
|
61
|
-
})
|
|
62
|
-
});
|
|
63
|
-
var googleVertexFailedResponseHandler = createJsonErrorResponseHandler(
|
|
64
|
-
{
|
|
65
|
-
errorSchema: googleVertexErrorDataSchema,
|
|
66
|
-
errorToMessage: (data) => data.error.message
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
|
|
70
|
-
// src/google-vertex-embedding-options.ts
|
|
71
|
-
import { z as z2 } from "zod/v4";
|
|
72
|
-
var googleVertexEmbeddingModelOptions = z2.object({
|
|
73
|
-
/**
|
|
74
|
-
* Optional. Optional reduced dimension for the output embedding.
|
|
75
|
-
* If set, excessive values in the output embedding are truncated from the end.
|
|
76
|
-
*/
|
|
77
|
-
outputDimensionality: z2.number().optional(),
|
|
78
|
-
/**
|
|
79
|
-
* Optional. Specifies the task type for generating embeddings.
|
|
80
|
-
* Supported task types:
|
|
81
|
-
* - SEMANTIC_SIMILARITY: Optimized for text similarity.
|
|
82
|
-
* - CLASSIFICATION: Optimized for text classification.
|
|
83
|
-
* - CLUSTERING: Optimized for clustering texts based on similarity.
|
|
84
|
-
* - RETRIEVAL_DOCUMENT: Optimized for document retrieval.
|
|
85
|
-
* - RETRIEVAL_QUERY: Optimized for query-based retrieval.
|
|
86
|
-
* - QUESTION_ANSWERING: Optimized for answering questions.
|
|
87
|
-
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
|
88
|
-
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
|
89
|
-
*/
|
|
90
|
-
taskType: z2.enum([
|
|
91
|
-
"SEMANTIC_SIMILARITY",
|
|
92
|
-
"CLASSIFICATION",
|
|
93
|
-
"CLUSTERING",
|
|
94
|
-
"RETRIEVAL_DOCUMENT",
|
|
95
|
-
"RETRIEVAL_QUERY",
|
|
96
|
-
"QUESTION_ANSWERING",
|
|
97
|
-
"FACT_VERIFICATION",
|
|
98
|
-
"CODE_RETRIEVAL_QUERY"
|
|
99
|
-
]).optional(),
|
|
100
|
-
/**
|
|
101
|
-
* Optional. The title of the document being embedded.
|
|
102
|
-
* Only valid when task_type is set to 'RETRIEVAL_DOCUMENT'.
|
|
103
|
-
* Helps the model produce better embeddings by providing additional context.
|
|
104
|
-
*/
|
|
105
|
-
title: z2.string().optional(),
|
|
106
|
-
/**
|
|
107
|
-
* Optional. When set to true, input text will be truncated. When set to false,
|
|
108
|
-
* an error is returned if the input text is longer than the maximum length supported by the model. Defaults to true.
|
|
109
|
-
*/
|
|
110
|
-
autoTruncate: z2.boolean().optional()
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// src/google-vertex-embedding-model.ts
|
|
114
|
-
var GoogleVertexEmbeddingModel = class {
|
|
115
|
-
constructor(modelId, config) {
|
|
116
|
-
this.specificationVersion = "v3";
|
|
117
|
-
this.maxEmbeddingsPerCall = 2048;
|
|
118
|
-
this.supportsParallelCalls = true;
|
|
119
|
-
this.modelId = modelId;
|
|
120
|
-
this.config = config;
|
|
121
|
-
}
|
|
122
|
-
get provider() {
|
|
123
|
-
return this.config.provider;
|
|
124
|
-
}
|
|
125
|
-
async doEmbed({
|
|
126
|
-
values,
|
|
127
|
-
headers,
|
|
128
|
-
abortSignal,
|
|
129
|
-
providerOptions
|
|
130
|
-
}) {
|
|
131
|
-
let googleOptions = await parseProviderOptions({
|
|
132
|
-
provider: "vertex",
|
|
133
|
-
providerOptions,
|
|
134
|
-
schema: googleVertexEmbeddingModelOptions
|
|
135
|
-
});
|
|
136
|
-
if (googleOptions == null) {
|
|
137
|
-
googleOptions = await parseProviderOptions({
|
|
138
|
-
provider: "google",
|
|
139
|
-
providerOptions,
|
|
140
|
-
schema: googleVertexEmbeddingModelOptions
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
googleOptions = googleOptions != null ? googleOptions : {};
|
|
144
|
-
if (values.length > this.maxEmbeddingsPerCall) {
|
|
145
|
-
throw new TooManyEmbeddingValuesForCallError({
|
|
146
|
-
provider: this.provider,
|
|
147
|
-
modelId: this.modelId,
|
|
148
|
-
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
|
|
149
|
-
values
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
const mergedHeaders = combineHeaders(
|
|
153
|
-
await resolve(this.config.headers),
|
|
154
|
-
headers
|
|
155
|
-
);
|
|
156
|
-
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
157
|
-
const {
|
|
158
|
-
responseHeaders,
|
|
159
|
-
value: response,
|
|
160
|
-
rawValue
|
|
161
|
-
} = await postJsonToApi({
|
|
162
|
-
url,
|
|
163
|
-
headers: mergedHeaders,
|
|
164
|
-
body: {
|
|
165
|
-
instances: values.map((value) => ({
|
|
166
|
-
content: value,
|
|
167
|
-
task_type: googleOptions.taskType,
|
|
168
|
-
title: googleOptions.title
|
|
169
|
-
})),
|
|
170
|
-
parameters: {
|
|
171
|
-
outputDimensionality: googleOptions.outputDimensionality,
|
|
172
|
-
autoTruncate: googleOptions.autoTruncate
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
176
|
-
successfulResponseHandler: createJsonResponseHandler(
|
|
177
|
-
googleVertexTextEmbeddingResponseSchema
|
|
178
|
-
),
|
|
179
|
-
abortSignal,
|
|
180
|
-
fetch: this.config.fetch
|
|
181
|
-
});
|
|
182
|
-
return {
|
|
183
|
-
warnings: [],
|
|
184
|
-
embeddings: response.predictions.map(
|
|
185
|
-
(prediction) => prediction.embeddings.values
|
|
186
|
-
),
|
|
187
|
-
usage: {
|
|
188
|
-
tokens: response.predictions.reduce(
|
|
189
|
-
(tokenCount, prediction) => tokenCount + prediction.embeddings.statistics.token_count,
|
|
190
|
-
0
|
|
191
|
-
)
|
|
192
|
-
},
|
|
193
|
-
response: { headers: responseHeaders, body: rawValue }
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
var googleVertexTextEmbeddingResponseSchema = z3.object({
|
|
198
|
-
predictions: z3.array(
|
|
199
|
-
z3.object({
|
|
200
|
-
embeddings: z3.object({
|
|
201
|
-
values: z3.array(z3.number()),
|
|
202
|
-
statistics: z3.object({
|
|
203
|
-
token_count: z3.number()
|
|
204
|
-
})
|
|
205
|
-
})
|
|
206
|
-
})
|
|
207
|
-
)
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
// src/google-vertex-image-model.ts
|
|
211
|
-
import { GoogleGenerativeAILanguageModel } from "@ai-sdk/google/internal";
|
|
212
|
-
import {
|
|
213
|
-
combineHeaders as combineHeaders2,
|
|
214
|
-
convertToBase64,
|
|
215
|
-
convertUint8ArrayToBase64,
|
|
216
|
-
createJsonResponseHandler as createJsonResponseHandler2,
|
|
217
|
-
generateId as defaultGenerateId,
|
|
218
|
-
parseProviderOptions as parseProviderOptions2,
|
|
219
|
-
postJsonToApi as postJsonToApi2,
|
|
220
|
-
resolve as resolve2
|
|
221
|
-
} from "@ai-sdk/provider-utils";
|
|
222
|
-
import { z as z4 } from "zod/v4";
|
|
223
|
-
var GoogleVertexImageModel = class {
|
|
224
|
-
constructor(modelId, config) {
|
|
225
|
-
this.modelId = modelId;
|
|
226
|
-
this.config = config;
|
|
227
|
-
this.specificationVersion = "v3";
|
|
228
|
-
}
|
|
229
|
-
get maxImagesPerCall() {
|
|
230
|
-
if (isGeminiModel(this.modelId)) {
|
|
231
|
-
return 10;
|
|
232
|
-
}
|
|
233
|
-
return 4;
|
|
234
|
-
}
|
|
235
|
-
get provider() {
|
|
236
|
-
return this.config.provider;
|
|
237
|
-
}
|
|
238
|
-
async doGenerate(options) {
|
|
239
|
-
if (isGeminiModel(this.modelId)) {
|
|
240
|
-
return this.doGenerateGemini(options);
|
|
241
|
-
}
|
|
242
|
-
return this.doGenerateImagen(options);
|
|
243
|
-
}
|
|
244
|
-
async doGenerateImagen({
|
|
245
|
-
prompt,
|
|
246
|
-
n,
|
|
247
|
-
size,
|
|
248
|
-
aspectRatio,
|
|
249
|
-
seed,
|
|
250
|
-
providerOptions,
|
|
251
|
-
headers,
|
|
252
|
-
abortSignal,
|
|
253
|
-
files,
|
|
254
|
-
mask
|
|
255
|
-
}) {
|
|
256
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
257
|
-
const warnings = [];
|
|
258
|
-
if (size != null) {
|
|
259
|
-
warnings.push({
|
|
260
|
-
type: "unsupported",
|
|
261
|
-
feature: "size",
|
|
262
|
-
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
263
|
-
});
|
|
264
|
-
}
|
|
265
|
-
const vertexImageOptions = await parseProviderOptions2({
|
|
266
|
-
provider: "vertex",
|
|
267
|
-
providerOptions,
|
|
268
|
-
schema: googleVertexImageModelOptionsSchema
|
|
269
|
-
});
|
|
270
|
-
const { edit, ...otherOptions } = vertexImageOptions != null ? vertexImageOptions : {};
|
|
271
|
-
const { mode: editMode, baseSteps, maskMode, maskDilation } = edit != null ? edit : {};
|
|
272
|
-
const isEditMode = files != null && files.length > 0;
|
|
273
|
-
let body;
|
|
274
|
-
if (isEditMode) {
|
|
275
|
-
const referenceImages = [];
|
|
276
|
-
for (let i = 0; i < files.length; i++) {
|
|
277
|
-
const file = files[i];
|
|
278
|
-
referenceImages.push({
|
|
279
|
-
referenceType: "REFERENCE_TYPE_RAW",
|
|
280
|
-
referenceId: i + 1,
|
|
281
|
-
referenceImage: {
|
|
282
|
-
bytesBase64Encoded: getBase64Data(file)
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
}
|
|
286
|
-
if (mask != null) {
|
|
287
|
-
referenceImages.push({
|
|
288
|
-
referenceType: "REFERENCE_TYPE_MASK",
|
|
289
|
-
referenceId: files.length + 1,
|
|
290
|
-
referenceImage: {
|
|
291
|
-
bytesBase64Encoded: getBase64Data(mask)
|
|
292
|
-
},
|
|
293
|
-
maskImageConfig: {
|
|
294
|
-
maskMode: maskMode != null ? maskMode : "MASK_MODE_USER_PROVIDED",
|
|
295
|
-
...maskDilation != null ? { dilation: maskDilation } : {}
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
}
|
|
299
|
-
body = {
|
|
300
|
-
instances: [
|
|
301
|
-
{
|
|
302
|
-
prompt,
|
|
303
|
-
referenceImages
|
|
304
|
-
}
|
|
305
|
-
],
|
|
306
|
-
parameters: {
|
|
307
|
-
sampleCount: n,
|
|
308
|
-
...aspectRatio != null ? { aspectRatio } : {},
|
|
309
|
-
...seed != null ? { seed } : {},
|
|
310
|
-
editMode: editMode != null ? editMode : "EDIT_MODE_INPAINT_INSERTION",
|
|
311
|
-
...baseSteps != null ? { editConfig: { baseSteps } } : {},
|
|
312
|
-
...otherOptions
|
|
313
|
-
}
|
|
314
|
-
};
|
|
315
|
-
} else {
|
|
316
|
-
body = {
|
|
317
|
-
instances: [{ prompt }],
|
|
318
|
-
parameters: {
|
|
319
|
-
sampleCount: n,
|
|
320
|
-
...aspectRatio != null ? { aspectRatio } : {},
|
|
321
|
-
...seed != null ? { seed } : {},
|
|
322
|
-
...otherOptions
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
}
|
|
326
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
327
|
-
const { value: response, responseHeaders } = await postJsonToApi2({
|
|
328
|
-
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
|
329
|
-
headers: combineHeaders2(await resolve2(this.config.headers), headers),
|
|
330
|
-
body,
|
|
331
|
-
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
332
|
-
successfulResponseHandler: createJsonResponseHandler2(
|
|
333
|
-
vertexImageResponseSchema
|
|
334
|
-
),
|
|
335
|
-
abortSignal,
|
|
336
|
-
fetch: this.config.fetch
|
|
337
|
-
});
|
|
338
|
-
return {
|
|
339
|
-
images: (_e = (_d = response.predictions) == null ? void 0 : _d.map(
|
|
340
|
-
({ bytesBase64Encoded }) => bytesBase64Encoded
|
|
341
|
-
)) != null ? _e : [],
|
|
342
|
-
warnings,
|
|
343
|
-
response: {
|
|
344
|
-
timestamp: currentDate,
|
|
345
|
-
modelId: this.modelId,
|
|
346
|
-
headers: responseHeaders
|
|
347
|
-
},
|
|
348
|
-
providerMetadata: {
|
|
349
|
-
vertex: {
|
|
350
|
-
images: (_g = (_f = response.predictions) == null ? void 0 : _f.map((prediction) => {
|
|
351
|
-
const {
|
|
352
|
-
// normalize revised prompt property
|
|
353
|
-
prompt: revisedPrompt
|
|
354
|
-
} = prediction;
|
|
355
|
-
return { ...revisedPrompt != null && { revisedPrompt } };
|
|
356
|
-
})) != null ? _g : []
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
async doGenerateGemini({
|
|
362
|
-
prompt,
|
|
363
|
-
n,
|
|
364
|
-
size,
|
|
365
|
-
aspectRatio,
|
|
366
|
-
seed,
|
|
367
|
-
providerOptions,
|
|
368
|
-
headers,
|
|
369
|
-
abortSignal,
|
|
370
|
-
files,
|
|
371
|
-
mask
|
|
372
|
-
}) {
|
|
373
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
374
|
-
const warnings = [];
|
|
375
|
-
if (mask != null) {
|
|
376
|
-
throw new Error(
|
|
377
|
-
"Gemini image models do not support mask-based image editing."
|
|
378
|
-
);
|
|
379
|
-
}
|
|
380
|
-
if (n != null && n > 1) {
|
|
381
|
-
throw new Error(
|
|
382
|
-
"Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter."
|
|
383
|
-
);
|
|
384
|
-
}
|
|
385
|
-
if (size != null) {
|
|
386
|
-
warnings.push({
|
|
387
|
-
type: "unsupported",
|
|
388
|
-
feature: "size",
|
|
389
|
-
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
390
|
-
});
|
|
391
|
-
}
|
|
392
|
-
const userContent = [];
|
|
393
|
-
if (prompt != null) {
|
|
394
|
-
userContent.push({ type: "text", text: prompt });
|
|
395
|
-
}
|
|
396
|
-
if (files != null && files.length > 0) {
|
|
397
|
-
for (const file of files) {
|
|
398
|
-
if (file.type === "url") {
|
|
399
|
-
userContent.push({
|
|
400
|
-
type: "file",
|
|
401
|
-
data: new URL(file.url),
|
|
402
|
-
mediaType: "image/*"
|
|
403
|
-
});
|
|
404
|
-
} else {
|
|
405
|
-
userContent.push({
|
|
406
|
-
type: "file",
|
|
407
|
-
data: typeof file.data === "string" ? file.data : new Uint8Array(file.data),
|
|
408
|
-
mediaType: file.mediaType
|
|
409
|
-
});
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
const languageModelPrompt = [
|
|
414
|
-
{ role: "user", content: userContent }
|
|
415
|
-
];
|
|
416
|
-
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
417
|
-
provider: this.config.provider,
|
|
418
|
-
baseURL: this.config.baseURL,
|
|
419
|
-
headers: (_a = this.config.headers) != null ? _a : {},
|
|
420
|
-
fetch: this.config.fetch,
|
|
421
|
-
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId,
|
|
422
|
-
supportedUrls: () => ({
|
|
423
|
-
"*": [/^https?:\/\/.*$/, /^gs:\/\/.*$/]
|
|
424
|
-
})
|
|
425
|
-
});
|
|
426
|
-
const result = await languageModel.doGenerate({
|
|
427
|
-
prompt: languageModelPrompt,
|
|
428
|
-
seed,
|
|
429
|
-
providerOptions: {
|
|
430
|
-
vertex: {
|
|
431
|
-
responseModalities: ["IMAGE"],
|
|
432
|
-
imageConfig: aspectRatio ? {
|
|
433
|
-
aspectRatio
|
|
434
|
-
} : void 0,
|
|
435
|
-
...(_c = providerOptions == null ? void 0 : providerOptions.vertex) != null ? _c : {}
|
|
436
|
-
}
|
|
437
|
-
},
|
|
438
|
-
headers,
|
|
439
|
-
abortSignal
|
|
440
|
-
});
|
|
441
|
-
const currentDate = (_f = (_e = (_d = this.config._internal) == null ? void 0 : _d.currentDate) == null ? void 0 : _e.call(_d)) != null ? _f : /* @__PURE__ */ new Date();
|
|
442
|
-
const images = [];
|
|
443
|
-
for (const part of result.content) {
|
|
444
|
-
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
445
|
-
images.push(convertToBase64(part.data));
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
return {
|
|
449
|
-
images,
|
|
450
|
-
warnings,
|
|
451
|
-
providerMetadata: {
|
|
452
|
-
vertex: {
|
|
453
|
-
images: images.map(() => ({}))
|
|
454
|
-
}
|
|
455
|
-
},
|
|
456
|
-
response: {
|
|
457
|
-
timestamp: currentDate,
|
|
458
|
-
modelId: this.modelId,
|
|
459
|
-
headers: (_g = result.response) == null ? void 0 : _g.headers
|
|
460
|
-
},
|
|
461
|
-
usage: result.usage ? {
|
|
462
|
-
inputTokens: result.usage.inputTokens.total,
|
|
463
|
-
outputTokens: result.usage.outputTokens.total,
|
|
464
|
-
totalTokens: ((_h = result.usage.inputTokens.total) != null ? _h : 0) + ((_i = result.usage.outputTokens.total) != null ? _i : 0)
|
|
465
|
-
} : void 0
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
};
|
|
469
|
-
function isGeminiModel(modelId) {
|
|
470
|
-
return modelId.startsWith("gemini-");
|
|
471
|
-
}
|
|
472
|
-
var vertexImageResponseSchema = z4.object({
|
|
473
|
-
predictions: z4.array(
|
|
474
|
-
z4.object({
|
|
475
|
-
bytesBase64Encoded: z4.string(),
|
|
476
|
-
mimeType: z4.string(),
|
|
477
|
-
prompt: z4.string().nullish()
|
|
478
|
-
})
|
|
479
|
-
).nullish()
|
|
480
|
-
});
|
|
481
|
-
var googleVertexImageModelOptionsSchema = z4.object({
|
|
482
|
-
negativePrompt: z4.string().nullish(),
|
|
483
|
-
personGeneration: z4.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
484
|
-
safetySetting: z4.enum([
|
|
485
|
-
"block_low_and_above",
|
|
486
|
-
"block_medium_and_above",
|
|
487
|
-
"block_only_high",
|
|
488
|
-
"block_none"
|
|
489
|
-
]).nullish(),
|
|
490
|
-
addWatermark: z4.boolean().nullish(),
|
|
491
|
-
storageUri: z4.string().nullish(),
|
|
492
|
-
sampleImageSize: z4.enum(["1K", "2K"]).nullish(),
|
|
493
|
-
/**
|
|
494
|
-
* Configuration for image editing operations
|
|
495
|
-
*/
|
|
496
|
-
edit: z4.object({
|
|
497
|
-
/**
|
|
498
|
-
* An integer that represents the number of sampling steps.
|
|
499
|
-
* A higher value offers better image quality, a lower value offers better latency.
|
|
500
|
-
* Try 35 steps to start. If the quality doesn't meet your requirements,
|
|
501
|
-
* increase the value towards an upper limit of 75.
|
|
502
|
-
*/
|
|
503
|
-
baseSteps: z4.number().nullish(),
|
|
504
|
-
// Edit mode options
|
|
505
|
-
// https://cloud.google.com/vertex-ai/generative-ai/docs/image/edit-insert-objects
|
|
506
|
-
mode: z4.enum([
|
|
507
|
-
"EDIT_MODE_INPAINT_INSERTION",
|
|
508
|
-
"EDIT_MODE_INPAINT_REMOVAL",
|
|
509
|
-
"EDIT_MODE_OUTPAINT",
|
|
510
|
-
"EDIT_MODE_CONTROLLED_EDITING",
|
|
511
|
-
"EDIT_MODE_PRODUCT_IMAGE",
|
|
512
|
-
"EDIT_MODE_BGSWAP"
|
|
513
|
-
]).nullish(),
|
|
514
|
-
/**
|
|
515
|
-
* The mask mode to use.
|
|
516
|
-
* - `MASK_MODE_DEFAULT` - Default value for mask mode.
|
|
517
|
-
* - `MASK_MODE_USER_PROVIDED` - User provided mask. No segmentation needed.
|
|
518
|
-
* - `MASK_MODE_DETECTION_BOX` - Mask from detected bounding boxes.
|
|
519
|
-
* - `MASK_MODE_CLOTHING_AREA` - Masks from segmenting the clothing area with open-vocab segmentation.
|
|
520
|
-
* - `MASK_MODE_PARSED_PERSON` - Masks from segmenting the person body and clothing using the person-parsing model.
|
|
521
|
-
*/
|
|
522
|
-
maskMode: z4.enum([
|
|
523
|
-
"MASK_MODE_DEFAULT",
|
|
524
|
-
"MASK_MODE_USER_PROVIDED",
|
|
525
|
-
"MASK_MODE_DETECTION_BOX",
|
|
526
|
-
"MASK_MODE_CLOTHING_AREA",
|
|
527
|
-
"MASK_MODE_PARSED_PERSON"
|
|
528
|
-
]).nullish(),
|
|
529
|
-
/**
|
|
530
|
-
* Optional. A float value between 0 and 1, inclusive, that represents the
|
|
531
|
-
* percentage of the image width to grow the mask by. Using dilation helps
|
|
532
|
-
* compensate for imprecise masks. We recommend a value of 0.01.
|
|
533
|
-
*/
|
|
534
|
-
maskDilation: z4.number().nullish()
|
|
535
|
-
}).nullish()
|
|
536
|
-
});
|
|
537
|
-
function getBase64Data(file) {
|
|
538
|
-
if (file.type === "url") {
|
|
539
|
-
throw new Error(
|
|
540
|
-
"URL-based images are not supported for Google Vertex image editing. Please provide the image data directly."
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
if (typeof file.data === "string") {
|
|
544
|
-
return file.data;
|
|
545
|
-
}
|
|
546
|
-
return convertUint8ArrayToBase64(file.data);
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
// src/google-vertex-tools.ts
|
|
550
|
-
import { googleTools } from "@ai-sdk/google/internal";
|
|
551
|
-
var googleVertexTools = {
|
|
552
|
-
googleSearch: googleTools.googleSearch,
|
|
553
|
-
enterpriseWebSearch: googleTools.enterpriseWebSearch,
|
|
554
|
-
googleMaps: googleTools.googleMaps,
|
|
555
|
-
urlContext: googleTools.urlContext,
|
|
556
|
-
fileSearch: googleTools.fileSearch,
|
|
557
|
-
codeExecution: googleTools.codeExecution,
|
|
558
|
-
vertexRagStore: googleTools.vertexRagStore
|
|
559
|
-
};
|
|
560
|
-
|
|
561
|
-
// src/google-vertex-video-model.ts
|
|
562
|
-
import {
|
|
563
|
-
AISDKError
|
|
564
|
-
} from "@ai-sdk/provider";
|
|
565
|
-
import {
|
|
566
|
-
combineHeaders as combineHeaders3,
|
|
567
|
-
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
568
|
-
createJsonResponseHandler as createJsonResponseHandler3,
|
|
569
|
-
delay,
|
|
570
|
-
lazySchema,
|
|
571
|
-
parseProviderOptions as parseProviderOptions3,
|
|
572
|
-
postJsonToApi as postJsonToApi3,
|
|
573
|
-
resolve as resolve3,
|
|
574
|
-
zodSchema
|
|
575
|
-
} from "@ai-sdk/provider-utils";
|
|
576
|
-
import { z as z5 } from "zod/v4";
|
|
577
|
-
var GoogleVertexVideoModel = class {
|
|
578
|
-
constructor(modelId, config) {
|
|
579
|
-
this.modelId = modelId;
|
|
580
|
-
this.config = config;
|
|
581
|
-
this.specificationVersion = "v3";
|
|
582
|
-
}
|
|
583
|
-
get provider() {
|
|
584
|
-
return this.config.provider;
|
|
585
|
-
}
|
|
586
|
-
get maxVideosPerCall() {
|
|
587
|
-
return 4;
|
|
588
|
-
}
|
|
589
|
-
async doGenerate(options) {
|
|
590
|
-
var _a, _b, _c, _d, _e, _f;
|
|
591
|
-
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
592
|
-
const warnings = [];
|
|
593
|
-
const vertexOptions = await parseProviderOptions3({
|
|
594
|
-
provider: "vertex",
|
|
595
|
-
providerOptions: options.providerOptions,
|
|
596
|
-
schema: googleVertexVideoModelOptionsSchema
|
|
597
|
-
});
|
|
598
|
-
const instances = [{}];
|
|
599
|
-
const instance = instances[0];
|
|
600
|
-
if (options.prompt != null) {
|
|
601
|
-
instance.prompt = options.prompt;
|
|
602
|
-
}
|
|
603
|
-
if (options.image != null) {
|
|
604
|
-
if (options.image.type === "url") {
|
|
605
|
-
warnings.push({
|
|
606
|
-
type: "unsupported",
|
|
607
|
-
feature: "URL-based image input",
|
|
608
|
-
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
609
|
-
});
|
|
610
|
-
} else {
|
|
611
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase642(options.image.data);
|
|
612
|
-
instance.image = {
|
|
613
|
-
bytesBase64Encoded: base64Data,
|
|
614
|
-
mimeType: options.image.mediaType
|
|
615
|
-
};
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
if ((vertexOptions == null ? void 0 : vertexOptions.referenceImages) != null) {
|
|
619
|
-
instance.referenceImages = vertexOptions.referenceImages;
|
|
620
|
-
}
|
|
621
|
-
const parameters = {
|
|
622
|
-
sampleCount: options.n
|
|
623
|
-
};
|
|
624
|
-
if (options.aspectRatio) {
|
|
625
|
-
parameters.aspectRatio = options.aspectRatio;
|
|
626
|
-
}
|
|
627
|
-
if (options.resolution) {
|
|
628
|
-
const resolutionMap = {
|
|
629
|
-
"1280x720": "720p",
|
|
630
|
-
"1920x1080": "1080p",
|
|
631
|
-
"3840x2160": "4k"
|
|
632
|
-
};
|
|
633
|
-
parameters.resolution = resolutionMap[options.resolution] || options.resolution;
|
|
634
|
-
}
|
|
635
|
-
if (options.duration) {
|
|
636
|
-
parameters.durationSeconds = options.duration;
|
|
637
|
-
}
|
|
638
|
-
if (options.seed) {
|
|
639
|
-
parameters.seed = options.seed;
|
|
640
|
-
}
|
|
641
|
-
if (vertexOptions != null) {
|
|
642
|
-
const opts = vertexOptions;
|
|
643
|
-
if (opts.personGeneration !== void 0 && opts.personGeneration !== null) {
|
|
644
|
-
parameters.personGeneration = opts.personGeneration;
|
|
645
|
-
}
|
|
646
|
-
if (opts.negativePrompt !== void 0 && opts.negativePrompt !== null) {
|
|
647
|
-
parameters.negativePrompt = opts.negativePrompt;
|
|
648
|
-
}
|
|
649
|
-
if (opts.generateAudio !== void 0 && opts.generateAudio !== null) {
|
|
650
|
-
parameters.generateAudio = opts.generateAudio;
|
|
651
|
-
}
|
|
652
|
-
if (opts.gcsOutputDirectory !== void 0 && opts.gcsOutputDirectory !== null) {
|
|
653
|
-
parameters.gcsOutputDirectory = opts.gcsOutputDirectory;
|
|
654
|
-
}
|
|
655
|
-
for (const [key, value] of Object.entries(opts)) {
|
|
656
|
-
if (![
|
|
657
|
-
"pollIntervalMs",
|
|
658
|
-
"pollTimeoutMs",
|
|
659
|
-
"personGeneration",
|
|
660
|
-
"negativePrompt",
|
|
661
|
-
"generateAudio",
|
|
662
|
-
"gcsOutputDirectory",
|
|
663
|
-
"referenceImages"
|
|
664
|
-
].includes(key)) {
|
|
665
|
-
parameters[key] = value;
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
const { value: operation } = await postJsonToApi3({
|
|
670
|
-
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
671
|
-
headers: combineHeaders3(
|
|
672
|
-
await resolve3(this.config.headers),
|
|
673
|
-
options.headers
|
|
674
|
-
),
|
|
675
|
-
body: {
|
|
676
|
-
instances,
|
|
677
|
-
parameters
|
|
678
|
-
},
|
|
679
|
-
successfulResponseHandler: createJsonResponseHandler3(
|
|
680
|
-
vertexOperationSchema
|
|
681
|
-
),
|
|
682
|
-
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
683
|
-
abortSignal: options.abortSignal,
|
|
684
|
-
fetch: this.config.fetch
|
|
685
|
-
});
|
|
686
|
-
const operationName = operation.name;
|
|
687
|
-
if (!operationName) {
|
|
688
|
-
throw new AISDKError({
|
|
689
|
-
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
690
|
-
message: "No operation name returned from API"
|
|
691
|
-
});
|
|
692
|
-
}
|
|
693
|
-
const pollIntervalMs = (_d = vertexOptions == null ? void 0 : vertexOptions.pollIntervalMs) != null ? _d : 1e4;
|
|
694
|
-
const pollTimeoutMs = (_e = vertexOptions == null ? void 0 : vertexOptions.pollTimeoutMs) != null ? _e : 6e5;
|
|
695
|
-
const startTime = Date.now();
|
|
696
|
-
let finalOperation = operation;
|
|
697
|
-
let responseHeaders;
|
|
698
|
-
while (!finalOperation.done) {
|
|
699
|
-
if (Date.now() - startTime > pollTimeoutMs) {
|
|
700
|
-
throw new AISDKError({
|
|
701
|
-
name: "VERTEX_VIDEO_GENERATION_TIMEOUT",
|
|
702
|
-
message: `Video generation timed out after ${pollTimeoutMs}ms`
|
|
703
|
-
});
|
|
704
|
-
}
|
|
705
|
-
await delay(pollIntervalMs);
|
|
706
|
-
if ((_f = options.abortSignal) == null ? void 0 : _f.aborted) {
|
|
707
|
-
throw new AISDKError({
|
|
708
|
-
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
709
|
-
message: "Video generation request was aborted"
|
|
710
|
-
});
|
|
711
|
-
}
|
|
712
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi3({
|
|
713
|
-
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
714
|
-
headers: combineHeaders3(
|
|
715
|
-
await resolve3(this.config.headers),
|
|
716
|
-
options.headers
|
|
717
|
-
),
|
|
718
|
-
body: {
|
|
719
|
-
operationName
|
|
720
|
-
},
|
|
721
|
-
successfulResponseHandler: createJsonResponseHandler3(
|
|
722
|
-
vertexOperationSchema
|
|
723
|
-
),
|
|
724
|
-
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
725
|
-
abortSignal: options.abortSignal,
|
|
726
|
-
fetch: this.config.fetch
|
|
727
|
-
});
|
|
728
|
-
finalOperation = statusOperation;
|
|
729
|
-
responseHeaders = pollHeaders;
|
|
730
|
-
}
|
|
731
|
-
if (finalOperation.error) {
|
|
732
|
-
throw new AISDKError({
|
|
733
|
-
name: "VERTEX_VIDEO_GENERATION_FAILED",
|
|
734
|
-
message: `Video generation failed: ${finalOperation.error.message}`
|
|
735
|
-
});
|
|
736
|
-
}
|
|
737
|
-
const response = finalOperation.response;
|
|
738
|
-
if (!(response == null ? void 0 : response.videos) || response.videos.length === 0) {
|
|
739
|
-
throw new AISDKError({
|
|
740
|
-
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
741
|
-
message: `No videos in response. Response: ${JSON.stringify(finalOperation)}`
|
|
742
|
-
});
|
|
743
|
-
}
|
|
744
|
-
const videos = [];
|
|
745
|
-
const videoMetadata = [];
|
|
746
|
-
for (const video of response.videos) {
|
|
747
|
-
if (video.bytesBase64Encoded) {
|
|
748
|
-
videos.push({
|
|
749
|
-
type: "base64",
|
|
750
|
-
data: video.bytesBase64Encoded,
|
|
751
|
-
mediaType: video.mimeType || "video/mp4"
|
|
752
|
-
});
|
|
753
|
-
videoMetadata.push({
|
|
754
|
-
mimeType: video.mimeType
|
|
755
|
-
});
|
|
756
|
-
} else if (video.gcsUri) {
|
|
757
|
-
videos.push({
|
|
758
|
-
type: "url",
|
|
759
|
-
url: video.gcsUri,
|
|
760
|
-
mediaType: video.mimeType || "video/mp4"
|
|
761
|
-
});
|
|
762
|
-
videoMetadata.push({
|
|
763
|
-
gcsUri: video.gcsUri,
|
|
764
|
-
mimeType: video.mimeType
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
}
|
|
768
|
-
if (videos.length === 0) {
|
|
769
|
-
throw new AISDKError({
|
|
770
|
-
name: "VERTEX_VIDEO_GENERATION_ERROR",
|
|
771
|
-
message: "No valid videos in response"
|
|
772
|
-
});
|
|
773
|
-
}
|
|
774
|
-
return {
|
|
775
|
-
videos,
|
|
776
|
-
warnings,
|
|
777
|
-
response: {
|
|
778
|
-
timestamp: currentDate,
|
|
779
|
-
modelId: this.modelId,
|
|
780
|
-
headers: responseHeaders
|
|
781
|
-
},
|
|
782
|
-
providerMetadata: {
|
|
783
|
-
"google-vertex": {
|
|
784
|
-
videos: videoMetadata
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
var vertexOperationSchema = z5.object({
|
|
791
|
-
name: z5.string().nullish(),
|
|
792
|
-
done: z5.boolean().nullish(),
|
|
793
|
-
error: z5.object({
|
|
794
|
-
code: z5.number().nullish(),
|
|
795
|
-
message: z5.string(),
|
|
796
|
-
status: z5.string().nullish()
|
|
797
|
-
}).nullish(),
|
|
798
|
-
response: z5.object({
|
|
799
|
-
videos: z5.array(
|
|
800
|
-
z5.object({
|
|
801
|
-
bytesBase64Encoded: z5.string().nullish(),
|
|
802
|
-
gcsUri: z5.string().nullish(),
|
|
803
|
-
mimeType: z5.string().nullish()
|
|
804
|
-
})
|
|
805
|
-
).nullish(),
|
|
806
|
-
raiMediaFilteredCount: z5.number().nullish()
|
|
807
|
-
}).nullish()
|
|
808
|
-
});
|
|
809
|
-
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
810
|
-
() => zodSchema(
|
|
811
|
-
z5.object({
|
|
812
|
-
pollIntervalMs: z5.number().positive().nullish(),
|
|
813
|
-
pollTimeoutMs: z5.number().positive().nullish(),
|
|
814
|
-
personGeneration: z5.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
815
|
-
negativePrompt: z5.string().nullish(),
|
|
816
|
-
generateAudio: z5.boolean().nullish(),
|
|
817
|
-
gcsOutputDirectory: z5.string().nullish(),
|
|
818
|
-
referenceImages: z5.array(
|
|
819
|
-
z5.object({
|
|
820
|
-
bytesBase64Encoded: z5.string().nullish(),
|
|
821
|
-
gcsUri: z5.string().nullish()
|
|
822
|
-
})
|
|
823
|
-
).nullish()
|
|
824
|
-
}).passthrough()
|
|
825
|
-
)
|
|
826
|
-
);
|
|
827
|
-
|
|
828
|
-
// src/google-vertex-provider.ts
|
|
829
|
-
var EXPRESS_MODE_BASE_URL = "https://aiplatform.googleapis.com/v1/publishers/google";
|
|
830
|
-
function createExpressModeFetch(apiKey, customFetch) {
|
|
831
|
-
return async (url, init) => {
|
|
832
|
-
const modifiedInit = {
|
|
833
|
-
...init,
|
|
834
|
-
headers: {
|
|
835
|
-
...(init == null ? void 0 : init.headers) ? normalizeHeaders(init.headers) : {},
|
|
836
|
-
"x-goog-api-key": apiKey
|
|
837
|
-
}
|
|
838
|
-
};
|
|
839
|
-
return (customFetch != null ? customFetch : fetch)(url.toString(), modifiedInit);
|
|
840
|
-
};
|
|
841
|
-
}
|
|
842
|
-
function createVertex(options = {}) {
|
|
843
|
-
const apiKey = loadOptionalSetting({
|
|
844
|
-
settingValue: options.apiKey,
|
|
845
|
-
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
846
|
-
});
|
|
847
|
-
const loadVertexProject = () => loadSetting({
|
|
848
|
-
settingValue: options.project,
|
|
849
|
-
settingName: "project",
|
|
850
|
-
environmentVariableName: "GOOGLE_VERTEX_PROJECT",
|
|
851
|
-
description: "Google Vertex project"
|
|
852
|
-
});
|
|
853
|
-
const loadVertexLocation = () => loadSetting({
|
|
854
|
-
settingValue: options.location,
|
|
855
|
-
settingName: "location",
|
|
856
|
-
environmentVariableName: "GOOGLE_VERTEX_LOCATION",
|
|
857
|
-
description: "Google Vertex location"
|
|
858
|
-
});
|
|
859
|
-
const loadBaseURL = () => {
|
|
860
|
-
var _a, _b;
|
|
861
|
-
if (apiKey) {
|
|
862
|
-
return (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : EXPRESS_MODE_BASE_URL;
|
|
863
|
-
}
|
|
864
|
-
const region = loadVertexLocation();
|
|
865
|
-
const project = loadVertexProject();
|
|
866
|
-
const baseHost = `${region === "global" ? "" : region + "-"}aiplatform.googleapis.com`;
|
|
867
|
-
return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${baseHost}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
868
|
-
};
|
|
869
|
-
const createConfig = (name) => {
|
|
870
|
-
const getHeaders = async () => {
|
|
871
|
-
var _a;
|
|
872
|
-
const originalHeaders = await resolve4((_a = options.headers) != null ? _a : {});
|
|
873
|
-
return withUserAgentSuffix(
|
|
874
|
-
originalHeaders,
|
|
875
|
-
`ai-sdk/google-vertex/${VERSION}`
|
|
876
|
-
);
|
|
877
|
-
};
|
|
878
|
-
return {
|
|
879
|
-
provider: `google.vertex.${name}`,
|
|
880
|
-
headers: getHeaders,
|
|
881
|
-
fetch: apiKey ? createExpressModeFetch(apiKey, options.fetch) : options.fetch,
|
|
882
|
-
baseURL: loadBaseURL()
|
|
883
|
-
};
|
|
884
|
-
};
|
|
885
|
-
const createChatModel = (modelId) => {
|
|
886
|
-
var _a;
|
|
887
|
-
return new GoogleGenerativeAILanguageModel2(modelId, {
|
|
888
|
-
...createConfig("chat"),
|
|
889
|
-
generateId: (_a = options.generateId) != null ? _a : generateId,
|
|
890
|
-
supportedUrls: () => ({
|
|
891
|
-
"*": [
|
|
892
|
-
// HTTP URLs:
|
|
893
|
-
/^https?:\/\/.*$/,
|
|
894
|
-
// Google Cloud Storage URLs:
|
|
895
|
-
/^gs:\/\/.*$/
|
|
896
|
-
]
|
|
897
|
-
})
|
|
898
|
-
});
|
|
899
|
-
};
|
|
900
|
-
const createEmbeddingModel = (modelId) => new GoogleVertexEmbeddingModel(modelId, createConfig("embedding"));
|
|
901
|
-
const createImageModel = (modelId) => {
|
|
902
|
-
var _a;
|
|
903
|
-
return new GoogleVertexImageModel(modelId, {
|
|
904
|
-
...createConfig("image"),
|
|
905
|
-
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
906
|
-
});
|
|
907
|
-
};
|
|
908
|
-
const createVideoModel = (modelId) => {
|
|
909
|
-
var _a;
|
|
910
|
-
return new GoogleVertexVideoModel(modelId, {
|
|
911
|
-
...createConfig("video"),
|
|
912
|
-
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
913
|
-
});
|
|
914
|
-
};
|
|
915
|
-
const provider = function(modelId) {
|
|
916
|
-
if (new.target) {
|
|
917
|
-
throw new Error(
|
|
918
|
-
"The Google Vertex AI model function cannot be called with the new keyword."
|
|
919
|
-
);
|
|
920
|
-
}
|
|
921
|
-
return createChatModel(modelId);
|
|
922
|
-
};
|
|
923
|
-
provider.specificationVersion = "v3";
|
|
924
|
-
provider.languageModel = createChatModel;
|
|
925
|
-
provider.embeddingModel = createEmbeddingModel;
|
|
926
|
-
provider.textEmbeddingModel = createEmbeddingModel;
|
|
927
|
-
provider.image = createImageModel;
|
|
928
|
-
provider.imageModel = createImageModel;
|
|
929
|
-
provider.video = createVideoModel;
|
|
930
|
-
provider.videoModel = createVideoModel;
|
|
931
|
-
provider.tools = googleVertexTools;
|
|
932
|
-
return provider;
|
|
933
|
-
}
|
|
934
|
-
|
|
935
|
-
// src/google-vertex-provider-node.ts
|
|
936
|
-
function createVertex2(options = {}) {
|
|
937
|
-
const apiKey = loadOptionalSetting2({
|
|
938
|
-
settingValue: options.apiKey,
|
|
939
|
-
environmentVariableName: "GOOGLE_VERTEX_API_KEY"
|
|
940
|
-
});
|
|
941
|
-
if (apiKey) {
|
|
942
|
-
return createVertex(options);
|
|
943
|
-
}
|
|
944
|
-
return createVertex({
|
|
945
|
-
...options,
|
|
946
|
-
headers: async () => ({
|
|
947
|
-
Authorization: `Bearer ${await generateAuthToken(
|
|
948
|
-
options.googleAuthOptions
|
|
949
|
-
)}`,
|
|
950
|
-
...await resolve5(options.headers)
|
|
951
|
-
})
|
|
952
|
-
});
|
|
953
|
-
}
|
|
954
|
-
var vertex = createVertex2();
|
|
955
|
-
export {
|
|
956
|
-
VERSION,
|
|
957
|
-
createVertex2 as createVertex,
|
|
958
|
-
vertex
|
|
959
|
-
};
|
|
960
|
-
//# sourceMappingURL=index.mjs.map
|