@ai-sdk/google 2.0.0-canary.11 → 2.0.0-canary.13
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 +23 -0
- package/dist/index.d.mts +92 -56
- package/dist/index.d.ts +92 -56
- package/dist/index.js +195 -98
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +195 -98
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +2 -81
- package/dist/internal/index.d.ts +2 -81
- package/dist/internal/index.js +162 -83
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +162 -83
- package/dist/internal/index.mjs.map +1 -1
- package/internal.d.ts +1 -0
- package/package.json +5 -4
package/dist/index.mjs
CHANGED
@@ -43,37 +43,54 @@ var googleGenerativeAIEmbeddingProviderOptions = z2.object({
|
|
43
43
|
* Optional. Optional reduced dimension for the output embedding.
|
44
44
|
* If set, excessive values in the output embedding are truncated from the end.
|
45
45
|
*/
|
46
|
-
outputDimensionality: z2.number().optional()
|
46
|
+
outputDimensionality: z2.number().optional(),
|
47
|
+
/**
|
48
|
+
* Optional. Specifies the task type for generating embeddings.
|
49
|
+
* Supported task types:
|
50
|
+
* - SEMANTIC_SIMILARITY: Optimized for text similarity.
|
51
|
+
* - CLASSIFICATION: Optimized for text classification.
|
52
|
+
* - CLUSTERING: Optimized for clustering texts based on similarity.
|
53
|
+
* - RETRIEVAL_DOCUMENT: Optimized for document retrieval.
|
54
|
+
* - RETRIEVAL_QUERY: Optimized for query-based retrieval.
|
55
|
+
* - QUESTION_ANSWERING: Optimized for answering questions.
|
56
|
+
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
57
|
+
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
58
|
+
*/
|
59
|
+
taskType: z2.enum([
|
60
|
+
"SEMANTIC_SIMILARITY",
|
61
|
+
"CLASSIFICATION",
|
62
|
+
"CLUSTERING",
|
63
|
+
"RETRIEVAL_DOCUMENT",
|
64
|
+
"RETRIEVAL_QUERY",
|
65
|
+
"QUESTION_ANSWERING",
|
66
|
+
"FACT_VERIFICATION",
|
67
|
+
"CODE_RETRIEVAL_QUERY"
|
68
|
+
]).optional()
|
47
69
|
});
|
48
70
|
|
49
71
|
// src/google-generative-ai-embedding-model.ts
|
50
72
|
var GoogleGenerativeAIEmbeddingModel = class {
|
51
73
|
constructor(modelId, config) {
|
52
74
|
this.specificationVersion = "v2";
|
75
|
+
this.maxEmbeddingsPerCall = 2048;
|
76
|
+
this.supportsParallelCalls = true;
|
53
77
|
this.modelId = modelId;
|
54
78
|
this.config = config;
|
55
79
|
}
|
56
80
|
get provider() {
|
57
81
|
return this.config.provider;
|
58
82
|
}
|
59
|
-
get maxEmbeddingsPerCall() {
|
60
|
-
return 2048;
|
61
|
-
}
|
62
|
-
get supportsParallelCalls() {
|
63
|
-
return true;
|
64
|
-
}
|
65
83
|
async doEmbed({
|
66
84
|
values,
|
67
85
|
headers,
|
68
86
|
abortSignal,
|
69
87
|
providerOptions
|
70
88
|
}) {
|
71
|
-
|
72
|
-
const googleOptions = (_a = parseProviderOptions({
|
89
|
+
const googleOptions = await parseProviderOptions({
|
73
90
|
provider: "google",
|
74
91
|
providerOptions,
|
75
92
|
schema: googleGenerativeAIEmbeddingProviderOptions
|
76
|
-
})
|
93
|
+
});
|
77
94
|
if (values.length > this.maxEmbeddingsPerCall) {
|
78
95
|
throw new TooManyEmbeddingValuesForCallError({
|
79
96
|
provider: this.provider,
|
@@ -97,7 +114,8 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
97
114
|
requests: values.map((value) => ({
|
98
115
|
model: `models/${this.modelId}`,
|
99
116
|
content: { role: "user", parts: [{ text: value }] },
|
100
|
-
outputDimensionality: googleOptions.outputDimensionality
|
117
|
+
outputDimensionality: googleOptions == null ? void 0 : googleOptions.outputDimensionality,
|
118
|
+
taskType: googleOptions == null ? void 0 : googleOptions.taskType
|
101
119
|
}))
|
102
120
|
},
|
103
121
|
failedResponseHandler: googleFailedResponseHandler,
|
@@ -127,7 +145,7 @@ import {
|
|
127
145
|
postJsonToApi as postJsonToApi2,
|
128
146
|
resolve as resolve2
|
129
147
|
} from "@ai-sdk/provider-utils";
|
130
|
-
import { z as
|
148
|
+
import { z as z5 } from "zod";
|
131
149
|
|
132
150
|
// src/convert-json-schema-to-openapi-schema.ts
|
133
151
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
@@ -348,6 +366,92 @@ function getModelPath(modelId) {
|
|
348
366
|
return modelId.includes("/") ? modelId : `models/${modelId}`;
|
349
367
|
}
|
350
368
|
|
369
|
+
// src/google-generative-ai-options.ts
|
370
|
+
import { z as z4 } from "zod";
|
371
|
+
var dynamicRetrievalConfig = z4.object({
|
372
|
+
/**
|
373
|
+
* The mode of the predictor to be used in dynamic retrieval.
|
374
|
+
*/
|
375
|
+
mode: z4.enum(["MODE_UNSPECIFIED", "MODE_DYNAMIC"]).optional(),
|
376
|
+
/**
|
377
|
+
* The threshold to be used in dynamic retrieval. If not set, a system default
|
378
|
+
* value is used.
|
379
|
+
*/
|
380
|
+
dynamicThreshold: z4.number().optional()
|
381
|
+
});
|
382
|
+
var googleGenerativeAIProviderOptions = z4.object({
|
383
|
+
responseModalities: z4.array(z4.enum(["TEXT", "IMAGE"])).optional(),
|
384
|
+
thinkingConfig: z4.object({
|
385
|
+
thinkingBudget: z4.number().optional()
|
386
|
+
}).optional(),
|
387
|
+
/**
|
388
|
+
Optional.
|
389
|
+
The name of the cached content used as context to serve the prediction.
|
390
|
+
Format: cachedContents/{cachedContent}
|
391
|
+
*/
|
392
|
+
cachedContent: z4.string().optional(),
|
393
|
+
/**
|
394
|
+
* Optional. Enable structured output. Default is true.
|
395
|
+
*
|
396
|
+
* This is useful when the JSON Schema contains elements that are
|
397
|
+
* not supported by the OpenAPI schema version that
|
398
|
+
* Google Generative AI uses. You can use this to disable
|
399
|
+
* structured outputs if you need to.
|
400
|
+
*/
|
401
|
+
structuredOutputs: z4.boolean().optional(),
|
402
|
+
/**
|
403
|
+
Optional. A list of unique safety settings for blocking unsafe content.
|
404
|
+
*/
|
405
|
+
safetySettings: z4.array(
|
406
|
+
z4.object({
|
407
|
+
category: z4.enum([
|
408
|
+
"HARM_CATEGORY_UNSPECIFIED",
|
409
|
+
"HARM_CATEGORY_HATE_SPEECH",
|
410
|
+
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
411
|
+
"HARM_CATEGORY_HARASSMENT",
|
412
|
+
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
413
|
+
"HARM_CATEGORY_CIVIC_INTEGRITY"
|
414
|
+
]),
|
415
|
+
threshold: z4.enum([
|
416
|
+
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
417
|
+
"BLOCK_LOW_AND_ABOVE",
|
418
|
+
"BLOCK_MEDIUM_AND_ABOVE",
|
419
|
+
"BLOCK_ONLY_HIGH",
|
420
|
+
"BLOCK_NONE",
|
421
|
+
"OFF"
|
422
|
+
])
|
423
|
+
})
|
424
|
+
).optional(),
|
425
|
+
threshold: z4.enum([
|
426
|
+
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
427
|
+
"BLOCK_LOW_AND_ABOVE",
|
428
|
+
"BLOCK_MEDIUM_AND_ABOVE",
|
429
|
+
"BLOCK_ONLY_HIGH",
|
430
|
+
"BLOCK_NONE",
|
431
|
+
"OFF"
|
432
|
+
]).optional(),
|
433
|
+
/**
|
434
|
+
* Optional. Enables timestamp understanding for audio-only files.
|
435
|
+
*
|
436
|
+
* https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding
|
437
|
+
*/
|
438
|
+
audioTimestamp: z4.boolean().optional(),
|
439
|
+
/**
|
440
|
+
Optional. When enabled, the model will use Google search to ground the response.
|
441
|
+
|
442
|
+
@see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
|
443
|
+
*/
|
444
|
+
useSearchGrounding: z4.boolean().optional(),
|
445
|
+
/**
|
446
|
+
Optional. Specifies the dynamic retrieval configuration.
|
447
|
+
|
448
|
+
@note Dynamic retrieval is only compatible with Gemini 1.5 Flash.
|
449
|
+
|
450
|
+
@see https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/ground-with-google-search#dynamic-retrieval
|
451
|
+
*/
|
452
|
+
dynamicRetrievalConfig: dynamicRetrievalConfig.optional()
|
453
|
+
});
|
454
|
+
|
351
455
|
// src/google-prepare-tools.ts
|
352
456
|
import {
|
353
457
|
UnsupportedFunctionalityError as UnsupportedFunctionalityError2
|
@@ -356,7 +460,7 @@ function prepareTools({
|
|
356
460
|
tools,
|
357
461
|
toolChoice,
|
358
462
|
useSearchGrounding,
|
359
|
-
dynamicRetrievalConfig,
|
463
|
+
dynamicRetrievalConfig: dynamicRetrievalConfig2,
|
360
464
|
modelId
|
361
465
|
}) {
|
362
466
|
var _a;
|
@@ -367,7 +471,7 @@ function prepareTools({
|
|
367
471
|
if (useSearchGrounding) {
|
368
472
|
return {
|
369
473
|
tools: isGemini2 ? { googleSearch: {} } : {
|
370
|
-
googleSearchRetrieval: !supportsDynamicRetrieval || !
|
474
|
+
googleSearchRetrieval: !supportsDynamicRetrieval || !dynamicRetrievalConfig2 ? {} : { dynamicRetrievalConfig: dynamicRetrievalConfig2 }
|
371
475
|
},
|
372
476
|
toolConfig: void 0,
|
373
477
|
toolWarnings
|
@@ -464,10 +568,9 @@ function mapGoogleGenerativeAIFinishReason({
|
|
464
568
|
|
465
569
|
// src/google-generative-ai-language-model.ts
|
466
570
|
var GoogleGenerativeAILanguageModel = class {
|
467
|
-
constructor(modelId,
|
571
|
+
constructor(modelId, config) {
|
468
572
|
this.specificationVersion = "v2";
|
469
573
|
this.modelId = modelId;
|
470
|
-
this.settings = settings;
|
471
574
|
this.config = config;
|
472
575
|
}
|
473
576
|
get provider() {
|
@@ -494,10 +597,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
494
597
|
}) {
|
495
598
|
var _a, _b;
|
496
599
|
const warnings = [];
|
497
|
-
const googleOptions = parseProviderOptions2({
|
600
|
+
const googleOptions = await parseProviderOptions2({
|
498
601
|
provider: "google",
|
499
602
|
providerOptions,
|
500
|
-
schema:
|
603
|
+
schema: googleGenerativeAIProviderOptions
|
501
604
|
});
|
502
605
|
const { contents, systemInstruction } = convertToGoogleGenerativeAIMessages(prompt);
|
503
606
|
const {
|
@@ -507,8 +610,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
507
610
|
} = prepareTools({
|
508
611
|
tools,
|
509
612
|
toolChoice,
|
510
|
-
useSearchGrounding: (_a =
|
511
|
-
dynamicRetrievalConfig:
|
613
|
+
useSearchGrounding: (_a = googleOptions == null ? void 0 : googleOptions.useSearchGrounding) != null ? _a : false,
|
614
|
+
dynamicRetrievalConfig: googleOptions == null ? void 0 : googleOptions.dynamicRetrievalConfig,
|
512
615
|
modelId: this.modelId
|
513
616
|
});
|
514
617
|
return {
|
@@ -528,9 +631,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
528
631
|
responseSchema: (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && // Google GenAI does not support all OpenAPI Schema features,
|
529
632
|
// so this is needed as an escape hatch:
|
530
633
|
// TODO convert into provider option
|
531
|
-
((_b =
|
532
|
-
...
|
533
|
-
audioTimestamp:
|
634
|
+
((_b = googleOptions == null ? void 0 : googleOptions.structuredOutputs) != null ? _b : true) ? convertJSONSchemaToOpenAPISchema(responseFormat.schema) : void 0,
|
635
|
+
...(googleOptions == null ? void 0 : googleOptions.audioTimestamp) && {
|
636
|
+
audioTimestamp: googleOptions.audioTimestamp
|
534
637
|
},
|
535
638
|
// provider options:
|
536
639
|
responseModalities: googleOptions == null ? void 0 : googleOptions.responseModalities,
|
@@ -538,10 +641,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
538
641
|
},
|
539
642
|
contents,
|
540
643
|
systemInstruction,
|
541
|
-
safetySettings:
|
644
|
+
safetySettings: googleOptions == null ? void 0 : googleOptions.safetySettings,
|
542
645
|
tools: googleTools,
|
543
646
|
toolConfig: googleToolConfig,
|
544
|
-
cachedContent:
|
647
|
+
cachedContent: googleOptions == null ? void 0 : googleOptions.cachedContent
|
545
648
|
},
|
546
649
|
warnings: [...warnings, ...toolWarnings]
|
547
650
|
};
|
@@ -789,100 +892,94 @@ function extractSources({
|
|
789
892
|
title: chunk.web.title
|
790
893
|
}));
|
791
894
|
}
|
792
|
-
var contentSchema =
|
793
|
-
role:
|
794
|
-
parts:
|
795
|
-
|
796
|
-
|
797
|
-
text:
|
895
|
+
var contentSchema = z5.object({
|
896
|
+
role: z5.string(),
|
897
|
+
parts: z5.array(
|
898
|
+
z5.union([
|
899
|
+
z5.object({
|
900
|
+
text: z5.string()
|
798
901
|
}),
|
799
|
-
|
800
|
-
functionCall:
|
801
|
-
name:
|
802
|
-
args:
|
902
|
+
z5.object({
|
903
|
+
functionCall: z5.object({
|
904
|
+
name: z5.string(),
|
905
|
+
args: z5.unknown()
|
803
906
|
})
|
804
907
|
}),
|
805
|
-
|
806
|
-
inlineData:
|
807
|
-
mimeType:
|
808
|
-
data:
|
908
|
+
z5.object({
|
909
|
+
inlineData: z5.object({
|
910
|
+
mimeType: z5.string(),
|
911
|
+
data: z5.string()
|
809
912
|
})
|
810
913
|
})
|
811
914
|
])
|
812
915
|
).nullish()
|
813
916
|
});
|
814
|
-
var groundingChunkSchema =
|
815
|
-
web:
|
816
|
-
retrievedContext:
|
917
|
+
var groundingChunkSchema = z5.object({
|
918
|
+
web: z5.object({ uri: z5.string(), title: z5.string() }).nullish(),
|
919
|
+
retrievedContext: z5.object({ uri: z5.string(), title: z5.string() }).nullish()
|
817
920
|
});
|
818
|
-
var groundingMetadataSchema =
|
819
|
-
webSearchQueries:
|
820
|
-
retrievalQueries:
|
821
|
-
searchEntryPoint:
|
822
|
-
groundingChunks:
|
823
|
-
groundingSupports:
|
824
|
-
|
825
|
-
segment:
|
826
|
-
startIndex:
|
827
|
-
endIndex:
|
828
|
-
text:
|
921
|
+
var groundingMetadataSchema = z5.object({
|
922
|
+
webSearchQueries: z5.array(z5.string()).nullish(),
|
923
|
+
retrievalQueries: z5.array(z5.string()).nullish(),
|
924
|
+
searchEntryPoint: z5.object({ renderedContent: z5.string() }).nullish(),
|
925
|
+
groundingChunks: z5.array(groundingChunkSchema).nullish(),
|
926
|
+
groundingSupports: z5.array(
|
927
|
+
z5.object({
|
928
|
+
segment: z5.object({
|
929
|
+
startIndex: z5.number().nullish(),
|
930
|
+
endIndex: z5.number().nullish(),
|
931
|
+
text: z5.string().nullish()
|
829
932
|
}),
|
830
|
-
segment_text:
|
831
|
-
groundingChunkIndices:
|
832
|
-
supportChunkIndices:
|
833
|
-
confidenceScores:
|
834
|
-
confidenceScore:
|
933
|
+
segment_text: z5.string().nullish(),
|
934
|
+
groundingChunkIndices: z5.array(z5.number()).nullish(),
|
935
|
+
supportChunkIndices: z5.array(z5.number()).nullish(),
|
936
|
+
confidenceScores: z5.array(z5.number()).nullish(),
|
937
|
+
confidenceScore: z5.array(z5.number()).nullish()
|
835
938
|
})
|
836
939
|
).nullish(),
|
837
|
-
retrievalMetadata:
|
838
|
-
|
839
|
-
webDynamicRetrievalScore:
|
940
|
+
retrievalMetadata: z5.union([
|
941
|
+
z5.object({
|
942
|
+
webDynamicRetrievalScore: z5.number()
|
840
943
|
}),
|
841
|
-
|
944
|
+
z5.object({})
|
842
945
|
]).nullish()
|
843
946
|
});
|
844
|
-
var safetyRatingSchema =
|
845
|
-
category:
|
846
|
-
probability:
|
847
|
-
probabilityScore:
|
848
|
-
severity:
|
849
|
-
severityScore:
|
850
|
-
blocked:
|
947
|
+
var safetyRatingSchema = z5.object({
|
948
|
+
category: z5.string(),
|
949
|
+
probability: z5.string(),
|
950
|
+
probabilityScore: z5.number().nullish(),
|
951
|
+
severity: z5.string().nullish(),
|
952
|
+
severityScore: z5.number().nullish(),
|
953
|
+
blocked: z5.boolean().nullish()
|
851
954
|
});
|
852
|
-
var responseSchema =
|
853
|
-
candidates:
|
854
|
-
|
855
|
-
content: contentSchema.nullish().or(
|
856
|
-
finishReason:
|
857
|
-
safetyRatings:
|
955
|
+
var responseSchema = z5.object({
|
956
|
+
candidates: z5.array(
|
957
|
+
z5.object({
|
958
|
+
content: contentSchema.nullish().or(z5.object({}).strict()),
|
959
|
+
finishReason: z5.string().nullish(),
|
960
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish(),
|
858
961
|
groundingMetadata: groundingMetadataSchema.nullish()
|
859
962
|
})
|
860
963
|
),
|
861
|
-
usageMetadata:
|
862
|
-
promptTokenCount:
|
863
|
-
candidatesTokenCount:
|
864
|
-
totalTokenCount:
|
964
|
+
usageMetadata: z5.object({
|
965
|
+
promptTokenCount: z5.number().nullish(),
|
966
|
+
candidatesTokenCount: z5.number().nullish(),
|
967
|
+
totalTokenCount: z5.number().nullish()
|
865
968
|
}).nullish()
|
866
969
|
});
|
867
|
-
var chunkSchema =
|
868
|
-
candidates:
|
869
|
-
|
970
|
+
var chunkSchema = z5.object({
|
971
|
+
candidates: z5.array(
|
972
|
+
z5.object({
|
870
973
|
content: contentSchema.nullish(),
|
871
|
-
finishReason:
|
872
|
-
safetyRatings:
|
974
|
+
finishReason: z5.string().nullish(),
|
975
|
+
safetyRatings: z5.array(safetyRatingSchema).nullish(),
|
873
976
|
groundingMetadata: groundingMetadataSchema.nullish()
|
874
977
|
})
|
875
978
|
).nullish(),
|
876
|
-
usageMetadata:
|
877
|
-
promptTokenCount:
|
878
|
-
candidatesTokenCount:
|
879
|
-
totalTokenCount:
|
880
|
-
}).nullish()
|
881
|
-
});
|
882
|
-
var googleGenerativeAIProviderOptionsSchema = z4.object({
|
883
|
-
responseModalities: z4.array(z4.enum(["TEXT", "IMAGE"])).nullish(),
|
884
|
-
thinkingConfig: z4.object({
|
885
|
-
thinkingBudget: z4.number().nullish()
|
979
|
+
usageMetadata: z5.object({
|
980
|
+
promptTokenCount: z5.number().nullish(),
|
981
|
+
candidatesTokenCount: z5.number().nullish(),
|
982
|
+
totalTokenCount: z5.number().nullish()
|
886
983
|
}).nullish()
|
887
984
|
});
|
888
985
|
|
@@ -898,9 +995,9 @@ function createGoogleGenerativeAI(options = {}) {
|
|
898
995
|
}),
|
899
996
|
...options.headers
|
900
997
|
});
|
901
|
-
const createChatModel = (modelId
|
998
|
+
const createChatModel = (modelId) => {
|
902
999
|
var _a2;
|
903
|
-
return new GoogleGenerativeAILanguageModel(modelId,
|
1000
|
+
return new GoogleGenerativeAILanguageModel(modelId, {
|
904
1001
|
provider: "google.generative-ai",
|
905
1002
|
baseURL,
|
906
1003
|
headers: getHeaders,
|
@@ -920,13 +1017,13 @@ function createGoogleGenerativeAI(options = {}) {
|
|
920
1017
|
headers: getHeaders,
|
921
1018
|
fetch: options.fetch
|
922
1019
|
});
|
923
|
-
const provider = function(modelId
|
1020
|
+
const provider = function(modelId) {
|
924
1021
|
if (new.target) {
|
925
1022
|
throw new Error(
|
926
1023
|
"The Google Generative AI model function cannot be called with the new keyword."
|
927
1024
|
);
|
928
1025
|
}
|
929
|
-
return createChatModel(modelId
|
1026
|
+
return createChatModel(modelId);
|
930
1027
|
};
|
931
1028
|
provider.languageModel = createChatModel;
|
932
1029
|
provider.chat = createChatModel;
|