@ai-sdk/google 4.0.9 → 4.0.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 +18 -0
- package/dist/index.js +30 -15
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +17 -5
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +30 -44
- package/package.json +3 -3
- package/src/convert-to-google-messages.ts +7 -5
- package/src/google-language-model.ts +18 -1
- package/src/google-video-model.ts +12 -9
package/docs/15-google.mdx
CHANGED
|
@@ -12,21 +12,7 @@ the [Google](https://ai.google.dev/api/rest) APIs.
|
|
|
12
12
|
|
|
13
13
|
The Google provider is available in the `@ai-sdk/google` module. You can install it with
|
|
14
14
|
|
|
15
|
-
<
|
|
16
|
-
<Tab>
|
|
17
|
-
<Snippet text="pnpm add @ai-sdk/google" dark />
|
|
18
|
-
</Tab>
|
|
19
|
-
<Tab>
|
|
20
|
-
<Snippet text="npm install @ai-sdk/google" dark />
|
|
21
|
-
</Tab>
|
|
22
|
-
<Tab>
|
|
23
|
-
<Snippet text="yarn add @ai-sdk/google" dark />
|
|
24
|
-
</Tab>
|
|
25
|
-
|
|
26
|
-
<Tab>
|
|
27
|
-
<Snippet text="bun add @ai-sdk/google" dark />
|
|
28
|
-
</Tab>
|
|
29
|
-
</Tabs>
|
|
15
|
+
<InstallPackages packages="@ai-sdk/google" />
|
|
30
16
|
|
|
31
17
|
## Provider Instance
|
|
32
18
|
|
|
@@ -1043,20 +1029,20 @@ The following Zod features are known to not work with Google:
|
|
|
1043
1029
|
|
|
1044
1030
|
### Model Capabilities
|
|
1045
1031
|
|
|
1046
|
-
| Model | Image Input
|
|
1047
|
-
| ------------------------------------- |
|
|
1048
|
-
| `gemini-3.5-flash` | <Check
|
|
1049
|
-
| `gemini-3.1-pro-preview` | <Check
|
|
1050
|
-
| `gemini-3.1-flash-image-preview` | <Check
|
|
1051
|
-
| `gemini-3.1-flash-lite-preview` | <Check
|
|
1052
|
-
| `gemini-3-pro-preview` | <Check
|
|
1053
|
-
| `gemini-3-pro-image-preview` | <Check
|
|
1054
|
-
| `gemini-3-flash-preview` | <Check
|
|
1055
|
-
| `gemini-2.5-pro` | <Check
|
|
1056
|
-
| `gemini-2.5-flash` | <Check
|
|
1057
|
-
| `gemini-2.5-flash-lite` | <Check
|
|
1058
|
-
| `gemini-2.5-flash-lite-preview-06-17` | <Check
|
|
1059
|
-
| `gemini-2.0-flash` | <Check
|
|
1032
|
+
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Google Search | URL Context |
|
|
1033
|
+
| ------------------------------------- | ----------- | ----------------- | ---------- | -------------- | ------------- | ----------- |
|
|
1034
|
+
| `gemini-3.5-flash` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1035
|
+
| `gemini-3.1-pro-preview` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1036
|
+
| `gemini-3.1-flash-image-preview` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1037
|
+
| `gemini-3.1-flash-lite-preview` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1038
|
+
| `gemini-3-pro-preview` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1039
|
+
| `gemini-3-pro-image-preview` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1040
|
+
| `gemini-3-flash-preview` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1041
|
+
| `gemini-2.5-pro` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1042
|
+
| `gemini-2.5-flash` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1043
|
+
| `gemini-2.5-flash-lite` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1044
|
+
| `gemini-2.5-flash-lite-preview-06-17` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1045
|
+
| `gemini-2.0-flash` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
1060
1046
|
|
|
1061
1047
|
<Note>
|
|
1062
1048
|
The table above lists popular models. Please see the [Google Generative AI
|
|
@@ -1836,11 +1822,11 @@ The following optional provider options are available for Google embedding model
|
|
|
1836
1822
|
|
|
1837
1823
|
### Model Capabilities
|
|
1838
1824
|
|
|
1839
|
-
| Model | Default Dimensions | Custom Dimensions
|
|
1840
|
-
| ---------------------------- | ------------------ |
|
|
1841
|
-
| `gemini-embedding-001` | 3072 | <Check
|
|
1842
|
-
| `gemini-embedding-2` | 3072 | <Check
|
|
1843
|
-
| `gemini-embedding-2-preview` | 3072 | <Check
|
|
1825
|
+
| Model | Default Dimensions | Custom Dimensions | Multimodal |
|
|
1826
|
+
| ---------------------------- | ------------------ | ----------------- | ---------- |
|
|
1827
|
+
| `gemini-embedding-001` | 3072 | <Check /> | <Cross /> |
|
|
1828
|
+
| `gemini-embedding-2` | 3072 | <Check /> | <Check /> |
|
|
1829
|
+
| `gemini-embedding-2-preview` | 3072 | <Check /> | <Check /> |
|
|
1844
1830
|
|
|
1845
1831
|
## Image Models
|
|
1846
1832
|
|
|
@@ -1988,11 +1974,11 @@ console.log(result.providerMetadata?.google?.groundingMetadata);
|
|
|
1988
1974
|
|
|
1989
1975
|
#### Gemini Image Model Capabilities
|
|
1990
1976
|
|
|
1991
|
-
| Model | Image Generation
|
|
1992
|
-
| -------------------------------- |
|
|
1993
|
-
| `gemini-2.5-flash-image` | <Check
|
|
1994
|
-
| `gemini-3-pro-image-preview` | <Check
|
|
1995
|
-
| `gemini-3.1-flash-image-preview` | <Check
|
|
1977
|
+
| Model | Image Generation | Image Editing | Aspect Ratios |
|
|
1978
|
+
| -------------------------------- | ---------------- | ------------- | --------------------------------------------------- |
|
|
1979
|
+
| `gemini-2.5-flash-image` | <Check /> | <Check /> | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
|
|
1980
|
+
| `gemini-3-pro-image-preview` | <Check /> | <Check /> | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
|
|
1981
|
+
| `gemini-3.1-flash-image-preview` | <Check /> | <Check /> | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9 |
|
|
1996
1982
|
|
|
1997
1983
|
<Note>
|
|
1998
1984
|
`gemini-3-pro-image-preview` supports additional features including up to 14
|
|
@@ -2072,8 +2058,8 @@ const result = await generateSpeech({
|
|
|
2072
2058
|
|
|
2073
2059
|
### Model Capabilities
|
|
2074
2060
|
|
|
2075
|
-
| Model | Multi-speaker
|
|
2076
|
-
| ------------------------------ |
|
|
2077
|
-
| `gemini-2.5-flash-preview-tts` | <Check
|
|
2078
|
-
| `gemini-2.5-pro-preview-tts` | <Check
|
|
2079
|
-
| `gemini-3.1-flash-tts-preview` | <Check
|
|
2061
|
+
| Model | Multi-speaker | Style via instructions |
|
|
2062
|
+
| ------------------------------ | ------------- | ---------------------- |
|
|
2063
|
+
| `gemini-2.5-flash-preview-tts` | <Check /> | <Check /> |
|
|
2064
|
+
| `gemini-2.5-pro-preview-tts` | <Check /> | <Check /> |
|
|
2065
|
+
| `gemini-3.1-flash-tts-preview` | <Check /> | <Check /> |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.11",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.3",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.7"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "22.19.19",
|
|
@@ -163,10 +163,9 @@ function appendLegacyToolResultParts(
|
|
|
163
163
|
});
|
|
164
164
|
break;
|
|
165
165
|
case 'file': {
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
) {
|
|
166
|
+
if (contentPart.data.type === 'data') {
|
|
167
|
+
const topLevelMediaType = getTopLevelMediaType(contentPart.mediaType);
|
|
168
|
+
|
|
170
169
|
parts.push(
|
|
171
170
|
{
|
|
172
171
|
inlineData: {
|
|
@@ -175,7 +174,10 @@ function appendLegacyToolResultParts(
|
|
|
175
174
|
},
|
|
176
175
|
},
|
|
177
176
|
{
|
|
178
|
-
text:
|
|
177
|
+
text:
|
|
178
|
+
`Tool executed successfully and returned this ` +
|
|
179
|
+
`${topLevelMediaType === 'image' ? 'image' : 'file'} ` +
|
|
180
|
+
`as a response`,
|
|
179
181
|
},
|
|
180
182
|
);
|
|
181
183
|
} else {
|
|
@@ -54,6 +54,13 @@ import {
|
|
|
54
54
|
} from './google-json-accumulator';
|
|
55
55
|
import { mapGoogleFinishReason } from './map-google-finish-reason';
|
|
56
56
|
|
|
57
|
+
const configurableSafetySettingCategories = [
|
|
58
|
+
'HARM_CATEGORY_HATE_SPEECH',
|
|
59
|
+
'HARM_CATEGORY_DANGEROUS_CONTENT',
|
|
60
|
+
'HARM_CATEGORY_HARASSMENT',
|
|
61
|
+
'HARM_CATEGORY_SEXUALLY_EXPLICIT',
|
|
62
|
+
] as const;
|
|
63
|
+
|
|
57
64
|
type GoogleConfig = {
|
|
58
65
|
provider: string;
|
|
59
66
|
baseURL: string;
|
|
@@ -258,6 +265,16 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
258
265
|
? (googleOptions?.streamFunctionCallArguments ?? false)
|
|
259
266
|
: undefined;
|
|
260
267
|
|
|
268
|
+
const safetyThreshold = googleOptions?.threshold;
|
|
269
|
+
const safetySettings =
|
|
270
|
+
googleOptions?.safetySettings ??
|
|
271
|
+
(safetyThreshold != null
|
|
272
|
+
? configurableSafetySettingCategories.map(category => ({
|
|
273
|
+
category,
|
|
274
|
+
threshold: safetyThreshold,
|
|
275
|
+
}))
|
|
276
|
+
: undefined);
|
|
277
|
+
|
|
261
278
|
const toolConfig =
|
|
262
279
|
googleToolConfig ||
|
|
263
280
|
streamFunctionCallArguments ||
|
|
@@ -317,7 +334,7 @@ export class GoogleLanguageModel implements LanguageModelV4 {
|
|
|
317
334
|
},
|
|
318
335
|
contents,
|
|
319
336
|
systemInstruction: isGemmaModel ? undefined : systemInstruction,
|
|
320
|
-
safetySettings
|
|
337
|
+
safetySettings,
|
|
321
338
|
tools: googleTools,
|
|
322
339
|
toolConfig,
|
|
323
340
|
cachedContent: googleOptions?.cachedContent,
|
|
@@ -94,13 +94,11 @@ function convertFileToGoogleImage(
|
|
|
94
94
|
? file.data
|
|
95
95
|
: convertUint8ArrayToBase64(file.data);
|
|
96
96
|
|
|
97
|
-
//
|
|
98
|
-
//
|
|
97
|
+
// Veo's predictLongRunning endpoint uses Vertex-style image payloads, not
|
|
98
|
+
// Gemini generateContent inlineData.
|
|
99
99
|
return {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
data: base64Data,
|
|
103
|
-
},
|
|
100
|
+
bytesBase64Encoded: base64Data,
|
|
101
|
+
mimeType: file.mediaType || 'image/png',
|
|
104
102
|
};
|
|
105
103
|
}
|
|
106
104
|
|
|
@@ -109,16 +107,21 @@ function convertProviderReferenceImage(
|
|
|
109
107
|
): Record<string, unknown> {
|
|
110
108
|
if (refImg.bytesBase64Encoded) {
|
|
111
109
|
return {
|
|
112
|
-
|
|
110
|
+
image: {
|
|
111
|
+
bytesBase64Encoded: refImg.bytesBase64Encoded,
|
|
113
112
|
mimeType: 'image/png',
|
|
114
|
-
data: refImg.bytesBase64Encoded,
|
|
115
113
|
},
|
|
114
|
+
referenceType: 'asset',
|
|
116
115
|
};
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
if (refImg.gcsUri) {
|
|
120
119
|
return {
|
|
121
|
-
|
|
120
|
+
image: {
|
|
121
|
+
gcsUri: refImg.gcsUri,
|
|
122
|
+
mimeType: 'image/png',
|
|
123
|
+
},
|
|
124
|
+
referenceType: 'asset',
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
127
|
|