@ai-sdk/google 4.0.0-beta.44 → 4.0.0-beta.46
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 +25 -0
- package/README.md +4 -4
- package/dist/index.d.ts +40 -40
- package/dist/index.js +102 -108
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +16 -16
- package/dist/internal/index.js +62 -62
- package/dist/internal/index.js.map +1 -1
- package/docs/{15-google-generative-ai.mdx → 15-google.mdx} +36 -36
- package/package.json +7 -6
- 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} +15 -15
- 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} +29 -34
- package/src/{google-generative-ai-options.ts → google-options.ts} +2 -2
- package/src/google-prepare-tools.ts +9 -5
- 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/tool/code-execution.ts +2 -2
- package/src/tool/enterprise-web-search.ts +9 -3
- package/src/tool/file-search.ts +5 -7
- package/src/tool/google-maps.ts +3 -2
- package/src/tool/google-search.ts +10 -11
- package/src/tool/url-context.ts +4 -2
- package/src/tool/vertex-rag-store.ts +9 -6
- package/src/google-generative-ai-prompt.ts +0 -82
|
@@ -34,24 +34,24 @@ import {
|
|
|
34
34
|
} from '@ai-sdk/provider-utils';
|
|
35
35
|
import { z } from 'zod/v4';
|
|
36
36
|
import {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} from './convert-google-
|
|
37
|
+
convertGoogleUsage,
|
|
38
|
+
GoogleUsageMetadata,
|
|
39
|
+
} from './convert-google-usage';
|
|
40
40
|
import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
|
|
41
|
-
import {
|
|
41
|
+
import { convertToGoogleMessages } from './convert-to-google-messages';
|
|
42
42
|
import { getModelPath } from './get-model-path';
|
|
43
43
|
import { googleFailedResponseHandler } from './google-error';
|
|
44
44
|
import {
|
|
45
|
-
|
|
45
|
+
GoogleModelId,
|
|
46
46
|
googleLanguageModelOptions,
|
|
47
47
|
VertexServiceTierMap,
|
|
48
|
-
} from './google-
|
|
49
|
-
import {
|
|
48
|
+
} from './google-options';
|
|
49
|
+
import { GoogleProviderMetadata } from './google-prompt';
|
|
50
50
|
import { prepareTools } from './google-prepare-tools';
|
|
51
51
|
import { GoogleJSONAccumulator, PartialArg } from './google-json-accumulator';
|
|
52
|
-
import {
|
|
52
|
+
import { mapGoogleFinishReason } from './map-google-finish-reason';
|
|
53
53
|
|
|
54
|
-
type
|
|
54
|
+
type GoogleConfig = {
|
|
55
55
|
provider: string;
|
|
56
56
|
baseURL: string;
|
|
57
57
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
@@ -64,15 +64,15 @@ type GoogleGenerativeAIConfig = {
|
|
|
64
64
|
supportedUrls?: () => LanguageModelV4['supportedUrls'];
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
export class
|
|
67
|
+
export class GoogleLanguageModel implements LanguageModelV4 {
|
|
68
68
|
readonly specificationVersion = 'v4';
|
|
69
69
|
|
|
70
|
-
readonly modelId:
|
|
70
|
+
readonly modelId: GoogleModelId;
|
|
71
71
|
|
|
72
|
-
private readonly config:
|
|
72
|
+
private readonly config: GoogleConfig;
|
|
73
73
|
private readonly generateId: () => string;
|
|
74
74
|
|
|
75
|
-
static [WORKFLOW_SERIALIZE](model:
|
|
75
|
+
static [WORKFLOW_SERIALIZE](model: GoogleLanguageModel) {
|
|
76
76
|
return serializeModelOptions({
|
|
77
77
|
modelId: model.modelId,
|
|
78
78
|
config: model.config,
|
|
@@ -81,15 +81,12 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
81
81
|
|
|
82
82
|
static [WORKFLOW_DESERIALIZE](options: {
|
|
83
83
|
modelId: string;
|
|
84
|
-
config:
|
|
84
|
+
config: GoogleConfig;
|
|
85
85
|
}) {
|
|
86
|
-
return new
|
|
86
|
+
return new GoogleLanguageModel(options.modelId, options.config);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
constructor(
|
|
90
|
-
modelId: GoogleGenerativeAIModelId,
|
|
91
|
-
config: GoogleGenerativeAIConfig,
|
|
92
|
-
) {
|
|
89
|
+
constructor(modelId: GoogleModelId, config: GoogleConfig) {
|
|
93
90
|
this.modelId = modelId;
|
|
94
91
|
this.config = config;
|
|
95
92
|
this.generateId = config.generateId ?? generateId;
|
|
@@ -179,14 +176,11 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
179
176
|
const isGemmaModel = this.modelId.toLowerCase().startsWith('gemma-');
|
|
180
177
|
const supportsFunctionResponseParts = this.modelId.startsWith('gemini-3');
|
|
181
178
|
|
|
182
|
-
const { contents, systemInstruction } =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
supportsFunctionResponseParts,
|
|
188
|
-
},
|
|
189
|
-
);
|
|
179
|
+
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
180
|
+
isGemmaModel,
|
|
181
|
+
providerOptionsName,
|
|
182
|
+
supportsFunctionResponseParts,
|
|
183
|
+
});
|
|
190
184
|
|
|
191
185
|
const {
|
|
192
186
|
tools: googleTools,
|
|
@@ -196,6 +190,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
196
190
|
tools,
|
|
197
191
|
toolChoice,
|
|
198
192
|
modelId: this.modelId,
|
|
193
|
+
isVertexProvider,
|
|
199
194
|
});
|
|
200
195
|
|
|
201
196
|
const resolvedThinking = resolveThinkingConfig({
|
|
@@ -469,7 +464,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
469
464
|
return {
|
|
470
465
|
content,
|
|
471
466
|
finishReason: {
|
|
472
|
-
unified:
|
|
467
|
+
unified: mapGoogleFinishReason({
|
|
473
468
|
finishReason: candidate.finishReason,
|
|
474
469
|
// Only count client-executed tool calls for finish reason determination.
|
|
475
470
|
hasToolCalls: content.some(
|
|
@@ -478,7 +473,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
478
473
|
}),
|
|
479
474
|
raw: candidate.finishReason ?? undefined,
|
|
480
475
|
},
|
|
481
|
-
usage:
|
|
476
|
+
usage: convertGoogleUsage(usageMetadata),
|
|
482
477
|
warnings,
|
|
483
478
|
providerMetadata: {
|
|
484
479
|
[providerOptionsName]: {
|
|
@@ -489,7 +484,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
489
484
|
usageMetadata: usageMetadata ?? null,
|
|
490
485
|
finishMessage: candidate.finishMessage ?? null,
|
|
491
486
|
serviceTier: response.serviceTier ?? null,
|
|
492
|
-
} satisfies
|
|
487
|
+
} satisfies GoogleProviderMetadata,
|
|
493
488
|
},
|
|
494
489
|
request: { body: args },
|
|
495
490
|
response: {
|
|
@@ -529,7 +524,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
529
524
|
unified: 'other',
|
|
530
525
|
raw: undefined,
|
|
531
526
|
};
|
|
532
|
-
let usage:
|
|
527
|
+
let usage: GoogleUsageMetadata | undefined = undefined;
|
|
533
528
|
let providerMetadata: SharedV4ProviderMetadata | undefined = undefined;
|
|
534
529
|
let lastGroundingMetadata: GroundingMetadataSchema | null = null;
|
|
535
530
|
let lastUrlContextMetadata: UrlContextMetadataSchema | null = null;
|
|
@@ -965,7 +960,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
965
960
|
|
|
966
961
|
if (candidate.finishReason != null) {
|
|
967
962
|
finishReason = {
|
|
968
|
-
unified:
|
|
963
|
+
unified: mapGoogleFinishReason({
|
|
969
964
|
finishReason: candidate.finishReason,
|
|
970
965
|
hasToolCalls,
|
|
971
966
|
}),
|
|
@@ -981,7 +976,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
981
976
|
usageMetadata: usageMetadata ?? null,
|
|
982
977
|
finishMessage: candidate.finishMessage ?? null,
|
|
983
978
|
serviceTier,
|
|
984
|
-
} satisfies
|
|
979
|
+
} satisfies GoogleProviderMetadata,
|
|
985
980
|
};
|
|
986
981
|
}
|
|
987
982
|
},
|
|
@@ -1003,7 +998,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV4 {
|
|
|
1003
998
|
controller.enqueue({
|
|
1004
999
|
type: 'finish',
|
|
1005
1000
|
finishReason,
|
|
1006
|
-
usage:
|
|
1001
|
+
usage: convertGoogleUsage(usage),
|
|
1007
1002
|
providerMetadata,
|
|
1008
1003
|
});
|
|
1009
1004
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
|
|
4
|
-
export type
|
|
4
|
+
export type GoogleModelId =
|
|
5
5
|
// Stable models
|
|
6
6
|
// https://ai.google.dev/gemini-api/docs/models/gemini
|
|
7
7
|
| 'gemini-2.0-flash'
|
|
@@ -73,7 +73,7 @@ export const googleLanguageModelOptions = lazySchema(() =>
|
|
|
73
73
|
*
|
|
74
74
|
* This is useful when the JSON Schema contains elements that are
|
|
75
75
|
* not supported by the OpenAPI schema version that
|
|
76
|
-
* Google
|
|
76
|
+
* Google uses. You can use this to disable
|
|
77
77
|
* structured outputs if you need to.
|
|
78
78
|
*/
|
|
79
79
|
structuredOutputs: z.boolean().optional(),
|
|
@@ -4,16 +4,18 @@ import {
|
|
|
4
4
|
UnsupportedFunctionalityError,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import { convertJSONSchemaToOpenAPISchema } from './convert-json-schema-to-openapi-schema';
|
|
7
|
-
import {
|
|
7
|
+
import { GoogleModelId } from './google-options';
|
|
8
8
|
|
|
9
9
|
export function prepareTools({
|
|
10
10
|
tools,
|
|
11
11
|
toolChoice,
|
|
12
12
|
modelId,
|
|
13
|
+
isVertexProvider = false,
|
|
13
14
|
}: {
|
|
14
15
|
tools: LanguageModelV4CallOptions['tools'];
|
|
15
16
|
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
16
|
-
modelId:
|
|
17
|
+
modelId: GoogleModelId;
|
|
18
|
+
isVertexProvider?: boolean;
|
|
17
19
|
}): {
|
|
18
20
|
tools:
|
|
19
21
|
| Array<
|
|
@@ -49,7 +51,7 @@ export function prepareTools({
|
|
|
49
51
|
'gemini-flash-latest',
|
|
50
52
|
'gemini-flash-lite-latest',
|
|
51
53
|
'gemini-pro-latest',
|
|
52
|
-
] as const satisfies
|
|
54
|
+
] as const satisfies GoogleModelId[]
|
|
53
55
|
).some(id => id === modelId);
|
|
54
56
|
const isGemini2orNewer =
|
|
55
57
|
modelId.includes('gemini-2') ||
|
|
@@ -202,10 +204,12 @@ export function prepareTools({
|
|
|
202
204
|
mode: 'VALIDATED' | 'ANY' | 'NONE';
|
|
203
205
|
allowedFunctionNames?: string[];
|
|
204
206
|
};
|
|
205
|
-
includeServerSideToolInvocations
|
|
207
|
+
includeServerSideToolInvocations?: true;
|
|
206
208
|
} = {
|
|
207
209
|
functionCallingConfig: { mode: 'VALIDATED' },
|
|
208
|
-
|
|
210
|
+
...(!isVertexProvider && {
|
|
211
|
+
includeServerSideToolInvocations: true,
|
|
212
|
+
}),
|
|
209
213
|
};
|
|
210
214
|
|
|
211
215
|
if (toolChoice != null) {
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GroundingMetadataSchema,
|
|
3
|
+
PromptFeedbackSchema,
|
|
4
|
+
UrlContextMetadataSchema,
|
|
5
|
+
type SafetyRatingSchema,
|
|
6
|
+
UsageMetadataSchema,
|
|
7
|
+
} from './google-language-model';
|
|
8
|
+
|
|
9
|
+
export type GooglePrompt = {
|
|
10
|
+
systemInstruction?: GoogleSystemInstruction;
|
|
11
|
+
contents: Array<GoogleContent>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type GoogleSystemInstruction = {
|
|
15
|
+
parts: Array<{ text: string }>;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type GoogleContent = {
|
|
19
|
+
role: 'user' | 'model';
|
|
20
|
+
parts: Array<GoogleContentPart>;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type GoogleContentPart =
|
|
24
|
+
| { text: string; thought?: boolean; thoughtSignature?: string }
|
|
25
|
+
| {
|
|
26
|
+
inlineData: { mimeType: string; data: string };
|
|
27
|
+
thought?: boolean;
|
|
28
|
+
thoughtSignature?: string;
|
|
29
|
+
}
|
|
30
|
+
| { functionCall: { name: string; args: unknown }; thoughtSignature?: string }
|
|
31
|
+
| {
|
|
32
|
+
functionResponse: {
|
|
33
|
+
name: string;
|
|
34
|
+
response: unknown;
|
|
35
|
+
parts?: Array<GoogleFunctionResponsePart>;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
fileData: { mimeType: string; fileUri: string };
|
|
40
|
+
thought?: boolean;
|
|
41
|
+
thoughtSignature?: string;
|
|
42
|
+
}
|
|
43
|
+
| {
|
|
44
|
+
toolCall: {
|
|
45
|
+
toolType: string;
|
|
46
|
+
args?: unknown;
|
|
47
|
+
id: string;
|
|
48
|
+
};
|
|
49
|
+
thoughtSignature?: string;
|
|
50
|
+
}
|
|
51
|
+
| {
|
|
52
|
+
toolResponse: {
|
|
53
|
+
toolType: string;
|
|
54
|
+
response?: unknown;
|
|
55
|
+
id: string;
|
|
56
|
+
};
|
|
57
|
+
thoughtSignature?: string;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type GoogleFunctionResponsePart = {
|
|
61
|
+
inlineData: { mimeType: string; data: string };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type GoogleGroundingMetadata = GroundingMetadataSchema;
|
|
65
|
+
|
|
66
|
+
export type GoogleUrlContextMetadata = UrlContextMetadataSchema;
|
|
67
|
+
|
|
68
|
+
export type GoogleSafetyRating = SafetyRatingSchema;
|
|
69
|
+
|
|
70
|
+
export type GooglePromptFeedback = PromptFeedbackSchema;
|
|
71
|
+
|
|
72
|
+
export type GoogleUsageMetadata = UsageMetadataSchema;
|
|
73
|
+
|
|
74
|
+
export interface GoogleProviderMetadata {
|
|
75
|
+
promptFeedback: GooglePromptFeedback | null;
|
|
76
|
+
groundingMetadata: GoogleGroundingMetadata | null;
|
|
77
|
+
urlContextMetadata: GoogleUrlContextMetadata | null;
|
|
78
|
+
safetyRatings: GoogleSafetyRating[] | null;
|
|
79
|
+
usageMetadata: GoogleUsageMetadata | null;
|
|
80
|
+
finishMessage: string | null;
|
|
81
|
+
serviceTier: string | null;
|
|
82
|
+
}
|
package/src/google-provider.ts
CHANGED
|
@@ -14,81 +14,77 @@ import {
|
|
|
14
14
|
withUserAgentSuffix,
|
|
15
15
|
} from '@ai-sdk/provider-utils';
|
|
16
16
|
import { VERSION } from './version';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
17
|
+
import { GoogleEmbeddingModel } from './google-embedding-model';
|
|
18
|
+
import { GoogleEmbeddingModelId } from './google-embedding-options';
|
|
19
|
+
import { GoogleLanguageModel } from './google-language-model';
|
|
20
|
+
import { GoogleModelId } from './google-options';
|
|
21
21
|
import { googleTools } from './google-tools';
|
|
22
22
|
|
|
23
23
|
import {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
} from './google-
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
29
|
-
import {
|
|
30
|
-
import {
|
|
24
|
+
GoogleImageSettings,
|
|
25
|
+
GoogleImageModelId,
|
|
26
|
+
} from './google-image-settings';
|
|
27
|
+
import { GoogleImageModel } from './google-image-model';
|
|
28
|
+
import { GoogleFiles } from './google-files';
|
|
29
|
+
import { GoogleVideoModel } from './google-video-model';
|
|
30
|
+
import { GoogleVideoModelId } from './google-video-settings';
|
|
31
31
|
|
|
32
|
-
export interface
|
|
33
|
-
(modelId:
|
|
32
|
+
export interface GoogleProvider extends ProviderV4 {
|
|
33
|
+
(modelId: GoogleModelId): LanguageModelV4;
|
|
34
34
|
|
|
35
|
-
languageModel(modelId:
|
|
35
|
+
languageModel(modelId: GoogleModelId): LanguageModelV4;
|
|
36
36
|
|
|
37
|
-
chat(modelId:
|
|
37
|
+
chat(modelId: GoogleModelId): LanguageModelV4;
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Creates a model for image generation.
|
|
41
41
|
*/
|
|
42
42
|
image(
|
|
43
|
-
modelId:
|
|
44
|
-
settings?:
|
|
43
|
+
modelId: GoogleImageModelId,
|
|
44
|
+
settings?: GoogleImageSettings,
|
|
45
45
|
): ImageModelV4;
|
|
46
46
|
|
|
47
47
|
/**
|
|
48
48
|
* @deprecated Use `chat()` instead.
|
|
49
49
|
*/
|
|
50
|
-
generativeAI(modelId:
|
|
50
|
+
generativeAI(modelId: GoogleModelId): LanguageModelV4;
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Creates a model for text embeddings.
|
|
54
54
|
*/
|
|
55
|
-
embedding(modelId:
|
|
55
|
+
embedding(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* Creates a model for text embeddings.
|
|
59
59
|
*/
|
|
60
|
-
embeddingModel(modelId:
|
|
60
|
+
embeddingModel(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* @deprecated Use `embedding` instead.
|
|
64
64
|
*/
|
|
65
|
-
textEmbedding(modelId:
|
|
65
|
+
textEmbedding(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* @deprecated Use `embeddingModel` instead.
|
|
69
69
|
*/
|
|
70
|
-
textEmbeddingModel(
|
|
71
|
-
modelId: GoogleGenerativeAIEmbeddingModelId,
|
|
72
|
-
): EmbeddingModelV4;
|
|
70
|
+
textEmbeddingModel(modelId: GoogleEmbeddingModelId): EmbeddingModelV4;
|
|
73
71
|
|
|
74
72
|
/**
|
|
75
73
|
* Creates a model for video generation.
|
|
76
74
|
*/
|
|
77
|
-
video(modelId:
|
|
75
|
+
video(modelId: GoogleVideoModelId): Experimental_VideoModelV4;
|
|
78
76
|
|
|
79
77
|
/**
|
|
80
78
|
* Creates a model for video generation.
|
|
81
79
|
*/
|
|
82
|
-
videoModel(
|
|
83
|
-
modelId: GoogleGenerativeAIVideoModelId,
|
|
84
|
-
): Experimental_VideoModelV4;
|
|
80
|
+
videoModel(modelId: GoogleVideoModelId): Experimental_VideoModelV4;
|
|
85
81
|
|
|
86
82
|
files(): FilesV4;
|
|
87
83
|
|
|
88
84
|
tools: typeof googleTools;
|
|
89
85
|
}
|
|
90
86
|
|
|
91
|
-
export interface
|
|
87
|
+
export interface GoogleProviderSettings {
|
|
92
88
|
/**
|
|
93
89
|
* Use a different URL prefix for API calls, e.g. to use proxy servers.
|
|
94
90
|
* The default prefix is `https://generativelanguage.googleapis.com/v1beta`.
|
|
@@ -125,11 +121,11 @@ export interface GoogleGenerativeAIProviderSettings {
|
|
|
125
121
|
}
|
|
126
122
|
|
|
127
123
|
/**
|
|
128
|
-
* Create a Google
|
|
124
|
+
* Create a Google provider instance.
|
|
129
125
|
*/
|
|
130
|
-
export function
|
|
131
|
-
options:
|
|
132
|
-
):
|
|
126
|
+
export function createGoogle(
|
|
127
|
+
options: GoogleProviderSettings = {},
|
|
128
|
+
): GoogleProvider {
|
|
133
129
|
const baseURL =
|
|
134
130
|
withoutTrailingSlash(options.baseURL) ??
|
|
135
131
|
'https://generativelanguage.googleapis.com/v1beta';
|
|
@@ -149,8 +145,8 @@ export function createGoogleGenerativeAI(
|
|
|
149
145
|
`ai-sdk/google/${VERSION}`,
|
|
150
146
|
);
|
|
151
147
|
|
|
152
|
-
const createChatModel = (modelId:
|
|
153
|
-
new
|
|
148
|
+
const createChatModel = (modelId: GoogleModelId) =>
|
|
149
|
+
new GoogleLanguageModel(modelId, {
|
|
154
150
|
provider: providerName,
|
|
155
151
|
baseURL,
|
|
156
152
|
headers: getHeaders,
|
|
@@ -170,8 +166,8 @@ export function createGoogleGenerativeAI(
|
|
|
170
166
|
fetch: options.fetch,
|
|
171
167
|
});
|
|
172
168
|
|
|
173
|
-
const createEmbeddingModel = (modelId:
|
|
174
|
-
new
|
|
169
|
+
const createEmbeddingModel = (modelId: GoogleEmbeddingModelId) =>
|
|
170
|
+
new GoogleEmbeddingModel(modelId, {
|
|
175
171
|
provider: providerName,
|
|
176
172
|
baseURL,
|
|
177
173
|
headers: getHeaders,
|
|
@@ -179,10 +175,10 @@ export function createGoogleGenerativeAI(
|
|
|
179
175
|
});
|
|
180
176
|
|
|
181
177
|
const createImageModel = (
|
|
182
|
-
modelId:
|
|
183
|
-
settings:
|
|
178
|
+
modelId: GoogleImageModelId,
|
|
179
|
+
settings: GoogleImageSettings = {},
|
|
184
180
|
) =>
|
|
185
|
-
new
|
|
181
|
+
new GoogleImageModel(modelId, settings, {
|
|
186
182
|
provider: providerName,
|
|
187
183
|
baseURL,
|
|
188
184
|
headers: getHeaders,
|
|
@@ -190,15 +186,15 @@ export function createGoogleGenerativeAI(
|
|
|
190
186
|
});
|
|
191
187
|
|
|
192
188
|
const createFiles = () =>
|
|
193
|
-
new
|
|
189
|
+
new GoogleFiles({
|
|
194
190
|
provider: providerName,
|
|
195
191
|
baseURL,
|
|
196
192
|
headers: getHeaders,
|
|
197
193
|
fetch: options.fetch,
|
|
198
194
|
});
|
|
199
195
|
|
|
200
|
-
const createVideoModel = (modelId:
|
|
201
|
-
new
|
|
196
|
+
const createVideoModel = (modelId: GoogleVideoModelId) =>
|
|
197
|
+
new GoogleVideoModel(modelId, {
|
|
202
198
|
provider: providerName,
|
|
203
199
|
baseURL,
|
|
204
200
|
headers: getHeaders,
|
|
@@ -206,7 +202,7 @@ export function createGoogleGenerativeAI(
|
|
|
206
202
|
generateId: options.generateId ?? generateId,
|
|
207
203
|
});
|
|
208
204
|
|
|
209
|
-
const provider = function (modelId:
|
|
205
|
+
const provider = function (modelId: GoogleModelId) {
|
|
210
206
|
if (new.target) {
|
|
211
207
|
throw new Error(
|
|
212
208
|
'The Google Generative AI model function cannot be called with the new keyword.',
|
|
@@ -231,10 +227,10 @@ export function createGoogleGenerativeAI(
|
|
|
231
227
|
provider.files = createFiles;
|
|
232
228
|
provider.tools = googleTools;
|
|
233
229
|
|
|
234
|
-
return provider as
|
|
230
|
+
return provider as GoogleProvider;
|
|
235
231
|
}
|
|
236
232
|
|
|
237
233
|
/**
|
|
238
234
|
* Default Google Generative AI provider instance.
|
|
239
235
|
*/
|
|
240
|
-
export const google =
|
|
236
|
+
export const google = createGoogle();
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
} from '@ai-sdk/provider-utils';
|
|
20
20
|
import { z } from 'zod/v4';
|
|
21
21
|
import { googleFailedResponseHandler } from './google-error';
|
|
22
|
-
import type {
|
|
22
|
+
import type { GoogleVideoModelId } from './google-video-settings';
|
|
23
23
|
|
|
24
24
|
export type GoogleVideoModelOptions = {
|
|
25
25
|
// Polling configuration
|
|
@@ -39,7 +39,7 @@ export type GoogleVideoModelOptions = {
|
|
|
39
39
|
[key: string]: unknown; // For passthrough
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
interface
|
|
42
|
+
interface GoogleVideoModelConfig {
|
|
43
43
|
provider: string;
|
|
44
44
|
baseURL: string;
|
|
45
45
|
headers?: Resolvable<Record<string, string | undefined>>;
|
|
@@ -50,7 +50,7 @@ interface GoogleGenerativeAIVideoModelConfig {
|
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
export class
|
|
53
|
+
export class GoogleVideoModel implements Experimental_VideoModelV4 {
|
|
54
54
|
readonly specificationVersion = 'v4';
|
|
55
55
|
|
|
56
56
|
get provider(): string {
|
|
@@ -63,8 +63,8 @@ export class GoogleGenerativeAIVideoModel implements Experimental_VideoModelV4 {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
constructor(
|
|
66
|
-
readonly modelId:
|
|
67
|
-
private readonly config:
|
|
66
|
+
readonly modelId: GoogleVideoModelId,
|
|
67
|
+
private readonly config: GoogleVideoModelConfig,
|
|
68
68
|
) {}
|
|
69
69
|
|
|
70
70
|
async doGenerate(
|
package/src/index.ts
CHANGED
|
@@ -3,28 +3,46 @@ export type {
|
|
|
3
3
|
GoogleLanguageModelOptions,
|
|
4
4
|
/** @deprecated Use `GoogleLanguageModelOptions` instead. */
|
|
5
5
|
GoogleLanguageModelOptions as GoogleGenerativeAIProviderOptions,
|
|
6
|
-
} from './google-
|
|
7
|
-
export type {
|
|
6
|
+
} from './google-options';
|
|
7
|
+
export type {
|
|
8
|
+
GoogleProviderMetadata,
|
|
9
|
+
/** @deprecated Use `GoogleProviderMetadata` instead. */
|
|
10
|
+
GoogleProviderMetadata as GoogleGenerativeAIProviderMetadata,
|
|
11
|
+
} from './google-prompt';
|
|
8
12
|
export type {
|
|
9
13
|
GoogleImageModelOptions,
|
|
10
14
|
/** @deprecated Use `GoogleImageModelOptions` instead. */
|
|
11
15
|
GoogleImageModelOptions as GoogleGenerativeAIImageProviderOptions,
|
|
12
|
-
} from './google-
|
|
16
|
+
} from './google-image-model';
|
|
13
17
|
export type {
|
|
14
18
|
GoogleEmbeddingModelOptions,
|
|
15
19
|
/** @deprecated Use `GoogleEmbeddingModelOptions` instead. */
|
|
16
20
|
GoogleEmbeddingModelOptions as GoogleGenerativeAIEmbeddingProviderOptions,
|
|
17
|
-
} from './google-
|
|
21
|
+
} from './google-embedding-options';
|
|
18
22
|
export type {
|
|
19
23
|
GoogleVideoModelOptions,
|
|
20
24
|
/** @deprecated Use `GoogleVideoModelOptions` instead. */
|
|
21
25
|
GoogleVideoModelOptions as GoogleGenerativeAIVideoProviderOptions,
|
|
22
|
-
} from './google-
|
|
23
|
-
export type {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
} from './google-video-model';
|
|
27
|
+
export type {
|
|
28
|
+
GoogleVideoModelId,
|
|
29
|
+
/** @deprecated Use `GoogleVideoModelId` instead. */
|
|
30
|
+
GoogleVideoModelId as GoogleGenerativeAIVideoModelId,
|
|
31
|
+
} from './google-video-settings';
|
|
32
|
+
export type { GoogleFilesUploadOptions } from './google-files';
|
|
33
|
+
export {
|
|
34
|
+
createGoogle,
|
|
35
|
+
google,
|
|
36
|
+
/** @deprecated Use `createGoogle` instead. */
|
|
37
|
+
createGoogle as createGoogleGenerativeAI,
|
|
38
|
+
} from './google-provider';
|
|
26
39
|
export type {
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
GoogleProvider,
|
|
41
|
+
GoogleProviderSettings,
|
|
42
|
+
/** @deprecated Use `GoogleProvider` instead. */
|
|
43
|
+
GoogleProvider as GoogleGenerativeAIProvider,
|
|
44
|
+
/** @deprecated Use `GoogleProviderSettings` instead. */
|
|
45
|
+
GoogleProviderSettings as GoogleGenerativeAIProviderSettings,
|
|
29
46
|
} from './google-provider';
|
|
47
|
+
|
|
30
48
|
export { VERSION } from './version';
|
package/src/internal/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from '../google-
|
|
1
|
+
export * from '../google-language-model';
|
|
2
2
|
export { googleTools } from '../google-tools';
|
|
3
|
-
export type {
|
|
3
|
+
export type { GoogleModelId } from '../google-options';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createProviderExecutedToolFactory } from '@ai-sdk/provider-utils';
|
|
2
2
|
import { z } from 'zod/v4';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -10,7 +10,7 @@ import { z } from 'zod/v4';
|
|
|
10
10
|
* @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
|
|
11
11
|
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
|
|
12
12
|
*/
|
|
13
|
-
export const codeExecution =
|
|
13
|
+
export const codeExecution = createProviderExecutedToolFactory<
|
|
14
14
|
{
|
|
15
15
|
language: string;
|
|
16
16
|
code: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
createProviderExecutedToolFactory,
|
|
3
3
|
lazySchema,
|
|
4
4
|
zodSchema,
|
|
5
5
|
} from '@ai-sdk/provider-utils';
|
|
@@ -7,12 +7,18 @@ import { z } from 'zod/v4';
|
|
|
7
7
|
|
|
8
8
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/web-grounding-enterprise
|
|
9
9
|
|
|
10
|
-
export const enterpriseWebSearch =
|
|
10
|
+
export const enterpriseWebSearch = createProviderExecutedToolFactory<
|
|
11
11
|
{
|
|
12
12
|
// Enterprise Web Search does not have any input schema
|
|
13
13
|
},
|
|
14
|
-
{
|
|
14
|
+
{
|
|
15
|
+
// Enterprise Web Search does not have any output parameters
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
// Enterprise Web Search does not have any configuration options
|
|
19
|
+
}
|
|
15
20
|
>({
|
|
16
21
|
id: 'google.enterprise_web_search',
|
|
17
22
|
inputSchema: lazySchema(() => zodSchema(z.object({}))),
|
|
23
|
+
outputSchema: lazySchema(() => zodSchema(z.object({}))),
|
|
18
24
|
});
|