@ai-sdk/google 4.0.79 → 4.0.80
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 +6 -0
- package/README.md +1 -1
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +15 -1
- package/dist/internal/index.js.map +1 -1
- package/docs/15-google.mdx +11 -11
- package/package.json +1 -1
- package/src/convert-to-google-messages.ts +26 -1
package/docs/15-google.mdx
CHANGED
|
@@ -923,14 +923,14 @@ The `vertexRagStore` tool accepts the following configuration options:
|
|
|
923
923
|
|
|
924
924
|
### Image Outputs
|
|
925
925
|
|
|
926
|
-
Gemini models with image generation capabilities (e.g. `gemini-
|
|
926
|
+
Gemini models with image generation capabilities (e.g. `gemini-3.1-flash-image-preview`) support generating images as part of a multimodal response. Images are exposed as files in the response.
|
|
927
927
|
|
|
928
928
|
```ts
|
|
929
929
|
import { google } from '@ai-sdk/google';
|
|
930
930
|
import { generateText } from 'ai';
|
|
931
931
|
|
|
932
932
|
const result = await generateText({
|
|
933
|
-
model: google('gemini-
|
|
933
|
+
model: google('gemini-3.1-flash-image-preview'),
|
|
934
934
|
prompt:
|
|
935
935
|
'Create a picture of a nano banana dish in a fancy restaurant with a Gemini theme',
|
|
936
936
|
});
|
|
@@ -1088,7 +1088,7 @@ You can pass a `webhookUrl` to receive a notification when the batch reaches a t
|
|
|
1088
1088
|
import { google } from '@ai-sdk/google';
|
|
1089
1089
|
import { experimental_startBatch as startBatch } from 'ai';
|
|
1090
1090
|
|
|
1091
|
-
const model = 'gemini-3.
|
|
1091
|
+
const model = 'gemini-3.8-flash';
|
|
1092
1092
|
|
|
1093
1093
|
const batch = await startBatch({
|
|
1094
1094
|
provider: google,
|
|
@@ -1578,7 +1578,7 @@ import { google, type GoogleInteractionsVideoOptions } from '@ai-sdk/google';
|
|
|
1578
1578
|
import { generateText } from 'ai';
|
|
1579
1579
|
|
|
1580
1580
|
const result = await generateText({
|
|
1581
|
-
model: google.interactions('gemini-3.
|
|
1581
|
+
model: google.interactions('gemini-3.8-flash'),
|
|
1582
1582
|
messages: [
|
|
1583
1583
|
{
|
|
1584
1584
|
role: 'user',
|
|
@@ -1778,7 +1778,7 @@ import {
|
|
|
1778
1778
|
import { generateText } from 'ai';
|
|
1779
1779
|
|
|
1780
1780
|
const result = await generateText({
|
|
1781
|
-
model: google.interactions('gemini-
|
|
1781
|
+
model: google.interactions('gemini-3.1-flash-image-preview'),
|
|
1782
1782
|
prompt:
|
|
1783
1783
|
'Tell me a three sentence bedtime story about a unicorn, accompanied by a suitable illustration.',
|
|
1784
1784
|
providerOptions: {
|
|
@@ -2042,7 +2042,7 @@ You can create models that call the [Google Generative AI embeddings API](https:
|
|
|
2042
2042
|
using the `.embedding()` factory method.
|
|
2043
2043
|
|
|
2044
2044
|
```ts
|
|
2045
|
-
const model = google.embedding('gemini-embedding-
|
|
2045
|
+
const model = google.embedding('gemini-embedding-2');
|
|
2046
2046
|
```
|
|
2047
2047
|
|
|
2048
2048
|
The Google provider sends API calls to the right endpoint based on the type of embedding:
|
|
@@ -2078,7 +2078,7 @@ import { google, type GoogleEmbeddingModelOptions } from '@ai-sdk/google';
|
|
|
2078
2078
|
import { embedMany } from 'ai';
|
|
2079
2079
|
|
|
2080
2080
|
const { embeddings } = await embedMany({
|
|
2081
|
-
model: google.embedding('gemini-embedding-2
|
|
2081
|
+
model: google.embedding('gemini-embedding-2'),
|
|
2082
2082
|
values: ['sunny day at the beach', 'rainy afternoon in the city'],
|
|
2083
2083
|
providerOptions: {
|
|
2084
2084
|
google: {
|
|
@@ -2132,14 +2132,14 @@ output capabilities through the `:generateContent` API.
|
|
|
2132
2132
|
|
|
2133
2133
|
### Gemini Image Models
|
|
2134
2134
|
|
|
2135
|
-
[Gemini image models](https://ai.google.dev/gemini-api/docs/image-generation) (e.g. `gemini-
|
|
2135
|
+
[Gemini image models](https://ai.google.dev/gemini-api/docs/image-generation) (e.g. `gemini-3.1-flash-image-preview`) are technically multimodal output language models, but they can be used with the `generateImage()` function for a simpler image generation experience. Internally, the provider calls the language model API with `responseModalities: ['IMAGE']`.
|
|
2136
2136
|
|
|
2137
2137
|
```ts
|
|
2138
2138
|
import { google } from '@ai-sdk/google';
|
|
2139
2139
|
import { generateImage } from 'ai';
|
|
2140
2140
|
|
|
2141
2141
|
const { image } = await generateImage({
|
|
2142
|
-
model: google.image('gemini-
|
|
2142
|
+
model: google.image('gemini-3.1-flash-image-preview'),
|
|
2143
2143
|
prompt: 'A photorealistic image of a cat wearing a wizard hat',
|
|
2144
2144
|
aspectRatio: '1:1',
|
|
2145
2145
|
});
|
|
@@ -2155,7 +2155,7 @@ import fs from 'node:fs';
|
|
|
2155
2155
|
const sourceImage = fs.readFileSync('./cat.png');
|
|
2156
2156
|
|
|
2157
2157
|
const { image } = await generateImage({
|
|
2158
|
-
model: google.image('gemini-
|
|
2158
|
+
model: google.image('gemini-3.1-flash-image-preview'),
|
|
2159
2159
|
prompt: {
|
|
2160
2160
|
text: 'Add a small wizard hat to this cat',
|
|
2161
2161
|
images: [sourceImage],
|
|
@@ -2170,7 +2170,7 @@ import { google } from '@ai-sdk/google';
|
|
|
2170
2170
|
import { generateImage } from 'ai';
|
|
2171
2171
|
|
|
2172
2172
|
const { image } = await generateImage({
|
|
2173
|
-
model: google.image('gemini-
|
|
2173
|
+
model: google.image('gemini-3.1-flash-image-preview'),
|
|
2174
2174
|
prompt: {
|
|
2175
2175
|
text: 'Add a small wizard hat to this cat',
|
|
2176
2176
|
images: ['https://example.com/cat.png'],
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
UnsupportedFunctionalityError,
|
|
3
|
+
type JSONValue,
|
|
3
4
|
type LanguageModelV4Prompt,
|
|
4
5
|
type LanguageModelV4ToolResultOutput,
|
|
5
6
|
type SharedV4Warning,
|
|
@@ -67,6 +68,30 @@ function convertUrlToolResultPart(
|
|
|
67
68
|
};
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
function containsJSONSchemaReference(value: JSONValue | undefined): boolean {
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
return value.some(containsJSONSchemaReference);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (typeof value !== 'object' || value === null) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return Object.entries(value).some(
|
|
81
|
+
([key, nestedValue]) =>
|
|
82
|
+
key === '$ref' || containsJSONSchemaReference(nestedValue),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function serializeFunctionResponseContent(
|
|
87
|
+
value: JSONValue,
|
|
88
|
+
): JSONValue | string {
|
|
89
|
+
// Google reserves { $ref: displayName } in structured function responses for
|
|
90
|
+
// multimodal parts. This conflicts with JSON Schema $ref, so serialize the
|
|
91
|
+
// result to preserve it without triggering Google's reference handling.
|
|
92
|
+
return containsJSONSchemaReference(value) ? JSON.stringify(value) : value;
|
|
93
|
+
}
|
|
94
|
+
|
|
70
95
|
/*
|
|
71
96
|
* Appends tool result content parts to the message using the functionResponse
|
|
72
97
|
* format with support for multimodal parts (e.g. inline images/files alongside
|
|
@@ -654,7 +679,7 @@ export function convertToGoogleMessages(
|
|
|
654
679
|
content:
|
|
655
680
|
output.type === 'execution-denied'
|
|
656
681
|
? (output.reason ?? 'Tool call execution denied.')
|
|
657
|
-
: output.value,
|
|
682
|
+
: serializeFunctionResponseContent(output.value),
|
|
658
683
|
},
|
|
659
684
|
},
|
|
660
685
|
});
|