@ai-sdk/google 4.0.0-beta.2 → 4.0.0-beta.20
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 +133 -4
- package/dist/index.d.mts +56 -22
- package/dist/index.d.ts +56 -22
- package/dist/index.js +500 -80
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +500 -77
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +34 -15
- package/dist/internal/index.d.ts +34 -15
- package/dist/internal/index.js +452 -67
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +452 -64
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +36 -3
- package/package.json +3 -5
- package/src/convert-google-generative-ai-usage.ts +2 -2
- package/src/convert-to-google-generative-ai-messages.ts +273 -34
- package/src/google-generative-ai-embedding-model.ts +42 -13
- package/src/google-generative-ai-embedding-options.ts +24 -0
- package/src/google-generative-ai-image-model.ts +14 -14
- package/src/google-generative-ai-language-model.ts +305 -44
- package/src/google-generative-ai-options.ts +11 -1
- package/src/google-generative-ai-prompt.ts +39 -3
- package/src/google-generative-ai-video-model.ts +7 -7
- package/src/google-prepare-tools.ts +63 -8
- package/src/google-provider.ts +18 -18
- package/src/map-google-generative-ai-finish-reason.ts +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
LanguageModelV4CallOptions,
|
|
3
|
+
SharedV4Warning,
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
|
|
@@ -11,8 +11,8 @@ export function prepareTools({
|
|
|
11
11
|
toolChoice,
|
|
12
12
|
modelId,
|
|
13
13
|
}: {
|
|
14
|
-
tools:
|
|
15
|
-
toolChoice?:
|
|
14
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
15
|
+
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
16
16
|
modelId: GoogleGenerativeAIModelId;
|
|
17
17
|
}): {
|
|
18
18
|
tools:
|
|
@@ -30,17 +30,18 @@ export function prepareTools({
|
|
|
30
30
|
toolConfig:
|
|
31
31
|
| undefined
|
|
32
32
|
| {
|
|
33
|
-
functionCallingConfig
|
|
33
|
+
functionCallingConfig?: {
|
|
34
34
|
mode: 'AUTO' | 'NONE' | 'ANY' | 'VALIDATED';
|
|
35
35
|
allowedFunctionNames?: string[];
|
|
36
36
|
};
|
|
37
|
+
includeServerSideToolInvocations?: boolean;
|
|
37
38
|
};
|
|
38
|
-
toolWarnings:
|
|
39
|
+
toolWarnings: SharedV4Warning[];
|
|
39
40
|
} {
|
|
40
41
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
41
42
|
tools = tools?.length ? tools : undefined;
|
|
42
43
|
|
|
43
|
-
const toolWarnings:
|
|
44
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
44
45
|
|
|
45
46
|
const isLatest = (
|
|
46
47
|
[
|
|
@@ -54,6 +55,7 @@ export function prepareTools({
|
|
|
54
55
|
modelId.includes('gemini-3') ||
|
|
55
56
|
modelId.includes('nano-banana') ||
|
|
56
57
|
isLatest;
|
|
58
|
+
const isGemini3orNewer = modelId.includes('gemini-3');
|
|
57
59
|
const supportsFileSearch =
|
|
58
60
|
modelId.includes('gemini-2.5') || modelId.includes('gemini-3');
|
|
59
61
|
|
|
@@ -65,7 +67,7 @@ export function prepareTools({
|
|
|
65
67
|
const hasFunctionTools = tools.some(tool => tool.type === 'function');
|
|
66
68
|
const hasProviderTools = tools.some(tool => tool.type === 'provider');
|
|
67
69
|
|
|
68
|
-
if (hasFunctionTools && hasProviderTools) {
|
|
70
|
+
if (hasFunctionTools && hasProviderTools && !isGemini3orNewer) {
|
|
69
71
|
toolWarnings.push({
|
|
70
72
|
type: 'unsupported',
|
|
71
73
|
feature: `combination of function and provider-defined tools`,
|
|
@@ -178,6 +180,59 @@ export function prepareTools({
|
|
|
178
180
|
}
|
|
179
181
|
});
|
|
180
182
|
|
|
183
|
+
if (hasFunctionTools && isGemini3orNewer && googleTools.length > 0) {
|
|
184
|
+
const functionDeclarations: Array<{
|
|
185
|
+
name: string;
|
|
186
|
+
description: string;
|
|
187
|
+
parameters: unknown;
|
|
188
|
+
}> = [];
|
|
189
|
+
for (const tool of tools) {
|
|
190
|
+
if (tool.type === 'function') {
|
|
191
|
+
functionDeclarations.push({
|
|
192
|
+
name: tool.name,
|
|
193
|
+
description: tool.description ?? '',
|
|
194
|
+
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const combinedToolConfig: {
|
|
200
|
+
functionCallingConfig: {
|
|
201
|
+
mode: 'VALIDATED' | 'ANY' | 'NONE';
|
|
202
|
+
allowedFunctionNames?: string[];
|
|
203
|
+
};
|
|
204
|
+
includeServerSideToolInvocations: true;
|
|
205
|
+
} = {
|
|
206
|
+
functionCallingConfig: { mode: 'VALIDATED' },
|
|
207
|
+
includeServerSideToolInvocations: true,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
if (toolChoice != null) {
|
|
211
|
+
switch (toolChoice.type) {
|
|
212
|
+
case 'auto':
|
|
213
|
+
break;
|
|
214
|
+
case 'none':
|
|
215
|
+
combinedToolConfig.functionCallingConfig = { mode: 'NONE' };
|
|
216
|
+
break;
|
|
217
|
+
case 'required':
|
|
218
|
+
combinedToolConfig.functionCallingConfig = { mode: 'ANY' };
|
|
219
|
+
break;
|
|
220
|
+
case 'tool':
|
|
221
|
+
combinedToolConfig.functionCallingConfig = {
|
|
222
|
+
mode: 'ANY',
|
|
223
|
+
allowedFunctionNames: [toolChoice.toolName],
|
|
224
|
+
};
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
tools: [...googleTools, { functionDeclarations }],
|
|
231
|
+
toolConfig: combinedToolConfig,
|
|
232
|
+
toolWarnings,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
181
236
|
return {
|
|
182
237
|
tools: googleTools.length > 0 ? googleTools : undefined,
|
|
183
238
|
toolConfig: undefined,
|
package/src/google-provider.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
EmbeddingModelV4,
|
|
3
|
+
Experimental_VideoModelV4,
|
|
4
|
+
ImageModelV4,
|
|
5
|
+
LanguageModelV4,
|
|
6
|
+
ProviderV4,
|
|
7
7
|
} from '@ai-sdk/provider';
|
|
8
8
|
import {
|
|
9
9
|
FetchFunction,
|
|
@@ -27,12 +27,12 @@ import { GoogleGenerativeAIImageModel } from './google-generative-ai-image-model
|
|
|
27
27
|
import { GoogleGenerativeAIVideoModel } from './google-generative-ai-video-model';
|
|
28
28
|
import { GoogleGenerativeAIVideoModelId } from './google-generative-ai-video-settings';
|
|
29
29
|
|
|
30
|
-
export interface GoogleGenerativeAIProvider extends
|
|
31
|
-
(modelId: GoogleGenerativeAIModelId):
|
|
30
|
+
export interface GoogleGenerativeAIProvider extends ProviderV4 {
|
|
31
|
+
(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
32
32
|
|
|
33
|
-
languageModel(modelId: GoogleGenerativeAIModelId):
|
|
33
|
+
languageModel(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
34
34
|
|
|
35
|
-
chat(modelId: GoogleGenerativeAIModelId):
|
|
35
|
+
chat(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
38
|
* Creates a model for image generation.
|
|
@@ -40,46 +40,46 @@ export interface GoogleGenerativeAIProvider extends ProviderV3 {
|
|
|
40
40
|
image(
|
|
41
41
|
modelId: GoogleGenerativeAIImageModelId,
|
|
42
42
|
settings?: GoogleGenerativeAIImageSettings,
|
|
43
|
-
):
|
|
43
|
+
): ImageModelV4;
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* @deprecated Use `chat()` instead.
|
|
47
47
|
*/
|
|
48
|
-
generativeAI(modelId: GoogleGenerativeAIModelId):
|
|
48
|
+
generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV4;
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Creates a model for text embeddings.
|
|
52
52
|
*/
|
|
53
|
-
embedding(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
53
|
+
embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Creates a model for text embeddings.
|
|
57
57
|
*/
|
|
58
|
-
embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
58
|
+
embeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
59
59
|
|
|
60
60
|
/**
|
|
61
61
|
* @deprecated Use `embedding` instead.
|
|
62
62
|
*/
|
|
63
|
-
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId):
|
|
63
|
+
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV4;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* @deprecated Use `embeddingModel` instead.
|
|
67
67
|
*/
|
|
68
68
|
textEmbeddingModel(
|
|
69
69
|
modelId: GoogleGenerativeAIEmbeddingModelId,
|
|
70
|
-
):
|
|
70
|
+
): EmbeddingModelV4;
|
|
71
71
|
|
|
72
72
|
/**
|
|
73
73
|
* Creates a model for video generation.
|
|
74
74
|
*/
|
|
75
|
-
video(modelId: GoogleGenerativeAIVideoModelId):
|
|
75
|
+
video(modelId: GoogleGenerativeAIVideoModelId): Experimental_VideoModelV4;
|
|
76
76
|
|
|
77
77
|
/**
|
|
78
78
|
* Creates a model for video generation.
|
|
79
79
|
*/
|
|
80
80
|
videoModel(
|
|
81
81
|
modelId: GoogleGenerativeAIVideoModelId,
|
|
82
|
-
):
|
|
82
|
+
): Experimental_VideoModelV4;
|
|
83
83
|
|
|
84
84
|
tools: typeof googleTools;
|
|
85
85
|
}
|
|
@@ -204,7 +204,7 @@ export function createGoogleGenerativeAI(
|
|
|
204
204
|
return createChatModel(modelId);
|
|
205
205
|
};
|
|
206
206
|
|
|
207
|
-
provider.specificationVersion = '
|
|
207
|
+
provider.specificationVersion = 'v4' as const;
|
|
208
208
|
provider.languageModel = createChatModel;
|
|
209
209
|
provider.chat = createChatModel;
|
|
210
210
|
provider.generativeAI = createChatModel;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export function mapGoogleGenerativeAIFinishReason({
|
|
4
4
|
finishReason,
|
|
@@ -6,7 +6,7 @@ export function mapGoogleGenerativeAIFinishReason({
|
|
|
6
6
|
}: {
|
|
7
7
|
finishReason: string | null | undefined;
|
|
8
8
|
hasToolCalls: boolean;
|
|
9
|
-
}):
|
|
9
|
+
}): LanguageModelV4FinishReason['unified'] {
|
|
10
10
|
switch (finishReason) {
|
|
11
11
|
case 'STOP':
|
|
12
12
|
return hasToolCalls ? 'tool-calls' : 'stop';
|