@ai-sdk/google 4.0.0-beta.43 → 4.0.0-beta.45
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/README.md +4 -4
- package/dist/index.d.ts +33 -33
- package/dist/index.js +46 -55
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +9 -9
- package/dist/internal/index.js +22 -25
- package/dist/internal/index.js.map +1 -1
- package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +36 -36
- package/package.json +2 -2
- package/src/{convert-google-generative-ai-usage.ts → convert-google-usage.ts} +6 -6
- package/src/{convert-to-google-generative-ai-messages.ts → convert-to-google-messages.ts} +14 -14
- package/src/{google-generative-ai-embedding-model.ts → google-embedding-model.ts} +10 -16
- package/src/{google-generative-ai-embedding-options.ts → google-embedding-options.ts} +1 -1
- package/src/{google-generative-ai-files.ts → google-files.ts} +3 -3
- package/src/{google-generative-ai-image-model.ts → google-image-model.ts} +16 -20
- package/src/{google-generative-ai-image-settings.ts → google-image-settings.ts} +2 -2
- package/src/{google-generative-ai-language-model.ts → google-language-model.ts} +28 -34
- package/src/{google-generative-ai-options.ts → google-options.ts} +2 -2
- package/src/google-prepare-tools.ts +3 -3
- package/src/google-prompt.ts +82 -0
- package/src/google-provider.ts +42 -46
- package/src/{google-generative-ai-video-model.ts → google-video-model.ts} +5 -5
- package/src/{google-generative-ai-video-settings.ts → google-video-settings.ts} +1 -1
- package/src/index.ts +28 -10
- package/src/internal/index.ts +2 -2
- package/src/{map-google-generative-ai-finish-reason.ts → map-google-finish-reason.ts} +1 -1
- package/src/google-generative-ai-prompt.ts +0 -82
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: Google
|
|
3
|
-
description: Learn how to use Google
|
|
2
|
+
title: Google
|
|
3
|
+
description: Learn how to use Google Provider.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# Google
|
|
6
|
+
# Google Provider
|
|
7
7
|
|
|
8
|
-
The [Google
|
|
9
|
-
the [Google
|
|
8
|
+
The [Google](https://ai.google.dev) provider contains language and embedding model support for
|
|
9
|
+
the [Google](https://ai.google.dev/api/rest) APIs.
|
|
10
10
|
|
|
11
11
|
## Setup
|
|
12
12
|
|
|
@@ -36,17 +36,17 @@ You can import the default provider instance `google` from `@ai-sdk/google`:
|
|
|
36
36
|
import { google } from '@ai-sdk/google';
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
If you need a customized setup, you can import `
|
|
39
|
+
If you need a customized setup, you can import `createGoogle` from `@ai-sdk/google` and create a provider instance with your settings:
|
|
40
40
|
|
|
41
41
|
```ts
|
|
42
|
-
import {
|
|
42
|
+
import { createGoogle } from '@ai-sdk/google';
|
|
43
43
|
|
|
44
|
-
const google =
|
|
44
|
+
const google = createGoogle({
|
|
45
45
|
// custom settings
|
|
46
46
|
});
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
You can use the following optional settings to customize the Google
|
|
49
|
+
You can use the following optional settings to customize the Google provider instance:
|
|
50
50
|
|
|
51
51
|
- **baseURL** _string_
|
|
52
52
|
|
|
@@ -89,7 +89,7 @@ The models support tool calls and some have multi-modal capabilities.
|
|
|
89
89
|
const model = google('gemini-2.5-flash');
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
You can use Google
|
|
92
|
+
You can use Google language models to generate text with the `generateText` function:
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
95
|
import { google } from '@ai-sdk/google';
|
|
@@ -101,11 +101,11 @@ const { text } = await generateText({
|
|
|
101
101
|
});
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
Google
|
|
104
|
+
Google language models can also be used in the `streamText` function
|
|
105
105
|
and support structured data generation with [`Output`](/docs/reference/ai-sdk-core/output)
|
|
106
106
|
(see [AI SDK Core](/docs/ai-sdk-core)).
|
|
107
107
|
|
|
108
|
-
Google
|
|
108
|
+
Google also supports some model specific settings that are not part of the [standard call settings](/docs/ai-sdk-core/settings).
|
|
109
109
|
You can pass them as an options argument:
|
|
110
110
|
|
|
111
111
|
```ts
|
|
@@ -128,7 +128,7 @@ await generateText({
|
|
|
128
128
|
});
|
|
129
129
|
```
|
|
130
130
|
|
|
131
|
-
The following optional provider options are available for Google
|
|
131
|
+
The following optional provider options are available for Google models:
|
|
132
132
|
|
|
133
133
|
- **cachedContent** _string_
|
|
134
134
|
|
|
@@ -141,7 +141,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
141
141
|
|
|
142
142
|
This is useful when the JSON Schema contains elements that are
|
|
143
143
|
not supported by the OpenAPI schema version that
|
|
144
|
-
Google
|
|
144
|
+
Google uses. You can use this to disable
|
|
145
145
|
structured outputs if you need to.
|
|
146
146
|
|
|
147
147
|
See [Troubleshooting: Schema Limitations](#schema-limitations) for more details.
|
|
@@ -177,7 +177,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
177
177
|
|
|
178
178
|
- **thinkingConfig** _\{ thinkingLevel?: 'minimal' | 'low' | 'medium' | 'high'; thinkingBudget?: number; includeThoughts?: boolean \}_
|
|
179
179
|
|
|
180
|
-
Optional. Configuration for the model's thinking process. Only supported by specific [Google
|
|
180
|
+
Optional. Configuration for the model's thinking process. Only supported by specific [Google models](https://ai.google.dev/gemini-api/docs/thinking).
|
|
181
181
|
|
|
182
182
|
- **thinkingLevel** _'minimal' | 'low' | 'medium' | 'high'_
|
|
183
183
|
|
|
@@ -186,7 +186,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
186
186
|
- **thinkingBudget** _number_
|
|
187
187
|
|
|
188
188
|
Optional. Gives the model guidance on the number of thinking tokens it can use when generating a response. Setting it to 0 disables thinking, if the model supports it.
|
|
189
|
-
For more information about the possible value ranges for each model see [Google
|
|
189
|
+
For more information about the possible value ranges for each model see [Google thinking documentation](https://ai.google.dev/gemini-api/docs/thinking#set-budget).
|
|
190
190
|
|
|
191
191
|
<Note>
|
|
192
192
|
This option is for Gemini 2.5 models. Gemini 3 models should use
|
|
@@ -199,7 +199,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
199
199
|
|
|
200
200
|
- **imageConfig** _\{ aspectRatio?: string, imageSize?: string \}_
|
|
201
201
|
|
|
202
|
-
Optional. Configuration for the models image generation. Only supported by specific [Google
|
|
202
|
+
Optional. Configuration for the models image generation. Only supported by specific [Google models](https://ai.google.dev/gemini-api/docs/image-generation).
|
|
203
203
|
|
|
204
204
|
- **aspectRatio** _string_
|
|
205
205
|
|
|
@@ -258,7 +258,7 @@ The following optional provider options are available for Google Generative AI m
|
|
|
258
258
|
|
|
259
259
|
### Thinking
|
|
260
260
|
|
|
261
|
-
The Gemini 2.5 and Gemini 3 series models use an internal "thinking process" that significantly improves their reasoning and multi-step planning abilities, making them highly effective for complex tasks such as coding, advanced mathematics, and data analysis. For more information see [Google
|
|
261
|
+
The Gemini 2.5 and Gemini 3 series models use an internal "thinking process" that significantly improves their reasoning and multi-step planning abilities, making them highly effective for complex tasks such as coding, advanced mathematics, and data analysis. For more information see [Google thinking documentation](https://ai.google.dev/gemini-api/docs/thinking).
|
|
262
262
|
|
|
263
263
|
#### Gemini 3 Models
|
|
264
264
|
|
|
@@ -318,7 +318,7 @@ console.log(reasoning); // Reasoning summary
|
|
|
318
318
|
|
|
319
319
|
### File Inputs
|
|
320
320
|
|
|
321
|
-
The Google
|
|
321
|
+
The Google provider supports file inputs, e.g. PDF files.
|
|
322
322
|
|
|
323
323
|
```ts
|
|
324
324
|
import { google } from '@ai-sdk/google';
|
|
@@ -384,7 +384,7 @@ See [File Parts](/docs/foundations/prompts#file-parts) for details on how to use
|
|
|
384
384
|
|
|
385
385
|
### Cached Content
|
|
386
386
|
|
|
387
|
-
Google
|
|
387
|
+
Google supports both explicit and implicit caching to help reduce costs on repetitive content.
|
|
388
388
|
|
|
389
389
|
#### Implicit Caching
|
|
390
390
|
|
|
@@ -516,7 +516,7 @@ the model has access to the latest information using Google Search.
|
|
|
516
516
|
|
|
517
517
|
```ts highlight="8,17-20"
|
|
518
518
|
import { google } from '@ai-sdk/google';
|
|
519
|
-
import {
|
|
519
|
+
import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
520
520
|
import { generateText } from 'ai';
|
|
521
521
|
|
|
522
522
|
const { text, sources, providerMetadata } = await generateText({
|
|
@@ -532,7 +532,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
532
532
|
// access the grounding metadata. Casting to the provider metadata type
|
|
533
533
|
// is optional but provides autocomplete and type safety.
|
|
534
534
|
const metadata = providerMetadata?.google as
|
|
535
|
-
|
|
|
535
|
+
| GoogleProviderMetadata
|
|
536
536
|
| undefined;
|
|
537
537
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
538
538
|
const safetyRatings = metadata?.safetyRatings;
|
|
@@ -693,7 +693,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
693
693
|
});
|
|
694
694
|
|
|
695
695
|
const metadata = providerMetadata?.google as
|
|
696
|
-
|
|
|
696
|
+
| GoogleProviderMetadata
|
|
697
697
|
| undefined;
|
|
698
698
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
699
699
|
const urlContextMetadata = metadata?.urlContextMetadata;
|
|
@@ -714,7 +714,7 @@ Example response:
|
|
|
714
714
|
{
|
|
715
715
|
"urlMetadata": [
|
|
716
716
|
{
|
|
717
|
-
"retrievedUrl": "https://ai-sdk.dev/providers/ai-sdk-providers/google
|
|
717
|
+
"retrievedUrl": "https://ai-sdk.dev/providers/ai-sdk-providers/google",
|
|
718
718
|
"urlRetrievalStatus": "URL_RETRIEVAL_STATUS_SUCCESS"
|
|
719
719
|
}
|
|
720
720
|
]
|
|
@@ -728,8 +728,8 @@ With the URL context tool, you will also get the `groundingMetadata`.
|
|
|
728
728
|
"groundingChunks": [
|
|
729
729
|
{
|
|
730
730
|
"web": {
|
|
731
|
-
"uri": "https://ai-sdk.dev/providers/ai-sdk-providers/google
|
|
732
|
-
"title": "Google
|
|
731
|
+
"uri": "https://ai-sdk.dev/providers/ai-sdk-providers/google",
|
|
732
|
+
"title": "Google - AI SDK Providers"
|
|
733
733
|
}
|
|
734
734
|
}
|
|
735
735
|
],
|
|
@@ -766,7 +766,7 @@ import { generateText } from 'ai';
|
|
|
766
766
|
|
|
767
767
|
const { text, sources, providerMetadata } = await generateText({
|
|
768
768
|
model: google('gemini-2.5-flash'),
|
|
769
|
-
prompt: `Based on this context: https://ai-sdk.dev/providers/ai-sdk-providers/google
|
|
769
|
+
prompt: `Based on this context: https://ai-sdk.dev/providers/ai-sdk-providers/google, tell me how to use Gemini with AI SDK.
|
|
770
770
|
Also, provide the latest news about AI SDK V5.`,
|
|
771
771
|
tools: {
|
|
772
772
|
google_search: google.tools.googleSearch({}),
|
|
@@ -775,7 +775,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
775
775
|
});
|
|
776
776
|
|
|
777
777
|
const metadata = providerMetadata?.google as
|
|
778
|
-
|
|
|
778
|
+
| GoogleProviderMetadata
|
|
779
779
|
| undefined;
|
|
780
780
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
781
781
|
const urlContextMetadata = metadata?.urlContextMetadata;
|
|
@@ -788,7 +788,7 @@ the model has access to Google Maps data for location-aware responses. This enab
|
|
|
788
788
|
|
|
789
789
|
```ts highlight="7-16"
|
|
790
790
|
import { google, type GoogleLanguageModelOptions } from '@ai-sdk/google';
|
|
791
|
-
import {
|
|
791
|
+
import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
792
792
|
import { generateText } from 'ai';
|
|
793
793
|
|
|
794
794
|
const { text, sources, providerMetadata } = await generateText({
|
|
@@ -808,7 +808,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
808
808
|
});
|
|
809
809
|
|
|
810
810
|
const metadata = providerMetadata?.google as
|
|
811
|
-
|
|
|
811
|
+
| GoogleProviderMetadata
|
|
812
812
|
| undefined;
|
|
813
813
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
814
814
|
```
|
|
@@ -849,7 +849,7 @@ This enables the model to provide answers based on your specific data sources an
|
|
|
849
849
|
|
|
850
850
|
```ts highlight="8,17-20"
|
|
851
851
|
import { createVertex } from '@ai-sdk/google-vertex';
|
|
852
|
-
import {
|
|
852
|
+
import { GoogleProviderMetadata } from '@ai-sdk/google';
|
|
853
853
|
import { generateText } from 'ai';
|
|
854
854
|
|
|
855
855
|
const vertex = createVertex({
|
|
@@ -873,7 +873,7 @@ const { text, sources, providerMetadata } = await generateText({
|
|
|
873
873
|
// access the grounding metadata. Casting to the provider metadata type
|
|
874
874
|
// is optional but provides autocomplete and type safety.
|
|
875
875
|
const metadata = providerMetadata?.google as
|
|
876
|
-
|
|
|
876
|
+
| GoogleProviderMetadata
|
|
877
877
|
| undefined;
|
|
878
878
|
const groundingMetadata = metadata?.groundingMetadata;
|
|
879
879
|
const safetyRatings = metadata?.safetyRatings;
|
|
@@ -1057,7 +1057,7 @@ const { output } = await generateText({
|
|
|
1057
1057
|
});
|
|
1058
1058
|
```
|
|
1059
1059
|
|
|
1060
|
-
The following Zod features are known to not work with Google
|
|
1060
|
+
The following Zod features are known to not work with Google:
|
|
1061
1061
|
|
|
1062
1062
|
- `z.union`
|
|
1063
1063
|
- `z.record`
|
|
@@ -1117,12 +1117,12 @@ using the `.embedding()` factory method.
|
|
|
1117
1117
|
const model = google.embedding('gemini-embedding-001');
|
|
1118
1118
|
```
|
|
1119
1119
|
|
|
1120
|
-
The Google
|
|
1120
|
+
The Google provider sends API calls to the right endpoint based on the type of embedding:
|
|
1121
1121
|
|
|
1122
1122
|
- **Single embeddings**: When embedding a single value with `embed()`, the provider uses the single `:embedContent` endpoint, which typically has higher rate limits compared to the batch endpoint.
|
|
1123
1123
|
- **Batch embeddings**: When embedding multiple values with `embedMany()` or multiple values in `embed()`, the provider uses the `:batchEmbedContents` endpoint.
|
|
1124
1124
|
|
|
1125
|
-
Google
|
|
1125
|
+
Google embedding models support additional settings. You can pass them as an options argument:
|
|
1126
1126
|
|
|
1127
1127
|
```ts
|
|
1128
1128
|
import { google, type GoogleEmbeddingModelOptions } from '@ai-sdk/google';
|
|
@@ -1164,7 +1164,7 @@ const { embeddings } = await embedMany({
|
|
|
1164
1164
|
});
|
|
1165
1165
|
```
|
|
1166
1166
|
|
|
1167
|
-
The following optional provider options are available for Google
|
|
1167
|
+
The following optional provider options are available for Google embedding models:
|
|
1168
1168
|
|
|
1169
1169
|
- **outputDimensionality**: _number_
|
|
1170
1170
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.45",
|
|
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.0-beta.12",
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.26"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@types/node": "20.17.24",
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type GoogleTokenDetail = {
|
|
4
4
|
modality: string;
|
|
5
5
|
tokenCount: number;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type GoogleUsageMetadata = {
|
|
9
9
|
promptTokenCount?: number | null;
|
|
10
10
|
candidatesTokenCount?: number | null;
|
|
11
11
|
totalTokenCount?: number | null;
|
|
12
12
|
cachedContentTokenCount?: number | null;
|
|
13
13
|
thoughtsTokenCount?: number | null;
|
|
14
14
|
trafficType?: string | null;
|
|
15
|
-
promptTokensDetails?:
|
|
16
|
-
candidatesTokensDetails?:
|
|
15
|
+
promptTokensDetails?: GoogleTokenDetail[] | null;
|
|
16
|
+
candidatesTokensDetails?: GoogleTokenDetail[] | null;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
-
export function
|
|
20
|
-
usage:
|
|
19
|
+
export function convertGoogleUsage(
|
|
20
|
+
usage: GoogleUsageMetadata | undefined | null,
|
|
21
21
|
): LanguageModelV4Usage {
|
|
22
22
|
if (usage == null) {
|
|
23
23
|
return {
|
|
@@ -8,11 +8,11 @@ import {
|
|
|
8
8
|
resolveProviderReference,
|
|
9
9
|
} from '@ai-sdk/provider-utils';
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from './google-
|
|
11
|
+
GoogleContent,
|
|
12
|
+
GoogleContentPart,
|
|
13
|
+
GoogleFunctionResponsePart,
|
|
14
|
+
GooglePrompt,
|
|
15
|
+
} from './google-prompt';
|
|
16
16
|
|
|
17
17
|
const dataUrlRegex = /^data:([^;,]+);base64,(.+)$/s;
|
|
18
18
|
|
|
@@ -32,7 +32,7 @@ function parseBase64DataUrl(
|
|
|
32
32
|
|
|
33
33
|
function convertUrlToolResultPart(
|
|
34
34
|
url: string,
|
|
35
|
-
):
|
|
35
|
+
): GoogleFunctionResponsePart | undefined {
|
|
36
36
|
// Per https://ai.google.dev/api/caching#FunctionResponsePart, only inline data is supported.
|
|
37
37
|
// https://docs.cloud.google.com/vertex-ai/generative-ai/docs/model-reference/function-calling#functionresponsepart suggests that this
|
|
38
38
|
// may be different for Vertex, but this needs to be confirmed and further tested for both APIs.
|
|
@@ -55,14 +55,14 @@ function convertUrlToolResultPart(
|
|
|
55
55
|
* text). This format is supported by Gemini 3+ models.
|
|
56
56
|
*/
|
|
57
57
|
function appendToolResultParts(
|
|
58
|
-
parts:
|
|
58
|
+
parts: GoogleContentPart[],
|
|
59
59
|
toolName: string,
|
|
60
60
|
outputValue: Array<{
|
|
61
61
|
type: string;
|
|
62
62
|
[key: string]: unknown;
|
|
63
63
|
}>,
|
|
64
64
|
): void {
|
|
65
|
-
const functionResponseParts:
|
|
65
|
+
const functionResponseParts: GoogleFunctionResponsePart[] = [];
|
|
66
66
|
const responseTextParts: string[] = [];
|
|
67
67
|
|
|
68
68
|
for (const contentPart of outputValue) {
|
|
@@ -122,7 +122,7 @@ function appendToolResultParts(
|
|
|
122
122
|
* non-text content like images is sent as separate top-level inlineData parts.
|
|
123
123
|
*/
|
|
124
124
|
function appendLegacyToolResultParts(
|
|
125
|
-
parts:
|
|
125
|
+
parts: GoogleContentPart[],
|
|
126
126
|
toolName: string,
|
|
127
127
|
outputValue: Array<{
|
|
128
128
|
type: string;
|
|
@@ -166,16 +166,16 @@ function appendLegacyToolResultParts(
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
export function
|
|
169
|
+
export function convertToGoogleMessages(
|
|
170
170
|
prompt: LanguageModelV4Prompt,
|
|
171
171
|
options?: {
|
|
172
172
|
isGemmaModel?: boolean;
|
|
173
173
|
providerOptionsName?: string;
|
|
174
174
|
supportsFunctionResponseParts?: boolean;
|
|
175
175
|
},
|
|
176
|
-
):
|
|
176
|
+
): GooglePrompt {
|
|
177
177
|
const systemInstructionParts: Array<{ text: string }> = [];
|
|
178
|
-
const contents: Array<
|
|
178
|
+
const contents: Array<GoogleContent> = [];
|
|
179
179
|
let systemMessagesAllowed = true;
|
|
180
180
|
const isGemmaModel = options?.isGemmaModel ?? false;
|
|
181
181
|
const providerOptionsName = options?.providerOptionsName ?? 'google';
|
|
@@ -199,7 +199,7 @@ export function convertToGoogleGenerativeAIMessages(
|
|
|
199
199
|
case 'user': {
|
|
200
200
|
systemMessagesAllowed = false;
|
|
201
201
|
|
|
202
|
-
const parts:
|
|
202
|
+
const parts: GoogleContentPart[] = [];
|
|
203
203
|
|
|
204
204
|
for (const part of content) {
|
|
205
205
|
switch (part.type) {
|
|
@@ -418,7 +418,7 @@ export function convertToGoogleGenerativeAIMessages(
|
|
|
418
418
|
case 'tool': {
|
|
419
419
|
systemMessagesAllowed = false;
|
|
420
420
|
|
|
421
|
-
const parts:
|
|
421
|
+
const parts: GoogleContentPart[] = [];
|
|
422
422
|
|
|
423
423
|
for (const part of content) {
|
|
424
424
|
if (part.type === 'tool-approval-response') {
|
|
@@ -18,26 +18,26 @@ import {
|
|
|
18
18
|
import { z } from 'zod/v4';
|
|
19
19
|
import { googleFailedResponseHandler } from './google-error';
|
|
20
20
|
import {
|
|
21
|
-
|
|
21
|
+
GoogleEmbeddingModelId,
|
|
22
22
|
googleEmbeddingModelOptions,
|
|
23
|
-
} from './google-
|
|
23
|
+
} from './google-embedding-options';
|
|
24
24
|
|
|
25
|
-
type
|
|
25
|
+
type GoogleEmbeddingConfig = {
|
|
26
26
|
provider: string;
|
|
27
27
|
baseURL: string;
|
|
28
28
|
headers?: () => Record<string, string | undefined>;
|
|
29
29
|
fetch?: FetchFunction;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export class
|
|
32
|
+
export class GoogleEmbeddingModel implements EmbeddingModelV4 {
|
|
33
33
|
readonly specificationVersion = 'v4';
|
|
34
|
-
readonly modelId:
|
|
34
|
+
readonly modelId: GoogleEmbeddingModelId;
|
|
35
35
|
readonly maxEmbeddingsPerCall = 2048;
|
|
36
36
|
readonly supportsParallelCalls = true;
|
|
37
37
|
|
|
38
|
-
private readonly config:
|
|
38
|
+
private readonly config: GoogleEmbeddingConfig;
|
|
39
39
|
|
|
40
|
-
static [WORKFLOW_SERIALIZE](model:
|
|
40
|
+
static [WORKFLOW_SERIALIZE](model: GoogleEmbeddingModel) {
|
|
41
41
|
return serializeModelOptions({
|
|
42
42
|
modelId: model.modelId,
|
|
43
43
|
config: model.config,
|
|
@@ -46,21 +46,15 @@ export class GoogleGenerativeAIEmbeddingModel implements EmbeddingModelV4 {
|
|
|
46
46
|
|
|
47
47
|
static [WORKFLOW_DESERIALIZE](options: {
|
|
48
48
|
modelId: string;
|
|
49
|
-
config:
|
|
49
|
+
config: GoogleEmbeddingConfig;
|
|
50
50
|
}) {
|
|
51
|
-
return new
|
|
52
|
-
options.modelId,
|
|
53
|
-
options.config,
|
|
54
|
-
);
|
|
51
|
+
return new GoogleEmbeddingModel(options.modelId, options.config);
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
get provider(): string {
|
|
58
55
|
return this.config.provider;
|
|
59
56
|
}
|
|
60
|
-
constructor(
|
|
61
|
-
modelId: GoogleGenerativeAIEmbeddingModelId,
|
|
62
|
-
config: GoogleGenerativeAIEmbeddingConfig,
|
|
63
|
-
) {
|
|
57
|
+
constructor(modelId: GoogleEmbeddingModelId, config: GoogleEmbeddingConfig) {
|
|
64
58
|
this.modelId = modelId;
|
|
65
59
|
this.config = config;
|
|
66
60
|
}
|
|
@@ -26,21 +26,21 @@ export type GoogleFilesUploadOptions = {
|
|
|
26
26
|
[key: string]: unknown;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
interface
|
|
29
|
+
interface GoogleFilesConfig {
|
|
30
30
|
provider: string;
|
|
31
31
|
baseURL: string;
|
|
32
32
|
headers: () => Record<string, string | undefined>;
|
|
33
33
|
fetch?: FetchFunction;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export class
|
|
36
|
+
export class GoogleFiles implements FilesV4 {
|
|
37
37
|
readonly specificationVersion = 'v4';
|
|
38
38
|
|
|
39
39
|
get provider(): string {
|
|
40
40
|
return this.config.provider;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
constructor(private readonly config:
|
|
43
|
+
constructor(private readonly config: GoogleFilesConfig) {}
|
|
44
44
|
|
|
45
45
|
async uploadFile(
|
|
46
46
|
options: FilesV4UploadFileCallOptions,
|
|
@@ -23,13 +23,13 @@ import {
|
|
|
23
23
|
import { z } from 'zod/v4';
|
|
24
24
|
import { googleFailedResponseHandler } from './google-error';
|
|
25
25
|
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
} from './google-
|
|
29
|
-
import {
|
|
30
|
-
import type { GoogleLanguageModelOptions } from './google-
|
|
26
|
+
GoogleImageModelId,
|
|
27
|
+
GoogleImageSettings,
|
|
28
|
+
} from './google-image-settings';
|
|
29
|
+
import { GoogleLanguageModel } from './google-language-model';
|
|
30
|
+
import type { GoogleLanguageModelOptions } from './google-options';
|
|
31
31
|
|
|
32
|
-
interface
|
|
32
|
+
interface GoogleImageModelConfig {
|
|
33
33
|
provider: string;
|
|
34
34
|
baseURL: string;
|
|
35
35
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
@@ -40,10 +40,10 @@ interface GoogleGenerativeAIImageModelConfig {
|
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export class
|
|
43
|
+
export class GoogleImageModel implements ImageModelV4 {
|
|
44
44
|
readonly specificationVersion = 'v4';
|
|
45
45
|
|
|
46
|
-
static [WORKFLOW_SERIALIZE](model:
|
|
46
|
+
static [WORKFLOW_SERIALIZE](model: GoogleImageModel) {
|
|
47
47
|
return serializeModelOptions({
|
|
48
48
|
modelId: model.modelId,
|
|
49
49
|
config: model.config,
|
|
@@ -52,13 +52,9 @@ export class GoogleGenerativeAIImageModel implements ImageModelV4 {
|
|
|
52
52
|
|
|
53
53
|
static [WORKFLOW_DESERIALIZE](options: {
|
|
54
54
|
modelId: string;
|
|
55
|
-
config:
|
|
55
|
+
config: GoogleImageModelConfig;
|
|
56
56
|
}) {
|
|
57
|
-
return new
|
|
58
|
-
options.modelId,
|
|
59
|
-
{},
|
|
60
|
-
options.config,
|
|
61
|
-
);
|
|
57
|
+
return new GoogleImageModel(options.modelId, {}, options.config);
|
|
62
58
|
}
|
|
63
59
|
|
|
64
60
|
get maxImagesPerCall(): number {
|
|
@@ -78,9 +74,9 @@ export class GoogleGenerativeAIImageModel implements ImageModelV4 {
|
|
|
78
74
|
}
|
|
79
75
|
|
|
80
76
|
constructor(
|
|
81
|
-
readonly modelId:
|
|
82
|
-
private readonly settings:
|
|
83
|
-
private readonly config:
|
|
77
|
+
readonly modelId: GoogleImageModelId,
|
|
78
|
+
private readonly settings: GoogleImageSettings,
|
|
79
|
+
private readonly config: GoogleImageModelConfig,
|
|
84
80
|
) {}
|
|
85
81
|
|
|
86
82
|
async doGenerate(
|
|
@@ -113,14 +109,14 @@ export class GoogleGenerativeAIImageModel implements ImageModelV4 {
|
|
|
113
109
|
// Imagen API endpoints do not support image editing
|
|
114
110
|
if (files != null && files.length > 0) {
|
|
115
111
|
throw new Error(
|
|
116
|
-
'Google
|
|
112
|
+
'Google Gemini API does not support image editing with Imagen models. ' +
|
|
117
113
|
'Use Google Vertex AI (@ai-sdk/google-vertex) for image editing capabilities.',
|
|
118
114
|
);
|
|
119
115
|
}
|
|
120
116
|
|
|
121
117
|
if (mask != null) {
|
|
122
118
|
throw new Error(
|
|
123
|
-
'Google
|
|
119
|
+
'Google Gemini API does not support image editing with masks. ' +
|
|
124
120
|
'Use Google Vertex AI (@ai-sdk/google-vertex) for image editing capabilities.',
|
|
125
121
|
);
|
|
126
122
|
}
|
|
@@ -282,7 +278,7 @@ export class GoogleGenerativeAIImageModel implements ImageModelV4 {
|
|
|
282
278
|
];
|
|
283
279
|
|
|
284
280
|
// Instantiate language model
|
|
285
|
-
const languageModel = new
|
|
281
|
+
const languageModel = new GoogleLanguageModel(this.modelId, {
|
|
286
282
|
provider: this.config.provider,
|
|
287
283
|
baseURL: this.config.baseURL,
|
|
288
284
|
headers: this.config.headers ?? {},
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type GoogleImageModelId =
|
|
2
2
|
// Imagen models (use :predict API)
|
|
3
3
|
| 'imagen-4.0-generate-001'
|
|
4
4
|
| 'imagen-4.0-ultra-generate-001'
|
|
@@ -9,7 +9,7 @@ export type GoogleGenerativeAIImageModelId =
|
|
|
9
9
|
| 'gemini-3.1-flash-image-preview'
|
|
10
10
|
| (string & {});
|
|
11
11
|
|
|
12
|
-
export interface
|
|
12
|
+
export interface GoogleImageSettings {
|
|
13
13
|
/**
|
|
14
14
|
* Override the maximum number of images per call (default 4)
|
|
15
15
|
*/
|