@ai-sdk/google 4.0.0-beta.0 → 4.0.0-beta.10
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 +63 -0
- package/dist/index.d.mts +31 -14
- package/dist/index.d.ts +31 -14
- package/dist/index.js +100 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +97 -32
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +11 -7
- package/dist/internal/index.d.ts +11 -7
- package/dist/internal/index.js +52 -22
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +49 -19
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +30 -3
- package/package.json +3 -3
- package/src/convert-google-generative-ai-usage.ts +2 -2
- package/src/convert-to-google-generative-ai-messages.ts +5 -2
- 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 +83 -54
- package/src/google-generative-ai-prompt.ts +9 -0
- package/src/google-generative-ai-video-model.ts +7 -7
- package/src/google-prepare-tools.ts +25 -11
- 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:
|
|
@@ -31,16 +31,16 @@ export function prepareTools({
|
|
|
31
31
|
| undefined
|
|
32
32
|
| {
|
|
33
33
|
functionCallingConfig: {
|
|
34
|
-
mode: 'AUTO' | 'NONE' | 'ANY';
|
|
34
|
+
mode: 'AUTO' | 'NONE' | 'ANY' | 'VALIDATED';
|
|
35
35
|
allowedFunctionNames?: string[];
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
|
-
toolWarnings:
|
|
38
|
+
toolWarnings: SharedV4Warning[];
|
|
39
39
|
} {
|
|
40
40
|
// when the tools array is empty, change it to undefined to prevent errors:
|
|
41
41
|
tools = tools?.length ? tools : undefined;
|
|
42
42
|
|
|
43
|
-
const toolWarnings:
|
|
43
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
44
44
|
|
|
45
45
|
const isLatest = (
|
|
46
46
|
[
|
|
@@ -186,6 +186,7 @@ export function prepareTools({
|
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
const functionDeclarations = [];
|
|
189
|
+
let hasStrictTools = false;
|
|
189
190
|
for (const tool of tools) {
|
|
190
191
|
switch (tool.type) {
|
|
191
192
|
case 'function':
|
|
@@ -194,6 +195,9 @@ export function prepareTools({
|
|
|
194
195
|
description: tool.description ?? '',
|
|
195
196
|
parameters: convertJSONSchemaToOpenAPISchema(tool.inputSchema),
|
|
196
197
|
});
|
|
198
|
+
if (tool.strict === true) {
|
|
199
|
+
hasStrictTools = true;
|
|
200
|
+
}
|
|
197
201
|
break;
|
|
198
202
|
default:
|
|
199
203
|
toolWarnings.push({
|
|
@@ -207,7 +211,9 @@ export function prepareTools({
|
|
|
207
211
|
if (toolChoice == null) {
|
|
208
212
|
return {
|
|
209
213
|
tools: [{ functionDeclarations }],
|
|
210
|
-
toolConfig:
|
|
214
|
+
toolConfig: hasStrictTools
|
|
215
|
+
? { functionCallingConfig: { mode: 'VALIDATED' } }
|
|
216
|
+
: undefined,
|
|
211
217
|
toolWarnings,
|
|
212
218
|
};
|
|
213
219
|
}
|
|
@@ -218,7 +224,11 @@ export function prepareTools({
|
|
|
218
224
|
case 'auto':
|
|
219
225
|
return {
|
|
220
226
|
tools: [{ functionDeclarations }],
|
|
221
|
-
toolConfig: {
|
|
227
|
+
toolConfig: {
|
|
228
|
+
functionCallingConfig: {
|
|
229
|
+
mode: hasStrictTools ? 'VALIDATED' : 'AUTO',
|
|
230
|
+
},
|
|
231
|
+
},
|
|
222
232
|
toolWarnings,
|
|
223
233
|
};
|
|
224
234
|
case 'none':
|
|
@@ -230,7 +240,11 @@ export function prepareTools({
|
|
|
230
240
|
case 'required':
|
|
231
241
|
return {
|
|
232
242
|
tools: [{ functionDeclarations }],
|
|
233
|
-
toolConfig: {
|
|
243
|
+
toolConfig: {
|
|
244
|
+
functionCallingConfig: {
|
|
245
|
+
mode: hasStrictTools ? 'VALIDATED' : 'ANY',
|
|
246
|
+
},
|
|
247
|
+
},
|
|
234
248
|
toolWarnings,
|
|
235
249
|
};
|
|
236
250
|
case 'tool':
|
|
@@ -238,7 +252,7 @@ export function prepareTools({
|
|
|
238
252
|
tools: [{ functionDeclarations }],
|
|
239
253
|
toolConfig: {
|
|
240
254
|
functionCallingConfig: {
|
|
241
|
-
mode: 'ANY',
|
|
255
|
+
mode: hasStrictTools ? 'VALIDATED' : 'ANY',
|
|
242
256
|
allowedFunctionNames: [toolChoice.toolName],
|
|
243
257
|
},
|
|
244
258
|
},
|
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';
|