@ai-sdk/google 2.0.0-beta.1 → 2.0.0-beta.11
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 +87 -0
- package/dist/index.d.mts +109 -294
- package/dist/index.d.ts +109 -294
- package/dist/index.js +411 -185
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +384 -153
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +22 -180
- package/dist/internal/index.d.ts +22 -180
- package/dist/internal/index.js +259 -172
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +232 -144
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
@@ -26,22 +26,21 @@ __export(src_exports, {
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
27
27
|
|
28
28
|
// src/google-provider.ts
|
29
|
-
var
|
30
|
-
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
29
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
31
30
|
|
32
31
|
// src/google-generative-ai-embedding-model.ts
|
33
32
|
var import_provider = require("@ai-sdk/provider");
|
34
33
|
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
35
|
-
var
|
34
|
+
var import_v43 = require("zod/v4");
|
36
35
|
|
37
36
|
// src/google-error.ts
|
38
37
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
39
|
-
var
|
40
|
-
var googleErrorDataSchema =
|
41
|
-
error:
|
42
|
-
code:
|
43
|
-
message:
|
44
|
-
status:
|
38
|
+
var import_v4 = require("zod/v4");
|
39
|
+
var googleErrorDataSchema = import_v4.z.object({
|
40
|
+
error: import_v4.z.object({
|
41
|
+
code: import_v4.z.number().nullable(),
|
42
|
+
message: import_v4.z.string(),
|
43
|
+
status: import_v4.z.string()
|
45
44
|
})
|
46
45
|
});
|
47
46
|
var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorResponseHandler)({
|
@@ -50,13 +49,13 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
50
49
|
});
|
51
50
|
|
52
51
|
// src/google-generative-ai-embedding-options.ts
|
53
|
-
var
|
54
|
-
var googleGenerativeAIEmbeddingProviderOptions =
|
52
|
+
var import_v42 = require("zod/v4");
|
53
|
+
var googleGenerativeAIEmbeddingProviderOptions = import_v42.z.object({
|
55
54
|
/**
|
56
55
|
* Optional. Optional reduced dimension for the output embedding.
|
57
56
|
* If set, excessive values in the output embedding are truncated from the end.
|
58
57
|
*/
|
59
|
-
outputDimensionality:
|
58
|
+
outputDimensionality: import_v42.z.number().optional(),
|
60
59
|
/**
|
61
60
|
* Optional. Specifies the task type for generating embeddings.
|
62
61
|
* Supported task types:
|
@@ -69,7 +68,7 @@ var googleGenerativeAIEmbeddingProviderOptions = import_zod2.z.object({
|
|
69
68
|
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
70
69
|
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
71
70
|
*/
|
72
|
-
taskType:
|
71
|
+
taskType: import_v42.z.enum([
|
73
72
|
"SEMANTIC_SIMILARITY",
|
74
73
|
"CLASSIFICATION",
|
75
74
|
"CLUSTERING",
|
@@ -116,6 +115,35 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
116
115
|
await (0, import_provider_utils2.resolve)(this.config.headers),
|
117
116
|
headers
|
118
117
|
);
|
118
|
+
if (values.length === 1) {
|
119
|
+
const {
|
120
|
+
responseHeaders: responseHeaders2,
|
121
|
+
value: response2,
|
122
|
+
rawValue: rawValue2
|
123
|
+
} = await (0, import_provider_utils2.postJsonToApi)({
|
124
|
+
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
125
|
+
headers: mergedHeaders,
|
126
|
+
body: {
|
127
|
+
model: `models/${this.modelId}`,
|
128
|
+
content: {
|
129
|
+
parts: [{ text: values[0] }]
|
130
|
+
},
|
131
|
+
outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
|
132
|
+
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
133
|
+
},
|
134
|
+
failedResponseHandler: googleFailedResponseHandler,
|
135
|
+
successfulResponseHandler: (0, import_provider_utils2.createJsonResponseHandler)(
|
136
|
+
googleGenerativeAISingleEmbeddingResponseSchema
|
137
|
+
),
|
138
|
+
abortSignal,
|
139
|
+
fetch: this.config.fetch
|
140
|
+
});
|
141
|
+
return {
|
142
|
+
embeddings: [response2.embedding.values],
|
143
|
+
usage: void 0,
|
144
|
+
response: { headers: responseHeaders2, body: rawValue2 }
|
145
|
+
};
|
146
|
+
}
|
119
147
|
const {
|
120
148
|
responseHeaders,
|
121
149
|
value: response,
|
@@ -145,13 +173,16 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
145
173
|
};
|
146
174
|
}
|
147
175
|
};
|
148
|
-
var googleGenerativeAITextEmbeddingResponseSchema =
|
149
|
-
embeddings:
|
176
|
+
var googleGenerativeAITextEmbeddingResponseSchema = import_v43.z.object({
|
177
|
+
embeddings: import_v43.z.array(import_v43.z.object({ values: import_v43.z.array(import_v43.z.number()) }))
|
178
|
+
});
|
179
|
+
var googleGenerativeAISingleEmbeddingResponseSchema = import_v43.z.object({
|
180
|
+
embedding: import_v43.z.object({ values: import_v43.z.array(import_v43.z.number()) })
|
150
181
|
});
|
151
182
|
|
152
183
|
// src/google-generative-ai-language-model.ts
|
153
|
-
var
|
154
|
-
var
|
184
|
+
var import_provider_utils6 = require("@ai-sdk/provider-utils");
|
185
|
+
var import_v47 = require("zod/v4");
|
155
186
|
|
156
187
|
// src/convert-json-schema-to-openapi-schema.ts
|
157
188
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
@@ -247,16 +278,18 @@ function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
|
247
278
|
return result;
|
248
279
|
}
|
249
280
|
function isEmptyObjectSchema(jsonSchema) {
|
250
|
-
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0);
|
281
|
+
return jsonSchema != null && typeof jsonSchema === "object" && jsonSchema.type === "object" && (jsonSchema.properties == null || Object.keys(jsonSchema.properties).length === 0) && !jsonSchema.additionalProperties;
|
251
282
|
}
|
252
283
|
|
253
284
|
// src/convert-to-google-generative-ai-messages.ts
|
254
285
|
var import_provider2 = require("@ai-sdk/provider");
|
255
286
|
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
256
|
-
function convertToGoogleGenerativeAIMessages(prompt) {
|
287
|
+
function convertToGoogleGenerativeAIMessages(prompt, options) {
|
288
|
+
var _a;
|
257
289
|
const systemInstructionParts = [];
|
258
290
|
const contents = [];
|
259
291
|
let systemMessagesAllowed = true;
|
292
|
+
const isGemmaModel = (_a = options == null ? void 0 : options.isGemmaModel) != null ? _a : false;
|
260
293
|
for (const { role, content } of prompt) {
|
261
294
|
switch (role) {
|
262
295
|
case "system": {
|
@@ -357,8 +390,12 @@ function convertToGoogleGenerativeAIMessages(prompt) {
|
|
357
390
|
}
|
358
391
|
}
|
359
392
|
}
|
393
|
+
if (isGemmaModel && systemInstructionParts.length > 0 && contents.length > 0 && contents[0].role === "user") {
|
394
|
+
const systemText = systemInstructionParts.map((part) => part.text).join("\n\n");
|
395
|
+
contents[0].parts.unshift({ text: systemText + "\n\n" });
|
396
|
+
}
|
360
397
|
return {
|
361
|
-
systemInstruction: systemInstructionParts.length > 0 ? { parts: systemInstructionParts } : void 0,
|
398
|
+
systemInstruction: systemInstructionParts.length > 0 && !isGemmaModel ? { parts: systemInstructionParts } : void 0,
|
362
399
|
contents
|
363
400
|
};
|
364
401
|
}
|
@@ -369,30 +406,19 @@ function getModelPath(modelId) {
|
|
369
406
|
}
|
370
407
|
|
371
408
|
// src/google-generative-ai-options.ts
|
372
|
-
var
|
373
|
-
var
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
/**
|
379
|
-
* The threshold to be used in dynamic retrieval. If not set, a system default
|
380
|
-
* value is used.
|
381
|
-
*/
|
382
|
-
dynamicThreshold: import_zod4.z.number().optional()
|
383
|
-
});
|
384
|
-
var googleGenerativeAIProviderOptions = import_zod4.z.object({
|
385
|
-
responseModalities: import_zod4.z.array(import_zod4.z.enum(["TEXT", "IMAGE"])).optional(),
|
386
|
-
thinkingConfig: import_zod4.z.object({
|
387
|
-
thinkingBudget: import_zod4.z.number().optional(),
|
388
|
-
includeThoughts: import_zod4.z.boolean().optional()
|
409
|
+
var import_v44 = require("zod/v4");
|
410
|
+
var googleGenerativeAIProviderOptions = import_v44.z.object({
|
411
|
+
responseModalities: import_v44.z.array(import_v44.z.enum(["TEXT", "IMAGE"])).optional(),
|
412
|
+
thinkingConfig: import_v44.z.object({
|
413
|
+
thinkingBudget: import_v44.z.number().optional(),
|
414
|
+
includeThoughts: import_v44.z.boolean().optional()
|
389
415
|
}).optional(),
|
390
416
|
/**
|
391
417
|
Optional.
|
392
418
|
The name of the cached content used as context to serve the prediction.
|
393
419
|
Format: cachedContents/{cachedContent}
|
394
420
|
*/
|
395
|
-
cachedContent:
|
421
|
+
cachedContent: import_v44.z.string().optional(),
|
396
422
|
/**
|
397
423
|
* Optional. Enable structured output. Default is true.
|
398
424
|
*
|
@@ -401,13 +427,13 @@ var googleGenerativeAIProviderOptions = import_zod4.z.object({
|
|
401
427
|
* Google Generative AI uses. You can use this to disable
|
402
428
|
* structured outputs if you need to.
|
403
429
|
*/
|
404
|
-
structuredOutputs:
|
430
|
+
structuredOutputs: import_v44.z.boolean().optional(),
|
405
431
|
/**
|
406
432
|
Optional. A list of unique safety settings for blocking unsafe content.
|
407
433
|
*/
|
408
|
-
safetySettings:
|
409
|
-
|
410
|
-
category:
|
434
|
+
safetySettings: import_v44.z.array(
|
435
|
+
import_v44.z.object({
|
436
|
+
category: import_v44.z.enum([
|
411
437
|
"HARM_CATEGORY_UNSPECIFIED",
|
412
438
|
"HARM_CATEGORY_HATE_SPEECH",
|
413
439
|
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
@@ -415,7 +441,7 @@ var googleGenerativeAIProviderOptions = import_zod4.z.object({
|
|
415
441
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
416
442
|
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
417
443
|
]),
|
418
|
-
threshold:
|
444
|
+
threshold: import_v44.z.enum([
|
419
445
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
420
446
|
"BLOCK_LOW_AND_ABOVE",
|
421
447
|
"BLOCK_MEDIUM_AND_ABOVE",
|
@@ -425,7 +451,7 @@ var googleGenerativeAIProviderOptions = import_zod4.z.object({
|
|
425
451
|
])
|
426
452
|
})
|
427
453
|
).optional(),
|
428
|
-
threshold:
|
454
|
+
threshold: import_v44.z.enum([
|
429
455
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
430
456
|
"BLOCK_LOW_AND_ABOVE",
|
431
457
|
"BLOCK_MEDIUM_AND_ABOVE",
|
@@ -438,21 +464,7 @@ var googleGenerativeAIProviderOptions = import_zod4.z.object({
|
|
438
464
|
*
|
439
465
|
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
440
466
|
*/
|
441
|
-
audioTimestamp:
|
442
|
-
/**
|
443
|
-
Optional. When enabled, the model will use Google search to ground the response.
|
444
|
-
|
445
|
-
@see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
|
446
|
-
*/
|
447
|
-
useSearchGrounding: import_zod4.z.boolean().optional(),
|
448
|
-
/**
|
449
|
-
Optional. Specifies the dynamic retrieval configuration.
|
450
|
-
|
451
|
-
@note Dynamic retrieval is only compatible with Gemini 1.5 Flash.
|
452
|
-
|
453
|
-
@see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-with-google-search#dynamic-retrieval
|
454
|
-
*/
|
455
|
-
dynamicRetrievalConfig: dynamicRetrievalConfig.optional()
|
467
|
+
audioTimestamp: import_v44.z.boolean().optional()
|
456
468
|
});
|
457
469
|
|
458
470
|
// src/google-prepare-tools.ts
|
@@ -460,8 +472,6 @@ var import_provider3 = require("@ai-sdk/provider");
|
|
460
472
|
function prepareTools({
|
461
473
|
tools,
|
462
474
|
toolChoice,
|
463
|
-
useSearchGrounding,
|
464
|
-
dynamicRetrievalConfig: dynamicRetrievalConfig2,
|
465
475
|
modelId
|
466
476
|
}) {
|
467
477
|
var _a;
|
@@ -469,28 +479,76 @@ function prepareTools({
|
|
469
479
|
const toolWarnings = [];
|
470
480
|
const isGemini2 = modelId.includes("gemini-2");
|
471
481
|
const supportsDynamicRetrieval = modelId.includes("gemini-1.5-flash") && !modelId.includes("-8b");
|
472
|
-
if (
|
482
|
+
if (tools == null) {
|
483
|
+
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
484
|
+
}
|
485
|
+
const hasFunctionTools = tools.some((tool) => tool.type === "function");
|
486
|
+
const hasProviderDefinedTools = tools.some(
|
487
|
+
(tool) => tool.type === "provider-defined"
|
488
|
+
);
|
489
|
+
if (hasFunctionTools && hasProviderDefinedTools) {
|
490
|
+
toolWarnings.push({
|
491
|
+
type: "unsupported-tool",
|
492
|
+
tool: tools.find((tool) => tool.type === "function"),
|
493
|
+
details: "Cannot mix function tools with provider-defined tools in the same request. Please use either function tools or provider-defined tools, but not both."
|
494
|
+
});
|
495
|
+
}
|
496
|
+
if (hasProviderDefinedTools) {
|
497
|
+
const googleTools2 = {};
|
498
|
+
const providerDefinedTools = tools.filter(
|
499
|
+
(tool) => tool.type === "provider-defined"
|
500
|
+
);
|
501
|
+
providerDefinedTools.forEach((tool) => {
|
502
|
+
switch (tool.id) {
|
503
|
+
case "google.google_search":
|
504
|
+
if (isGemini2) {
|
505
|
+
googleTools2.googleSearch = {};
|
506
|
+
} else if (supportsDynamicRetrieval) {
|
507
|
+
googleTools2.googleSearchRetrieval = {
|
508
|
+
dynamicRetrievalConfig: {
|
509
|
+
mode: tool.args.mode,
|
510
|
+
dynamicThreshold: tool.args.dynamicThreshold
|
511
|
+
}
|
512
|
+
};
|
513
|
+
} else {
|
514
|
+
googleTools2.googleSearchRetrieval = {};
|
515
|
+
}
|
516
|
+
break;
|
517
|
+
case "google.url_context":
|
518
|
+
if (isGemini2) {
|
519
|
+
googleTools2.urlContext = {};
|
520
|
+
} else {
|
521
|
+
toolWarnings.push({
|
522
|
+
type: "unsupported-tool",
|
523
|
+
tool,
|
524
|
+
details: "The URL context tool is not supported with other Gemini models than Gemini 2."
|
525
|
+
});
|
526
|
+
}
|
527
|
+
break;
|
528
|
+
default:
|
529
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
530
|
+
break;
|
531
|
+
}
|
532
|
+
});
|
473
533
|
return {
|
474
|
-
tools:
|
475
|
-
googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig2 ? {} : { dynamicRetrievalConfig: dynamicRetrievalConfig2 }
|
476
|
-
},
|
534
|
+
tools: Object.keys(googleTools2).length > 0 ? googleTools2 : void 0,
|
477
535
|
toolConfig: void 0,
|
478
536
|
toolWarnings
|
479
537
|
};
|
480
538
|
}
|
481
|
-
if (tools == null) {
|
482
|
-
return { tools: void 0, toolConfig: void 0, toolWarnings };
|
483
|
-
}
|
484
539
|
const functionDeclarations = [];
|
485
540
|
for (const tool of tools) {
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
541
|
+
switch (tool.type) {
|
542
|
+
case "function":
|
543
|
+
functionDeclarations.push({
|
544
|
+
name: tool.name,
|
545
|
+
description: (_a = tool.description) != null ? _a : "",
|
546
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema)
|
547
|
+
});
|
548
|
+
break;
|
549
|
+
default:
|
550
|
+
toolWarnings.push({ type: "unsupported-tool", tool });
|
551
|
+
break;
|
494
552
|
}
|
495
553
|
}
|
496
554
|
if (toolChoice == null) {
|
@@ -567,12 +625,72 @@ function mapGoogleGenerativeAIFinishReason({
|
|
567
625
|
}
|
568
626
|
}
|
569
627
|
|
628
|
+
// src/tool/google-search.ts
|
629
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
630
|
+
var import_v45 = require("zod/v4");
|
631
|
+
var groundingChunkSchema = import_v45.z.object({
|
632
|
+
web: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish(),
|
633
|
+
retrievedContext: import_v45.z.object({ uri: import_v45.z.string(), title: import_v45.z.string() }).nullish()
|
634
|
+
});
|
635
|
+
var groundingMetadataSchema = import_v45.z.object({
|
636
|
+
webSearchQueries: import_v45.z.array(import_v45.z.string()).nullish(),
|
637
|
+
retrievalQueries: import_v45.z.array(import_v45.z.string()).nullish(),
|
638
|
+
searchEntryPoint: import_v45.z.object({ renderedContent: import_v45.z.string() }).nullish(),
|
639
|
+
groundingChunks: import_v45.z.array(groundingChunkSchema).nullish(),
|
640
|
+
groundingSupports: import_v45.z.array(
|
641
|
+
import_v45.z.object({
|
642
|
+
segment: import_v45.z.object({
|
643
|
+
startIndex: import_v45.z.number().nullish(),
|
644
|
+
endIndex: import_v45.z.number().nullish(),
|
645
|
+
text: import_v45.z.string().nullish()
|
646
|
+
}),
|
647
|
+
segment_text: import_v45.z.string().nullish(),
|
648
|
+
groundingChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
|
649
|
+
supportChunkIndices: import_v45.z.array(import_v45.z.number()).nullish(),
|
650
|
+
confidenceScores: import_v45.z.array(import_v45.z.number()).nullish(),
|
651
|
+
confidenceScore: import_v45.z.array(import_v45.z.number()).nullish()
|
652
|
+
})
|
653
|
+
).nullish(),
|
654
|
+
retrievalMetadata: import_v45.z.union([
|
655
|
+
import_v45.z.object({
|
656
|
+
webDynamicRetrievalScore: import_v45.z.number()
|
657
|
+
}),
|
658
|
+
import_v45.z.object({})
|
659
|
+
]).nullish()
|
660
|
+
});
|
661
|
+
var googleSearch = (0, import_provider_utils4.createProviderDefinedToolFactory)({
|
662
|
+
id: "google.google_search",
|
663
|
+
name: "google_search",
|
664
|
+
inputSchema: import_v45.z.object({
|
665
|
+
mode: import_v45.z.enum(["MODE_DYNAMIC", "MODE_UNSPECIFIED"]).default("MODE_UNSPECIFIED"),
|
666
|
+
dynamicThreshold: import_v45.z.number().default(1)
|
667
|
+
})
|
668
|
+
});
|
669
|
+
|
670
|
+
// src/tool/url-context.ts
|
671
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
672
|
+
var import_v46 = require("zod/v4");
|
673
|
+
var urlMetadataSchema = import_v46.z.object({
|
674
|
+
retrievedUrl: import_v46.z.string(),
|
675
|
+
urlRetrievalStatus: import_v46.z.string()
|
676
|
+
});
|
677
|
+
var urlContextMetadataSchema = import_v46.z.object({
|
678
|
+
urlMetadata: import_v46.z.array(urlMetadataSchema)
|
679
|
+
});
|
680
|
+
var urlContext = (0, import_provider_utils5.createProviderDefinedToolFactory)({
|
681
|
+
id: "google.url_context",
|
682
|
+
name: "url_context",
|
683
|
+
inputSchema: import_v46.z.object({})
|
684
|
+
});
|
685
|
+
|
570
686
|
// src/google-generative-ai-language-model.ts
|
571
687
|
var GoogleGenerativeAILanguageModel = class {
|
572
688
|
constructor(modelId, config) {
|
573
689
|
this.specificationVersion = "v2";
|
690
|
+
var _a;
|
574
691
|
this.modelId = modelId;
|
575
692
|
this.config = config;
|
693
|
+
this.generateId = (_a = config.generateId) != null ? _a : import_provider_utils6.generateId;
|
576
694
|
}
|
577
695
|
get provider() {
|
578
696
|
return this.config.provider;
|
@@ -596,9 +714,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
596
714
|
toolChoice,
|
597
715
|
providerOptions
|
598
716
|
}) {
|
599
|
-
var _a, _b
|
717
|
+
var _a, _b;
|
600
718
|
const warnings = [];
|
601
|
-
const googleOptions = await (0,
|
719
|
+
const googleOptions = await (0, import_provider_utils6.parseProviderOptions)({
|
602
720
|
provider: "google",
|
603
721
|
providerOptions,
|
604
722
|
schema: googleGenerativeAIProviderOptions
|
@@ -609,16 +727,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
609
727
|
message: `The 'includeThoughts' option is only supported with the Google Vertex provider and might not be supported or could behave unexpectedly with the current Google provider (${this.config.provider}).`
|
610
728
|
});
|
611
729
|
}
|
612
|
-
const
|
730
|
+
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
731
|
+
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(
|
732
|
+
prompt,
|
733
|
+
{ isGemmaModel }
|
734
|
+
);
|
613
735
|
const {
|
614
|
-
tools:
|
736
|
+
tools: googleTools2,
|
615
737
|
toolConfig: googleToolConfig,
|
616
738
|
toolWarnings
|
617
739
|
} = prepareTools({
|
618
740
|
tools,
|
619
741
|
toolChoice,
|
620
|
-
useSearchGrounding: (_b = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _b : false,
|
621
|
-
dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
|
622
742
|
modelId: this.modelId
|
623
743
|
});
|
624
744
|
return {
|
@@ -638,7 +758,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
638
758
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
639
759
|
// so this is needed as an escape hatch:
|
640
760
|
// TODO convert into provider option
|
641
|
-
((
|
761
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
642
762
|
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
643
763
|
audioTimestamp: googleOptions.audioTimestamp
|
644
764
|
},
|
@@ -647,9 +767,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
647
767
|
thinkingConfig: googleOptions == null ? void 0 : googleOptions.thinkingConfig
|
648
768
|
},
|
649
769
|
contents,
|
650
|
-
systemInstruction,
|
770
|
+
systemInstruction: isGemmaModel ? void 0 : systemInstruction,
|
651
771
|
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
652
|
-
tools:
|
772
|
+
tools: googleTools2,
|
653
773
|
toolConfig: googleToolConfig,
|
654
774
|
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
|
655
775
|
},
|
@@ -657,25 +777,25 @@ var GoogleGenerativeAILanguageModel = class {
|
|
657
777
|
};
|
658
778
|
}
|
659
779
|
async doGenerate(options) {
|
660
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
780
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
661
781
|
const { args, warnings } = await this.getArgs(options);
|
662
782
|
const body = JSON.stringify(args);
|
663
|
-
const mergedHeaders = (0,
|
664
|
-
await (0,
|
783
|
+
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
784
|
+
await (0, import_provider_utils6.resolve)(this.config.headers),
|
665
785
|
options.headers
|
666
786
|
);
|
667
787
|
const {
|
668
788
|
responseHeaders,
|
669
789
|
value: response,
|
670
790
|
rawValue: rawResponse
|
671
|
-
} = await (0,
|
791
|
+
} = await (0, import_provider_utils6.postJsonToApi)({
|
672
792
|
url: `${this.config.baseURL}/${getModelPath(
|
673
793
|
this.modelId
|
674
794
|
)}:generateContent`,
|
675
795
|
headers: mergedHeaders,
|
676
796
|
body: args,
|
677
797
|
failedResponseHandler: googleFailedResponseHandler,
|
678
|
-
successfulResponseHandler: (0,
|
798
|
+
successfulResponseHandler: (0, import_provider_utils6.createJsonResponseHandler)(responseSchema),
|
679
799
|
abortSignal: options.abortSignal,
|
680
800
|
fetch: this.config.fetch
|
681
801
|
});
|
@@ -729,7 +849,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
729
849
|
providerMetadata: {
|
730
850
|
google: {
|
731
851
|
groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
|
732
|
-
|
852
|
+
urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
|
853
|
+
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null,
|
854
|
+
usageMetadata: usageMetadata != null ? usageMetadata : null
|
733
855
|
}
|
734
856
|
},
|
735
857
|
request: { body },
|
@@ -743,18 +865,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
743
865
|
async doStream(options) {
|
744
866
|
const { args, warnings } = await this.getArgs(options);
|
745
867
|
const body = JSON.stringify(args);
|
746
|
-
const headers = (0,
|
747
|
-
await (0,
|
868
|
+
const headers = (0, import_provider_utils6.combineHeaders)(
|
869
|
+
await (0, import_provider_utils6.resolve)(this.config.headers),
|
748
870
|
options.headers
|
749
871
|
);
|
750
|
-
const { responseHeaders, value: response } = await (0,
|
872
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils6.postJsonToApi)({
|
751
873
|
url: `${this.config.baseURL}/${getModelPath(
|
752
874
|
this.modelId
|
753
875
|
)}:streamGenerateContent?alt=sse`,
|
754
876
|
headers,
|
755
877
|
body: args,
|
756
878
|
failedResponseHandler: googleFailedResponseHandler,
|
757
|
-
successfulResponseHandler: (0,
|
879
|
+
successfulResponseHandler: (0, import_provider_utils6.createEventSourceResponseHandler)(chunkSchema),
|
758
880
|
abortSignal: options.abortSignal,
|
759
881
|
fetch: this.config.fetch
|
760
882
|
});
|
@@ -765,11 +887,12 @@ var GoogleGenerativeAILanguageModel = class {
|
|
765
887
|
totalTokens: void 0
|
766
888
|
};
|
767
889
|
let providerMetadata = void 0;
|
768
|
-
const
|
890
|
+
const generateId3 = this.config.generateId;
|
769
891
|
let hasToolCalls = false;
|
770
892
|
let currentTextBlockId = null;
|
771
893
|
let currentReasoningBlockId = null;
|
772
894
|
let blockCounter = 0;
|
895
|
+
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
773
896
|
return {
|
774
897
|
stream: response.pipeThrough(
|
775
898
|
new TransformStream({
|
@@ -799,6 +922,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
799
922
|
return;
|
800
923
|
}
|
801
924
|
const content = candidate.content;
|
925
|
+
const sources = extractSources({
|
926
|
+
groundingMetadata: candidate.groundingMetadata,
|
927
|
+
generateId: generateId3
|
928
|
+
});
|
929
|
+
if (sources != null) {
|
930
|
+
for (const source of sources) {
|
931
|
+
if (source.sourceType === "url" && !emittedSourceUrls.has(source.url)) {
|
932
|
+
emittedSourceUrls.add(source.url);
|
933
|
+
controller.enqueue(source);
|
934
|
+
}
|
935
|
+
}
|
936
|
+
}
|
802
937
|
if (content != null) {
|
803
938
|
const parts = (_g = content.parts) != null ? _g : [];
|
804
939
|
for (const part of parts) {
|
@@ -858,7 +993,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
858
993
|
}
|
859
994
|
const toolCallDeltas = getToolCallsFromParts({
|
860
995
|
parts: content.parts,
|
861
|
-
generateId:
|
996
|
+
generateId: generateId3
|
862
997
|
});
|
863
998
|
if (toolCallDeltas != null) {
|
864
999
|
for (const toolCall of toolCallDeltas) {
|
@@ -891,19 +1026,16 @@ var GoogleGenerativeAILanguageModel = class {
|
|
891
1026
|
finishReason: candidate.finishReason,
|
892
1027
|
hasToolCalls
|
893
1028
|
});
|
894
|
-
const sources = (_h = extractSources({
|
895
|
-
groundingMetadata: candidate.groundingMetadata,
|
896
|
-
generateId: generateId2
|
897
|
-
})) != null ? _h : [];
|
898
|
-
for (const source of sources) {
|
899
|
-
controller.enqueue(source);
|
900
|
-
}
|
901
1029
|
providerMetadata = {
|
902
1030
|
google: {
|
903
|
-
groundingMetadata: (
|
1031
|
+
groundingMetadata: (_h = candidate.groundingMetadata) != null ? _h : null,
|
1032
|
+
urlContextMetadata: (_i = candidate.urlContextMetadata) != null ? _i : null,
|
904
1033
|
safetyRatings: (_j = candidate.safetyRatings) != null ? _j : null
|
905
1034
|
}
|
906
1035
|
};
|
1036
|
+
if (usageMetadata != null) {
|
1037
|
+
providerMetadata.google.usageMetadata = usageMetadata;
|
1038
|
+
}
|
907
1039
|
}
|
908
1040
|
},
|
909
1041
|
flush(controller) {
|
@@ -935,14 +1067,14 @@ var GoogleGenerativeAILanguageModel = class {
|
|
935
1067
|
};
|
936
1068
|
function getToolCallsFromParts({
|
937
1069
|
parts,
|
938
|
-
generateId:
|
1070
|
+
generateId: generateId3
|
939
1071
|
}) {
|
940
1072
|
const functionCallParts = parts == null ? void 0 : parts.filter(
|
941
1073
|
(part) => "functionCall" in part
|
942
1074
|
);
|
943
1075
|
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
944
1076
|
type: "tool-call",
|
945
|
-
toolCallId:
|
1077
|
+
toolCallId: generateId3(),
|
946
1078
|
toolName: part.functionCall.name,
|
947
1079
|
args: JSON.stringify(part.functionCall.args)
|
948
1080
|
}));
|
@@ -954,7 +1086,7 @@ function getInlineDataParts(parts) {
|
|
954
1086
|
}
|
955
1087
|
function extractSources({
|
956
1088
|
groundingMetadata,
|
957
|
-
generateId:
|
1089
|
+
generateId: generateId3
|
958
1090
|
}) {
|
959
1091
|
var _a;
|
960
1092
|
return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
|
@@ -962,108 +1094,196 @@ function extractSources({
|
|
962
1094
|
).map((chunk) => ({
|
963
1095
|
type: "source",
|
964
1096
|
sourceType: "url",
|
965
|
-
id:
|
1097
|
+
id: generateId3(),
|
966
1098
|
url: chunk.web.uri,
|
967
1099
|
title: chunk.web.title
|
968
1100
|
}));
|
969
1101
|
}
|
970
|
-
var contentSchema =
|
971
|
-
parts:
|
972
|
-
|
1102
|
+
var contentSchema = import_v47.z.object({
|
1103
|
+
parts: import_v47.z.array(
|
1104
|
+
import_v47.z.union([
|
973
1105
|
// note: order matters since text can be fully empty
|
974
|
-
|
975
|
-
functionCall:
|
976
|
-
name:
|
977
|
-
args:
|
1106
|
+
import_v47.z.object({
|
1107
|
+
functionCall: import_v47.z.object({
|
1108
|
+
name: import_v47.z.string(),
|
1109
|
+
args: import_v47.z.unknown()
|
978
1110
|
})
|
979
1111
|
}),
|
980
|
-
|
981
|
-
inlineData:
|
982
|
-
mimeType:
|
983
|
-
data:
|
1112
|
+
import_v47.z.object({
|
1113
|
+
inlineData: import_v47.z.object({
|
1114
|
+
mimeType: import_v47.z.string(),
|
1115
|
+
data: import_v47.z.string()
|
984
1116
|
})
|
985
1117
|
}),
|
986
|
-
|
987
|
-
text:
|
988
|
-
thought:
|
1118
|
+
import_v47.z.object({
|
1119
|
+
text: import_v47.z.string().nullish(),
|
1120
|
+
thought: import_v47.z.boolean().nullish()
|
989
1121
|
})
|
990
1122
|
])
|
991
1123
|
).nullish()
|
992
1124
|
});
|
993
|
-
var
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
searchEntryPoint: import_zod5.z.object({ renderedContent: import_zod5.z.string() }).nullish(),
|
1001
|
-
groundingChunks: import_zod5.z.array(groundingChunkSchema).nullish(),
|
1002
|
-
groundingSupports: import_zod5.z.array(
|
1003
|
-
import_zod5.z.object({
|
1004
|
-
segment: import_zod5.z.object({
|
1005
|
-
startIndex: import_zod5.z.number().nullish(),
|
1006
|
-
endIndex: import_zod5.z.number().nullish(),
|
1007
|
-
text: import_zod5.z.string().nullish()
|
1008
|
-
}),
|
1009
|
-
segment_text: import_zod5.z.string().nullish(),
|
1010
|
-
groundingChunkIndices: import_zod5.z.array(import_zod5.z.number()).nullish(),
|
1011
|
-
supportChunkIndices: import_zod5.z.array(import_zod5.z.number()).nullish(),
|
1012
|
-
confidenceScores: import_zod5.z.array(import_zod5.z.number()).nullish(),
|
1013
|
-
confidenceScore: import_zod5.z.array(import_zod5.z.number()).nullish()
|
1014
|
-
})
|
1015
|
-
).nullish(),
|
1016
|
-
retrievalMetadata: import_zod5.z.union([
|
1017
|
-
import_zod5.z.object({
|
1018
|
-
webDynamicRetrievalScore: import_zod5.z.number()
|
1019
|
-
}),
|
1020
|
-
import_zod5.z.object({})
|
1021
|
-
]).nullish()
|
1022
|
-
});
|
1023
|
-
var safetyRatingSchema = import_zod5.z.object({
|
1024
|
-
category: import_zod5.z.string().nullish(),
|
1025
|
-
probability: import_zod5.z.string().nullish(),
|
1026
|
-
probabilityScore: import_zod5.z.number().nullish(),
|
1027
|
-
severity: import_zod5.z.string().nullish(),
|
1028
|
-
severityScore: import_zod5.z.number().nullish(),
|
1029
|
-
blocked: import_zod5.z.boolean().nullish()
|
1125
|
+
var safetyRatingSchema = import_v47.z.object({
|
1126
|
+
category: import_v47.z.string().nullish(),
|
1127
|
+
probability: import_v47.z.string().nullish(),
|
1128
|
+
probabilityScore: import_v47.z.number().nullish(),
|
1129
|
+
severity: import_v47.z.string().nullish(),
|
1130
|
+
severityScore: import_v47.z.number().nullish(),
|
1131
|
+
blocked: import_v47.z.boolean().nullish()
|
1030
1132
|
});
|
1031
|
-
var usageSchema =
|
1032
|
-
cachedContentTokenCount:
|
1033
|
-
thoughtsTokenCount:
|
1034
|
-
promptTokenCount:
|
1035
|
-
candidatesTokenCount:
|
1036
|
-
totalTokenCount:
|
1133
|
+
var usageSchema = import_v47.z.object({
|
1134
|
+
cachedContentTokenCount: import_v47.z.number().nullish(),
|
1135
|
+
thoughtsTokenCount: import_v47.z.number().nullish(),
|
1136
|
+
promptTokenCount: import_v47.z.number().nullish(),
|
1137
|
+
candidatesTokenCount: import_v47.z.number().nullish(),
|
1138
|
+
totalTokenCount: import_v47.z.number().nullish()
|
1037
1139
|
});
|
1038
|
-
var responseSchema =
|
1039
|
-
candidates:
|
1040
|
-
|
1041
|
-
content: contentSchema.nullish().or(
|
1042
|
-
finishReason:
|
1043
|
-
safetyRatings:
|
1044
|
-
groundingMetadata: groundingMetadataSchema.nullish()
|
1140
|
+
var responseSchema = import_v47.z.object({
|
1141
|
+
candidates: import_v47.z.array(
|
1142
|
+
import_v47.z.object({
|
1143
|
+
content: contentSchema.nullish().or(import_v47.z.object({}).strict()),
|
1144
|
+
finishReason: import_v47.z.string().nullish(),
|
1145
|
+
safetyRatings: import_v47.z.array(safetyRatingSchema).nullish(),
|
1146
|
+
groundingMetadata: groundingMetadataSchema.nullish(),
|
1147
|
+
urlContextMetadata: urlContextMetadataSchema.nullish()
|
1045
1148
|
})
|
1046
1149
|
),
|
1047
1150
|
usageMetadata: usageSchema.nullish()
|
1048
1151
|
});
|
1049
|
-
var chunkSchema =
|
1050
|
-
candidates:
|
1051
|
-
|
1152
|
+
var chunkSchema = import_v47.z.object({
|
1153
|
+
candidates: import_v47.z.array(
|
1154
|
+
import_v47.z.object({
|
1052
1155
|
content: contentSchema.nullish(),
|
1053
|
-
finishReason:
|
1054
|
-
safetyRatings:
|
1055
|
-
groundingMetadata: groundingMetadataSchema.nullish()
|
1156
|
+
finishReason: import_v47.z.string().nullish(),
|
1157
|
+
safetyRatings: import_v47.z.array(safetyRatingSchema).nullish(),
|
1158
|
+
groundingMetadata: groundingMetadataSchema.nullish(),
|
1159
|
+
urlContextMetadata: urlContextMetadataSchema.nullish()
|
1056
1160
|
})
|
1057
1161
|
).nullish(),
|
1058
1162
|
usageMetadata: usageSchema.nullish()
|
1059
1163
|
});
|
1060
1164
|
|
1165
|
+
// src/google-tools.ts
|
1166
|
+
var googleTools = {
|
1167
|
+
/**
|
1168
|
+
* Creates a Google search tool that gives Google direct access to real-time web content.
|
1169
|
+
* Must have name "google_search".
|
1170
|
+
*/
|
1171
|
+
googleSearch,
|
1172
|
+
/**
|
1173
|
+
* Creates a URL context tool that gives Google direct access to real-time web content.
|
1174
|
+
* Must have name "url_context".
|
1175
|
+
*/
|
1176
|
+
urlContext
|
1177
|
+
};
|
1178
|
+
|
1179
|
+
// src/google-generative-ai-image-model.ts
|
1180
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
1181
|
+
var import_v48 = require("zod/v4");
|
1182
|
+
var GoogleGenerativeAIImageModel = class {
|
1183
|
+
constructor(modelId, settings, config) {
|
1184
|
+
this.modelId = modelId;
|
1185
|
+
this.settings = settings;
|
1186
|
+
this.config = config;
|
1187
|
+
this.specificationVersion = "v2";
|
1188
|
+
}
|
1189
|
+
get maxImagesPerCall() {
|
1190
|
+
var _a;
|
1191
|
+
return (_a = this.settings.maxImagesPerCall) != null ? _a : 4;
|
1192
|
+
}
|
1193
|
+
get provider() {
|
1194
|
+
return this.config.provider;
|
1195
|
+
}
|
1196
|
+
async doGenerate(options) {
|
1197
|
+
var _a, _b, _c;
|
1198
|
+
const {
|
1199
|
+
prompt,
|
1200
|
+
n = 1,
|
1201
|
+
size = "1024x1024",
|
1202
|
+
aspectRatio = "1:1",
|
1203
|
+
seed,
|
1204
|
+
providerOptions,
|
1205
|
+
headers,
|
1206
|
+
abortSignal
|
1207
|
+
} = options;
|
1208
|
+
const warnings = [];
|
1209
|
+
if (size != null) {
|
1210
|
+
warnings.push({
|
1211
|
+
type: "unsupported-setting",
|
1212
|
+
setting: "size",
|
1213
|
+
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
1214
|
+
});
|
1215
|
+
}
|
1216
|
+
if (seed != null) {
|
1217
|
+
warnings.push({
|
1218
|
+
type: "unsupported-setting",
|
1219
|
+
setting: "seed",
|
1220
|
+
details: "This model does not support the `seed` option through this provider."
|
1221
|
+
});
|
1222
|
+
}
|
1223
|
+
const googleOptions = await (0, import_provider_utils7.parseProviderOptions)({
|
1224
|
+
provider: "google",
|
1225
|
+
providerOptions,
|
1226
|
+
schema: googleImageProviderOptionsSchema
|
1227
|
+
});
|
1228
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
1229
|
+
const parameters = {
|
1230
|
+
sampleCount: n
|
1231
|
+
};
|
1232
|
+
if (aspectRatio != null) {
|
1233
|
+
parameters.aspectRatio = aspectRatio;
|
1234
|
+
}
|
1235
|
+
if (googleOptions) {
|
1236
|
+
Object.assign(parameters, googleOptions);
|
1237
|
+
}
|
1238
|
+
const body = {
|
1239
|
+
instances: [{ prompt }],
|
1240
|
+
parameters
|
1241
|
+
};
|
1242
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils7.postJsonToApi)({
|
1243
|
+
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
1244
|
+
headers: (0, import_provider_utils7.combineHeaders)(await (0, import_provider_utils7.resolve)(this.config.headers), headers),
|
1245
|
+
body,
|
1246
|
+
failedResponseHandler: googleFailedResponseHandler,
|
1247
|
+
successfulResponseHandler: (0, import_provider_utils7.createJsonResponseHandler)(
|
1248
|
+
googleImageResponseSchema
|
1249
|
+
),
|
1250
|
+
abortSignal,
|
1251
|
+
fetch: this.config.fetch
|
1252
|
+
});
|
1253
|
+
return {
|
1254
|
+
images: response.predictions.map(
|
1255
|
+
(p) => p.bytesBase64Encoded
|
1256
|
+
),
|
1257
|
+
warnings: warnings != null ? warnings : [],
|
1258
|
+
providerMetadata: {
|
1259
|
+
google: {
|
1260
|
+
images: response.predictions.map((prediction) => ({
|
1261
|
+
// Add any prediction-specific metadata here
|
1262
|
+
}))
|
1263
|
+
}
|
1264
|
+
},
|
1265
|
+
response: {
|
1266
|
+
timestamp: currentDate,
|
1267
|
+
modelId: this.modelId,
|
1268
|
+
headers: responseHeaders
|
1269
|
+
}
|
1270
|
+
};
|
1271
|
+
}
|
1272
|
+
};
|
1273
|
+
var googleImageResponseSchema = import_v48.z.object({
|
1274
|
+
predictions: import_v48.z.array(import_v48.z.object({ bytesBase64Encoded: import_v48.z.string() })).default([])
|
1275
|
+
});
|
1276
|
+
var googleImageProviderOptionsSchema = import_v48.z.object({
|
1277
|
+
personGeneration: import_v48.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
1278
|
+
aspectRatio: import_v48.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
1279
|
+
});
|
1280
|
+
|
1061
1281
|
// src/google-provider.ts
|
1062
1282
|
function createGoogleGenerativeAI(options = {}) {
|
1063
1283
|
var _a;
|
1064
|
-
const baseURL = (_a = (0,
|
1284
|
+
const baseURL = (_a = (0, import_provider_utils8.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
1065
1285
|
const getHeaders = () => ({
|
1066
|
-
"x-goog-api-key": (0,
|
1286
|
+
"x-goog-api-key": (0, import_provider_utils8.loadApiKey)({
|
1067
1287
|
apiKey: options.apiKey,
|
1068
1288
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
1069
1289
|
description: "Google Generative AI"
|
@@ -1076,7 +1296,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
1076
1296
|
provider: "google.generative-ai",
|
1077
1297
|
baseURL,
|
1078
1298
|
headers: getHeaders,
|
1079
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
1299
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils8.generateId,
|
1080
1300
|
supportedUrls: () => ({
|
1081
1301
|
"*": [
|
1082
1302
|
// Only allow requests to the Google Generative Language "files" endpoint
|
@@ -1093,6 +1313,12 @@ function createGoogleGenerativeAI(options = {}) {
|
|
1093
1313
|
headers: getHeaders,
|
1094
1314
|
fetch: options.fetch
|
1095
1315
|
});
|
1316
|
+
const createImageModel = (modelId, settings = {}) => new GoogleGenerativeAIImageModel(modelId, settings, {
|
1317
|
+
provider: "google.generative-ai",
|
1318
|
+
baseURL,
|
1319
|
+
headers: getHeaders,
|
1320
|
+
fetch: options.fetch
|
1321
|
+
});
|
1096
1322
|
const provider = function(modelId) {
|
1097
1323
|
if (new.target) {
|
1098
1324
|
throw new Error(
|
@@ -1107,9 +1333,9 @@ function createGoogleGenerativeAI(options = {}) {
|
|
1107
1333
|
provider.embedding = createEmbeddingModel;
|
1108
1334
|
provider.textEmbedding = createEmbeddingModel;
|
1109
1335
|
provider.textEmbeddingModel = createEmbeddingModel;
|
1110
|
-
provider.
|
1111
|
-
|
1112
|
-
|
1336
|
+
provider.image = createImageModel;
|
1337
|
+
provider.imageModel = createImageModel;
|
1338
|
+
provider.tools = googleTools;
|
1113
1339
|
return provider;
|
1114
1340
|
}
|
1115
1341
|
var google = createGoogleGenerativeAI();
|