@ai-sdk/google 4.0.55 → 4.0.57
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 +15 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +14 -0
- package/dist/internal/index.js +22 -5
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/convert-google-usage.ts +3 -0
- package/src/google-language-model.ts +48 -19
- package/src/google-provider.ts +8 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.57",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@ai-sdk/provider": "4.0.8",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.33"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.1",
|
|
@@ -9,13 +9,16 @@ export type GoogleTokenDetail = {
|
|
|
9
9
|
export type GoogleUsageMetadata = {
|
|
10
10
|
promptTokenCount?: number | null;
|
|
11
11
|
candidatesTokenCount?: number | null;
|
|
12
|
+
toolUsePromptTokenCount?: number | null;
|
|
12
13
|
totalTokenCount?: number | null;
|
|
13
14
|
cachedContentTokenCount?: number | null;
|
|
14
15
|
thoughtsTokenCount?: number | null;
|
|
15
16
|
trafficType?: string | null;
|
|
16
17
|
serviceTier?: string | null;
|
|
17
18
|
promptTokensDetails?: GoogleTokenDetail[] | null;
|
|
19
|
+
cacheTokensDetails?: GoogleTokenDetail[] | null;
|
|
18
20
|
candidatesTokensDetails?: GoogleTokenDetail[] | null;
|
|
21
|
+
toolUsePromptTokensDetails?: GoogleTokenDetail[] | null;
|
|
19
22
|
};
|
|
20
23
|
|
|
21
24
|
export function convertGoogleUsage(
|
|
@@ -62,6 +62,8 @@ const configurableSafetySettingCategories = [
|
|
|
62
62
|
'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
|
63
63
|
] as const;
|
|
64
64
|
|
|
65
|
+
const gemini25ModelPattern = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
66
|
+
|
|
65
67
|
export type GoogleLanguageModelConfig = {
|
|
66
68
|
provider: string;
|
|
67
69
|
baseURL: string;
|
|
@@ -258,6 +260,22 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
258
260
|
}
|
|
259
261
|
|
|
260
262
|
const isGemmaModel = this.modelId.toLowerCase().startsWith('gemma-');
|
|
263
|
+
const isGemini25DeveloperApiModel =
|
|
264
|
+
!isVertexProvider && gemini25ModelPattern.test(this.modelId);
|
|
265
|
+
|
|
266
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
267
|
+
warnings.push({
|
|
268
|
+
type: 'unsupported',
|
|
269
|
+
feature: 'frequencyPenalty',
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
273
|
+
warnings.push({
|
|
274
|
+
type: 'unsupported',
|
|
275
|
+
feature: 'presencePenalty',
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
261
279
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
262
280
|
|
|
263
281
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
@@ -331,8 +349,12 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
331
349
|
temperature,
|
|
332
350
|
topK,
|
|
333
351
|
topP,
|
|
334
|
-
frequencyPenalty
|
|
335
|
-
|
|
352
|
+
frequencyPenalty: isGemini25DeveloperApiModel
|
|
353
|
+
? undefined
|
|
354
|
+
: frequencyPenalty,
|
|
355
|
+
presencePenalty: isGemini25DeveloperApiModel
|
|
356
|
+
? undefined
|
|
357
|
+
: presencePenalty,
|
|
336
358
|
stopSequences,
|
|
337
359
|
seed,
|
|
338
360
|
|
|
@@ -1583,26 +1605,33 @@ const getSafetyRatingSchema = () =>
|
|
|
1583
1605
|
|
|
1584
1606
|
const tokenDetailsSchema = z
|
|
1585
1607
|
.array(
|
|
1586
|
-
z
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1608
|
+
z
|
|
1609
|
+
.object({
|
|
1610
|
+
modality: z.string(),
|
|
1611
|
+
tokenCount: z.number(),
|
|
1612
|
+
})
|
|
1613
|
+
.loose(),
|
|
1590
1614
|
)
|
|
1591
1615
|
.nullish();
|
|
1592
1616
|
|
|
1593
|
-
const usageSchema = z
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1617
|
+
const usageSchema = z
|
|
1618
|
+
.object({
|
|
1619
|
+
cachedContentTokenCount: z.number().nullish(),
|
|
1620
|
+
thoughtsTokenCount: z.number().nullish(),
|
|
1621
|
+
promptTokenCount: z.number().nullish(),
|
|
1622
|
+
candidatesTokenCount: z.number().nullish(),
|
|
1623
|
+
toolUsePromptTokenCount: z.number().nullish(),
|
|
1624
|
+
totalTokenCount: z.number().nullish(),
|
|
1625
|
+
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
1626
|
+
trafficType: z.string().nullish(),
|
|
1627
|
+
serviceTier: z.string().nullish(),
|
|
1628
|
+
// https://ai.google.dev/api/generate-content#Modality
|
|
1629
|
+
promptTokensDetails: tokenDetailsSchema,
|
|
1630
|
+
cacheTokensDetails: tokenDetailsSchema,
|
|
1631
|
+
candidatesTokensDetails: tokenDetailsSchema,
|
|
1632
|
+
toolUsePromptTokensDetails: tokenDetailsSchema,
|
|
1633
|
+
})
|
|
1634
|
+
.loose();
|
|
1606
1635
|
|
|
1607
1636
|
// https://ai.google.dev/api/generate-content#UrlRetrievalMetadata
|
|
1608
1637
|
export const getUrlContextMetadataSchema = () =>
|
package/src/google-provider.ts
CHANGED
|
@@ -49,6 +49,10 @@ import type { GoogleTranscriptionModelId } from './transcription/google-transcri
|
|
|
49
49
|
import { GoogleSpeechTranslationModel } from './speech-translation/google-speech-translation-model';
|
|
50
50
|
import type { GoogleSpeechTranslationModelId } from './speech-translation/google-speech-translation-model-options';
|
|
51
51
|
|
|
52
|
+
const DEFAULT_BASE_URL = 'https://generativelanguage.googleapis.com/v1beta';
|
|
53
|
+
const googleFilesUrlPattern =
|
|
54
|
+
/^https:\/\/generativelanguage\.googleapis\.com\/v1beta\/files\/.*$/;
|
|
55
|
+
|
|
52
56
|
export interface GoogleProvider extends ProviderV4 {
|
|
53
57
|
(modelId: GoogleModelId): BatchLanguageModelV4;
|
|
54
58
|
|
|
@@ -237,9 +241,7 @@ function supportsExternalFileUrls(modelId: string) {
|
|
|
237
241
|
export function createGoogle(
|
|
238
242
|
options: GoogleProviderSettings = {},
|
|
239
243
|
): GoogleProvider {
|
|
240
|
-
const baseURL =
|
|
241
|
-
withoutTrailingSlash(options.baseURL) ??
|
|
242
|
-
'https://generativelanguage.googleapis.com/v1beta';
|
|
244
|
+
const baseURL = withoutTrailingSlash(options.baseURL) ?? DEFAULT_BASE_URL;
|
|
243
245
|
|
|
244
246
|
const providerName = options.name ?? 'google.generative-ai';
|
|
245
247
|
|
|
@@ -264,8 +266,10 @@ export function createGoogle(
|
|
|
264
266
|
generateId: options.generateId ?? generateId,
|
|
265
267
|
supportedUrls: () => ({
|
|
266
268
|
'*': [
|
|
267
|
-
// Google Generative Language "files" endpoint
|
|
269
|
+
// Default Google Generative Language "files" endpoint
|
|
268
270
|
// e.g. https://generativelanguage.googleapis.com/v1beta/files/...
|
|
271
|
+
googleFilesUrlPattern,
|
|
272
|
+
// Configured Google Generative Language "files" endpoint
|
|
269
273
|
new RegExp(`^${baseURL}/files/.*$`),
|
|
270
274
|
// YouTube URLs (public or unlisted videos)
|
|
271
275
|
new RegExp(
|