@ai-sdk/google 3.0.14 → 3.0.16
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 +14 -0
- package/dist/index.d.mts +18 -18
- package/dist/index.d.ts +18 -18
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +4 -4
- package/dist/internal/index.d.ts +4 -4
- package/dist/internal/index.js +1 -1
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +1 -1
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +119 -15
- package/package.json +1 -1
- package/src/google-generative-ai-image-settings.ts +1 -1
- package/src/google-generative-ai-language-model.ts +7 -5
- package/src/google-provider.ts +15 -15
|
@@ -69,6 +69,16 @@ You can use the following optional settings to customize the Google Generative A
|
|
|
69
69
|
You can use it as a middleware to intercept requests,
|
|
70
70
|
or to provide a custom fetch implementation for e.g. testing.
|
|
71
71
|
|
|
72
|
+
- **generateId** _() => string_
|
|
73
|
+
|
|
74
|
+
Optional function to generate unique IDs for each request.
|
|
75
|
+
Defaults to the SDK's built-in ID generator.
|
|
76
|
+
|
|
77
|
+
- **name** _string_
|
|
78
|
+
|
|
79
|
+
Custom provider name.
|
|
80
|
+
Defaults to `'google.generative-ai'`.
|
|
81
|
+
|
|
72
82
|
## Language Models
|
|
73
83
|
|
|
74
84
|
You can create models that call the [Google Generative AI API](https://ai.google.dev/api/rest) using the provider instance.
|
|
@@ -141,10 +151,12 @@ The following optional provider options are available for Google Generative AI m
|
|
|
141
151
|
|
|
142
152
|
The category of the safety setting. Can be one of the following:
|
|
143
153
|
|
|
154
|
+
- `HARM_CATEGORY_UNSPECIFIED`
|
|
144
155
|
- `HARM_CATEGORY_HATE_SPEECH`
|
|
145
156
|
- `HARM_CATEGORY_DANGEROUS_CONTENT`
|
|
146
157
|
- `HARM_CATEGORY_HARASSMENT`
|
|
147
158
|
- `HARM_CATEGORY_SEXUALLY_EXPLICIT`
|
|
159
|
+
- `HARM_CATEGORY_CIVIC_INTEGRITY`
|
|
148
160
|
|
|
149
161
|
- **threshold** _string_
|
|
150
162
|
|
|
@@ -155,6 +167,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
155
167
|
- `BLOCK_MEDIUM_AND_ABOVE`
|
|
156
168
|
- `BLOCK_ONLY_HIGH`
|
|
157
169
|
- `BLOCK_NONE`
|
|
170
|
+
- `OFF`
|
|
158
171
|
|
|
159
172
|
- **responseModalities** _string[]_
|
|
160
173
|
The modalities to use for the response. The following modalities are supported: `TEXT`, `IMAGE`. When not defined or empty, the model defaults to returning only text.
|
|
@@ -181,24 +194,58 @@ The following optional provider options are available for Google Generative AI m
|
|
|
181
194
|
|
|
182
195
|
Optional. If set to true, thought summaries are returned, which are synthisized versions of the model's raw thoughts and offer insights into the model's internal reasoning process.
|
|
183
196
|
|
|
184
|
-
- **imageConfig** _\{ aspectRatio
|
|
197
|
+
- **imageConfig** _\{ aspectRatio?: string, imageSize?: string \}_
|
|
185
198
|
|
|
186
199
|
Optional. Configuration for the models image generation. Only supported by specific [Google Generative AI models](https://ai.google.dev/gemini-api/docs/image-generation).
|
|
187
200
|
|
|
188
201
|
- **aspectRatio** _string_
|
|
189
202
|
|
|
190
|
-
|
|
203
|
+
Model defaults to generate 1:1 squares, or to matching the output image size to that of your input image. Can be one of the following:
|
|
204
|
+
|
|
205
|
+
- 1:1
|
|
206
|
+
- 2:3
|
|
207
|
+
- 3:2
|
|
208
|
+
- 3:4
|
|
209
|
+
- 4:3
|
|
210
|
+
- 4:5
|
|
211
|
+
- 5:4
|
|
212
|
+
- 9:16
|
|
213
|
+
- 16:9
|
|
214
|
+
- 21:9
|
|
215
|
+
|
|
216
|
+
- **imageSize** _string_
|
|
217
|
+
|
|
218
|
+
Controls the output image resolution. Defaults to 1K. Can be one of the following:
|
|
219
|
+
|
|
220
|
+
- 1K
|
|
221
|
+
- 2K
|
|
222
|
+
- 4K
|
|
223
|
+
|
|
224
|
+
- **audioTimestamp** _boolean_
|
|
225
|
+
|
|
226
|
+
Optional. Enables timestamp understanding for audio-only files.
|
|
227
|
+
See [Google Cloud audio understanding documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/audio-understanding).
|
|
228
|
+
|
|
229
|
+
- **mediaResolution** _string_
|
|
230
|
+
|
|
231
|
+
Optional. If specified, the media resolution specified will be used. Can be one of the following:
|
|
191
232
|
|
|
192
|
-
-
|
|
193
|
-
-
|
|
194
|
-
-
|
|
195
|
-
-
|
|
196
|
-
|
|
197
|
-
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
233
|
+
- `MEDIA_RESOLUTION_UNSPECIFIED`
|
|
234
|
+
- `MEDIA_RESOLUTION_LOW`
|
|
235
|
+
- `MEDIA_RESOLUTION_MEDIUM`
|
|
236
|
+
- `MEDIA_RESOLUTION_HIGH`
|
|
237
|
+
|
|
238
|
+
See [Google API MediaResolution documentation](https://ai.google.dev/api/generate-content#MediaResolution).
|
|
239
|
+
|
|
240
|
+
- **labels** _Record<string, string>_
|
|
241
|
+
|
|
242
|
+
Optional. Defines labels used in billing reports. Available on Vertex AI only.
|
|
243
|
+
See [Google Cloud labels documentation](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/add-labels-to-api-calls).
|
|
244
|
+
|
|
245
|
+
- **threshold** _string_
|
|
246
|
+
|
|
247
|
+
Optional. Standalone threshold setting that can be used independently of `safetySettings`.
|
|
248
|
+
Uses the same values as the `safetySettings` threshold.
|
|
202
249
|
|
|
203
250
|
### Thinking
|
|
204
251
|
|
|
@@ -483,6 +530,19 @@ const groundingMetadata = metadata?.groundingMetadata;
|
|
|
483
530
|
const safetyRatings = metadata?.safetyRatings;
|
|
484
531
|
```
|
|
485
532
|
|
|
533
|
+
The `googleSearch` tool accepts the following optional configuration options:
|
|
534
|
+
|
|
535
|
+
- **mode** _'MODE_DYNAMIC' | 'MODE_UNSPECIFIED'_
|
|
536
|
+
|
|
537
|
+
The mode of the predictor to be used in dynamic retrieval. Default is `'MODE_UNSPECIFIED'`.
|
|
538
|
+
|
|
539
|
+
- `MODE_DYNAMIC`: Run retrieval only when the system decides it is necessary
|
|
540
|
+
- `MODE_UNSPECIFIED`: Always trigger retrieval
|
|
541
|
+
|
|
542
|
+
- **dynamicThreshold** _number_
|
|
543
|
+
|
|
544
|
+
The threshold to be used in dynamic retrieval. Default is `1`. If not set, a system default value is used.
|
|
545
|
+
|
|
486
546
|
When Search Grounding is enabled, the model will include sources in the response.
|
|
487
547
|
|
|
488
548
|
Additionally, the grounding metadata includes detailed information about how search results were used to ground the model's response. Here are the available fields:
|
|
@@ -531,6 +591,42 @@ Example response:
|
|
|
531
591
|
}
|
|
532
592
|
```
|
|
533
593
|
|
|
594
|
+
### Enterprise Web Search
|
|
595
|
+
|
|
596
|
+
With [Enterprise Web Search](https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise),
|
|
597
|
+
the model has access to a compliance-focused web index designed for highly-regulated industries such as finance, healthcare, and public sector.
|
|
598
|
+
|
|
599
|
+
<Note>
|
|
600
|
+
Enterprise Web Search is only available on Vertex AI. You must use the Google
|
|
601
|
+
Vertex provider (`@ai-sdk/google-vertex`) instead of the standard Google
|
|
602
|
+
provider (`@ai-sdk/google`) to use this feature. Requires Gemini 2.0 or newer
|
|
603
|
+
models.
|
|
604
|
+
</Note>
|
|
605
|
+
|
|
606
|
+
```ts
|
|
607
|
+
import { createVertex } from '@ai-sdk/google-vertex';
|
|
608
|
+
import { generateText } from 'ai';
|
|
609
|
+
|
|
610
|
+
const vertex = createVertex({
|
|
611
|
+
project: 'my-project',
|
|
612
|
+
location: 'us-central1',
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
const { text, sources, providerMetadata } = await generateText({
|
|
616
|
+
model: vertex('gemini-2.5-flash'),
|
|
617
|
+
tools: {
|
|
618
|
+
enterprise_web_search: vertex.tools.enterpriseWebSearch({}),
|
|
619
|
+
},
|
|
620
|
+
prompt: 'What are the latest regulatory updates for financial services?',
|
|
621
|
+
});
|
|
622
|
+
```
|
|
623
|
+
|
|
624
|
+
Enterprise Web Search provides the following benefits:
|
|
625
|
+
|
|
626
|
+
- Does not log customer data
|
|
627
|
+
- Supports VPC service controls
|
|
628
|
+
- Compliance-focused web index for regulated industries
|
|
629
|
+
|
|
534
630
|
### File Search
|
|
535
631
|
|
|
536
632
|
The [File Search tool](https://ai.google.dev/gemini-api/docs/file-search) lets Gemini retrieve context from your own documents that you have indexed in File Search stores. Only Gemini 2.5 and Gemini 3 models support this feature.
|
|
@@ -942,6 +1038,8 @@ The following Zod features are known to not work with Google Generative AI:
|
|
|
942
1038
|
| Model | Image Input | Object Generation | Tool Usage | Tool Streaming | Google Search | URL Context |
|
|
943
1039
|
| ------------------------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
|
|
944
1040
|
| `gemini-3-pro-preview` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
1041
|
+
| `gemini-3-pro-image-preview` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
1042
|
+
| `gemini-3-flash-preview` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
945
1043
|
| `gemini-2.5-pro` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
946
1044
|
| `gemini-2.5-flash` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
947
1045
|
| `gemini-2.5-flash-lite` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
|
|
@@ -964,6 +1062,10 @@ The following Zod features are known to not work with Google Generative AI:
|
|
|
964
1062
|
## Gemma Models
|
|
965
1063
|
|
|
966
1064
|
You can use [Gemma models](https://deepmind.google/models/gemma/) with the Google Generative AI API.
|
|
1065
|
+
The following Gemma models are available:
|
|
1066
|
+
|
|
1067
|
+
- `gemma-3-27b-it`
|
|
1068
|
+
- `gemma-3-12b-it`
|
|
967
1069
|
|
|
968
1070
|
Gemma models don't natively support the `systemInstruction` parameter, but the provider automatically handles system instructions by prepending them to the first user message. This allows you to use system instructions with Gemma models seamlessly:
|
|
969
1071
|
|
|
@@ -1086,6 +1188,8 @@ The following provider options are available:
|
|
|
1086
1188
|
|
|
1087
1189
|
#### Model Capabilities
|
|
1088
1190
|
|
|
1089
|
-
| Model
|
|
1090
|
-
|
|
|
1091
|
-
| `imagen-4.0-generate-001`
|
|
1191
|
+
| Model | Aspect Ratios |
|
|
1192
|
+
| ------------------------------- | ------------------------- |
|
|
1193
|
+
| `imagen-4.0-generate-001` | 1:1, 3:4, 4:3, 9:16, 16:9 |
|
|
1194
|
+
| `imagen-4.0-ultra-generate-001` | 1:1, 3:4, 4:3, 9:16, 16:9 |
|
|
1195
|
+
| `imagen-4.0-fast-generate-001` | 1:1, 3:4, 4:3, 9:16, 16:9 |
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ export type GoogleGenerativeAIImageModelId =
|
|
|
6
6
|
|
|
7
7
|
export interface GoogleGenerativeAIImageSettings {
|
|
8
8
|
/**
|
|
9
|
-
Override the maximum number of images per call (default 4)
|
|
9
|
+
* Override the maximum number of images per call (default 4)
|
|
10
10
|
*/
|
|
11
11
|
maxImagesPerCall?: number;
|
|
12
12
|
}
|
|
@@ -840,11 +840,13 @@ export const getGroundingMetadataSchema = () =>
|
|
|
840
840
|
groundingSupports: z
|
|
841
841
|
.array(
|
|
842
842
|
z.object({
|
|
843
|
-
segment: z
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
843
|
+
segment: z
|
|
844
|
+
.object({
|
|
845
|
+
startIndex: z.number().nullish(),
|
|
846
|
+
endIndex: z.number().nullish(),
|
|
847
|
+
text: z.string().nullish(),
|
|
848
|
+
})
|
|
849
|
+
.nullish(),
|
|
848
850
|
segment_text: z.string().nullish(),
|
|
849
851
|
groundingChunkIndices: z.array(z.number()).nullish(),
|
|
850
852
|
supportChunkIndices: z.array(z.number()).nullish(),
|
package/src/google-provider.ts
CHANGED
|
@@ -32,8 +32,8 @@ export interface GoogleGenerativeAIProvider extends ProviderV3 {
|
|
|
32
32
|
chat(modelId: GoogleGenerativeAIModelId): LanguageModelV3;
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
|
-
Creates a model for image generation.
|
|
36
|
-
|
|
35
|
+
* Creates a model for image generation.
|
|
36
|
+
*/
|
|
37
37
|
image(
|
|
38
38
|
modelId: GoogleGenerativeAIImageModelId,
|
|
39
39
|
settings?: GoogleGenerativeAIImageSettings,
|
|
@@ -71,31 +71,31 @@ Creates a model for image generation.
|
|
|
71
71
|
|
|
72
72
|
export interface GoogleGenerativeAIProviderSettings {
|
|
73
73
|
/**
|
|
74
|
-
Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
75
|
-
The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
|
74
|
+
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
75
|
+
* The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
|
76
76
|
*/
|
|
77
77
|
baseURL?: string;
|
|
78
78
|
|
|
79
79
|
/**
|
|
80
|
-
API key that is being send using the `x-goog-api-key` header.
|
|
81
|
-
It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
|
80
|
+
* API key that is being send using the `x-goog-api-key` header.
|
|
81
|
+
* It defaults to the `GOOGLE_GENERATIVE_AI_API_KEY` environment variable.
|
|
82
82
|
*/
|
|
83
83
|
apiKey?: string;
|
|
84
84
|
|
|
85
85
|
/**
|
|
86
|
-
Custom headers to include in the requests.
|
|
87
|
-
|
|
86
|
+
* Custom headers to include in the requests.
|
|
87
|
+
*/
|
|
88
88
|
headers?: Record<string, string | undefined>;
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
92
|
-
or to provide a custom fetch implementation for e.g. testing.
|
|
93
|
-
|
|
91
|
+
* Custom fetch implementation. You can use it as a middleware to intercept requests,
|
|
92
|
+
* or to provide a custom fetch implementation for e.g. testing.
|
|
93
|
+
*/
|
|
94
94
|
fetch?: FetchFunction;
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
|
-
Optional function to generate a unique ID for each request.
|
|
98
|
-
|
|
97
|
+
* Optional function to generate a unique ID for each request.
|
|
98
|
+
*/
|
|
99
99
|
generateId?: () => string;
|
|
100
100
|
|
|
101
101
|
/**
|
|
@@ -106,7 +106,7 @@ Optional function to generate a unique ID for each request.
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
Create a Google Generative AI provider instance.
|
|
109
|
+
* Create a Google Generative AI provider instance.
|
|
110
110
|
*/
|
|
111
111
|
export function createGoogleGenerativeAI(
|
|
112
112
|
options: GoogleGenerativeAIProviderSettings = {},
|
|
@@ -196,6 +196,6 @@ export function createGoogleGenerativeAI(
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
/**
|
|
199
|
-
Default Google Generative AI provider instance.
|
|
199
|
+
* Default Google Generative AI provider instance.
|
|
200
200
|
*/
|
|
201
201
|
export const google = createGoogleGenerativeAI();
|