@ai-sdk/google 2.0.0-beta.16 → 2.0.0-beta.18
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/dist/index.d.mts +34 -6
- package/dist/index.d.ts +34 -6
- package/dist/index.js +131 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -25
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +17 -0
- package/dist/internal/index.d.ts +17 -0
- package/dist/internal/index.js +116 -19
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +116 -19
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# @ai-sdk/google
|
2
2
|
|
3
|
+
## 2.0.0-beta.18
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 78e7fa9: Add code execution provider defined tool
|
8
|
+
- 0f05690: Add gemini-embedding-001 model, add embedding provider options type export
|
9
|
+
- Updated dependencies [27deb4d]
|
10
|
+
- @ai-sdk/provider@2.0.0-beta.2
|
11
|
+
- @ai-sdk/provider-utils@3.0.0-beta.9
|
12
|
+
|
13
|
+
## 2.0.0-beta.17
|
14
|
+
|
15
|
+
### Patch Changes
|
16
|
+
|
17
|
+
- eb173f1: chore (providers): remove model shorthand deprecation warnings
|
18
|
+
- Updated dependencies [dd5fd43]
|
19
|
+
- @ai-sdk/provider-utils@3.0.0-beta.8
|
20
|
+
|
3
21
|
## 2.0.0-beta.16
|
4
22
|
|
5
23
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -136,7 +136,21 @@ declare const googleImageProviderOptionsSchema: z.ZodObject<{
|
|
136
136
|
}, z.core.$strip>;
|
137
137
|
type GoogleGenerativeAIImageProviderOptions = z.infer<typeof googleImageProviderOptionsSchema>;
|
138
138
|
|
139
|
-
type GoogleGenerativeAIEmbeddingModelId = 'text-embedding-004' | (string & {});
|
139
|
+
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'text-embedding-004' | (string & {});
|
140
|
+
declare const googleGenerativeAIEmbeddingProviderOptions: z.ZodObject<{
|
141
|
+
outputDimensionality: z.ZodOptional<z.ZodNumber>;
|
142
|
+
taskType: z.ZodOptional<z.ZodEnum<{
|
143
|
+
SEMANTIC_SIMILARITY: "SEMANTIC_SIMILARITY";
|
144
|
+
CLASSIFICATION: "CLASSIFICATION";
|
145
|
+
CLUSTERING: "CLUSTERING";
|
146
|
+
RETRIEVAL_DOCUMENT: "RETRIEVAL_DOCUMENT";
|
147
|
+
RETRIEVAL_QUERY: "RETRIEVAL_QUERY";
|
148
|
+
QUESTION_ANSWERING: "QUESTION_ANSWERING";
|
149
|
+
FACT_VERIFICATION: "FACT_VERIFICATION";
|
150
|
+
CODE_RETRIEVAL_QUERY: "CODE_RETRIEVAL_QUERY";
|
151
|
+
}>>;
|
152
|
+
}, z.core.$strip>;
|
153
|
+
type GoogleGenerativeAIEmbeddingProviderOptions = z.infer<typeof googleGenerativeAIEmbeddingProviderOptions>;
|
140
154
|
|
141
155
|
declare const googleTools: {
|
142
156
|
/**
|
@@ -152,6 +166,23 @@ declare const googleTools: {
|
|
152
166
|
* Must have name "url_context".
|
153
167
|
*/
|
154
168
|
urlContext: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {}>;
|
169
|
+
/**
|
170
|
+
* A tool that enables the model to generate and run Python code.
|
171
|
+
* Must have name "code_execution".
|
172
|
+
*
|
173
|
+
* @note Ensure the selected model supports Code Execution.
|
174
|
+
* Multi-tool usage with the code execution tool is typically compatible with Gemini >=2 models.
|
175
|
+
*
|
176
|
+
* @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
|
177
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
|
178
|
+
*/
|
179
|
+
codeExecution: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{
|
180
|
+
language: string;
|
181
|
+
code: string;
|
182
|
+
}, {
|
183
|
+
outcome: string;
|
184
|
+
output: string;
|
185
|
+
}, {}>;
|
155
186
|
};
|
156
187
|
|
157
188
|
interface GoogleGenerativeAIProvider extends ProviderV2 {
|
@@ -167,12 +198,9 @@ interface GoogleGenerativeAIProvider extends ProviderV2 {
|
|
167
198
|
*/
|
168
199
|
generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV2;
|
169
200
|
/**
|
170
|
-
@deprecated Use `
|
201
|
+
@deprecated Use `textEmbedding()` instead.
|
171
202
|
*/
|
172
203
|
embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
173
|
-
/**
|
174
|
-
@deprecated Use `textEmbeddingModel()` instead.
|
175
|
-
*/
|
176
204
|
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
177
205
|
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
178
206
|
tools: typeof googleTools;
|
@@ -211,4 +239,4 @@ Default Google Generative AI provider instance.
|
|
211
239
|
*/
|
212
240
|
declare const google: GoogleGenerativeAIProvider;
|
213
241
|
|
214
|
-
export { type GoogleErrorData, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|
242
|
+
export { type GoogleErrorData, type GoogleGenerativeAIEmbeddingProviderOptions, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|
package/dist/index.d.ts
CHANGED
@@ -136,7 +136,21 @@ declare const googleImageProviderOptionsSchema: z.ZodObject<{
|
|
136
136
|
}, z.core.$strip>;
|
137
137
|
type GoogleGenerativeAIImageProviderOptions = z.infer<typeof googleImageProviderOptionsSchema>;
|
138
138
|
|
139
|
-
type GoogleGenerativeAIEmbeddingModelId = 'text-embedding-004' | (string & {});
|
139
|
+
type GoogleGenerativeAIEmbeddingModelId = 'gemini-embedding-001' | 'text-embedding-004' | (string & {});
|
140
|
+
declare const googleGenerativeAIEmbeddingProviderOptions: z.ZodObject<{
|
141
|
+
outputDimensionality: z.ZodOptional<z.ZodNumber>;
|
142
|
+
taskType: z.ZodOptional<z.ZodEnum<{
|
143
|
+
SEMANTIC_SIMILARITY: "SEMANTIC_SIMILARITY";
|
144
|
+
CLASSIFICATION: "CLASSIFICATION";
|
145
|
+
CLUSTERING: "CLUSTERING";
|
146
|
+
RETRIEVAL_DOCUMENT: "RETRIEVAL_DOCUMENT";
|
147
|
+
RETRIEVAL_QUERY: "RETRIEVAL_QUERY";
|
148
|
+
QUESTION_ANSWERING: "QUESTION_ANSWERING";
|
149
|
+
FACT_VERIFICATION: "FACT_VERIFICATION";
|
150
|
+
CODE_RETRIEVAL_QUERY: "CODE_RETRIEVAL_QUERY";
|
151
|
+
}>>;
|
152
|
+
}, z.core.$strip>;
|
153
|
+
type GoogleGenerativeAIEmbeddingProviderOptions = z.infer<typeof googleGenerativeAIEmbeddingProviderOptions>;
|
140
154
|
|
141
155
|
declare const googleTools: {
|
142
156
|
/**
|
@@ -152,6 +166,23 @@ declare const googleTools: {
|
|
152
166
|
* Must have name "url_context".
|
153
167
|
*/
|
154
168
|
urlContext: _ai_sdk_provider_utils.ProviderDefinedToolFactory<{}, {}>;
|
169
|
+
/**
|
170
|
+
* A tool that enables the model to generate and run Python code.
|
171
|
+
* Must have name "code_execution".
|
172
|
+
*
|
173
|
+
* @note Ensure the selected model supports Code Execution.
|
174
|
+
* Multi-tool usage with the code execution tool is typically compatible with Gemini >=2 models.
|
175
|
+
*
|
176
|
+
* @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
|
177
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
|
178
|
+
*/
|
179
|
+
codeExecution: _ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{
|
180
|
+
language: string;
|
181
|
+
code: string;
|
182
|
+
}, {
|
183
|
+
outcome: string;
|
184
|
+
output: string;
|
185
|
+
}, {}>;
|
155
186
|
};
|
156
187
|
|
157
188
|
interface GoogleGenerativeAIProvider extends ProviderV2 {
|
@@ -167,12 +198,9 @@ interface GoogleGenerativeAIProvider extends ProviderV2 {
|
|
167
198
|
*/
|
168
199
|
generativeAI(modelId: GoogleGenerativeAIModelId): LanguageModelV2;
|
169
200
|
/**
|
170
|
-
@deprecated Use `
|
201
|
+
@deprecated Use `textEmbedding()` instead.
|
171
202
|
*/
|
172
203
|
embedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
173
|
-
/**
|
174
|
-
@deprecated Use `textEmbeddingModel()` instead.
|
175
|
-
*/
|
176
204
|
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
177
205
|
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId): EmbeddingModelV2<string>;
|
178
206
|
tools: typeof googleTools;
|
@@ -211,4 +239,4 @@ Default Google Generative AI provider instance.
|
|
211
239
|
*/
|
212
240
|
declare const google: GoogleGenerativeAIProvider;
|
213
241
|
|
214
|
-
export { type GoogleErrorData, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|
242
|
+
export { type GoogleErrorData, type GoogleGenerativeAIEmbeddingProviderOptions, type GoogleGenerativeAIImageProviderOptions, type GoogleGenerativeAIProvider, type GoogleGenerativeAIProviderMetadata, type GoogleGenerativeAIProviderOptions, type GoogleGenerativeAIProviderSettings, createGoogleGenerativeAI, google };
|
package/dist/index.js
CHANGED
@@ -26,7 +26,7 @@ __export(src_exports, {
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
27
27
|
|
28
28
|
// src/google-provider.ts
|
29
|
-
var
|
29
|
+
var import_provider_utils9 = require("@ai-sdk/provider-utils");
|
30
30
|
|
31
31
|
// src/google-generative-ai-embedding-model.ts
|
32
32
|
var import_provider = require("@ai-sdk/provider");
|
@@ -525,6 +525,17 @@ function prepareTools({
|
|
525
525
|
});
|
526
526
|
}
|
527
527
|
break;
|
528
|
+
case "google.code_execution":
|
529
|
+
if (isGemini2) {
|
530
|
+
googleTools2.codeExecution = {};
|
531
|
+
} else {
|
532
|
+
toolWarnings.push({
|
533
|
+
type: "unsupported-tool",
|
534
|
+
tool,
|
535
|
+
details: "The code execution tools is not supported with other Gemini models than Gemini 2."
|
536
|
+
});
|
537
|
+
}
|
538
|
+
break;
|
528
539
|
default:
|
529
540
|
toolWarnings.push({ type: "unsupported-tool", tool });
|
530
541
|
break;
|
@@ -777,7 +788,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
777
788
|
};
|
778
789
|
}
|
779
790
|
async doGenerate(options) {
|
780
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
791
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
781
792
|
const { args, warnings } = await this.getArgs(options);
|
782
793
|
const body = JSON.stringify(args);
|
783
794
|
const mergedHeaders = (0, import_provider_utils6.combineHeaders)(
|
@@ -801,10 +812,34 @@ var GoogleGenerativeAILanguageModel = class {
|
|
801
812
|
});
|
802
813
|
const candidate = response.candidates[0];
|
803
814
|
const content = [];
|
804
|
-
const parts =
|
815
|
+
const parts = (_b = (_a = candidate.content) == null ? void 0 : _a.parts) != null ? _b : [];
|
805
816
|
const usageMetadata = response.usageMetadata;
|
817
|
+
let lastCodeExecutionToolCallId;
|
806
818
|
for (const part of parts) {
|
807
|
-
if ("
|
819
|
+
if ("executableCode" in part && ((_c = part.executableCode) == null ? void 0 : _c.code)) {
|
820
|
+
const toolCallId = this.config.generateId();
|
821
|
+
lastCodeExecutionToolCallId = toolCallId;
|
822
|
+
content.push({
|
823
|
+
type: "tool-call",
|
824
|
+
toolCallId,
|
825
|
+
toolName: "code_execution",
|
826
|
+
input: JSON.stringify(part.executableCode),
|
827
|
+
providerExecuted: true
|
828
|
+
});
|
829
|
+
} else if ("codeExecutionResult" in part && part.codeExecutionResult) {
|
830
|
+
content.push({
|
831
|
+
type: "tool-result",
|
832
|
+
// Assumes a result directly follows its corresponding call part.
|
833
|
+
toolCallId: lastCodeExecutionToolCallId,
|
834
|
+
toolName: "code_execution",
|
835
|
+
result: {
|
836
|
+
outcome: part.codeExecutionResult.outcome,
|
837
|
+
output: part.codeExecutionResult.output
|
838
|
+
},
|
839
|
+
providerExecuted: true
|
840
|
+
});
|
841
|
+
lastCodeExecutionToolCallId = void 0;
|
842
|
+
} else if ("text" in part && part.text != null && part.text.length > 0) {
|
808
843
|
if (part.thought === true) {
|
809
844
|
content.push({ type: "reasoning", text: part.text });
|
810
845
|
} else {
|
@@ -825,10 +860,10 @@ var GoogleGenerativeAILanguageModel = class {
|
|
825
860
|
});
|
826
861
|
}
|
827
862
|
}
|
828
|
-
const sources = (
|
863
|
+
const sources = (_d = extractSources({
|
829
864
|
groundingMetadata: candidate.groundingMetadata,
|
830
865
|
generateId: this.config.generateId
|
831
|
-
})) != null ?
|
866
|
+
})) != null ? _d : [];
|
832
867
|
for (const source of sources) {
|
833
868
|
content.push(source);
|
834
869
|
}
|
@@ -839,18 +874,18 @@ var GoogleGenerativeAILanguageModel = class {
|
|
839
874
|
hasToolCalls: content.some((part) => part.type === "tool-call")
|
840
875
|
}),
|
841
876
|
usage: {
|
842
|
-
inputTokens: (
|
843
|
-
outputTokens: (
|
844
|
-
totalTokens: (
|
845
|
-
reasoningTokens: (
|
846
|
-
cachedInputTokens: (
|
877
|
+
inputTokens: (_e = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _e : void 0,
|
878
|
+
outputTokens: (_f = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _f : void 0,
|
879
|
+
totalTokens: (_g = usageMetadata == null ? void 0 : usageMetadata.totalTokenCount) != null ? _g : void 0,
|
880
|
+
reasoningTokens: (_h = usageMetadata == null ? void 0 : usageMetadata.thoughtsTokenCount) != null ? _h : void 0,
|
881
|
+
cachedInputTokens: (_i = usageMetadata == null ? void 0 : usageMetadata.cachedContentTokenCount) != null ? _i : void 0
|
847
882
|
},
|
848
883
|
warnings,
|
849
884
|
providerMetadata: {
|
850
885
|
google: {
|
851
|
-
groundingMetadata: (
|
852
|
-
urlContextMetadata: (
|
853
|
-
safetyRatings: (
|
886
|
+
groundingMetadata: (_j = candidate.groundingMetadata) != null ? _j : null,
|
887
|
+
urlContextMetadata: (_k = candidate.urlContextMetadata) != null ? _k : null,
|
888
|
+
safetyRatings: (_l = candidate.safetyRatings) != null ? _l : null,
|
854
889
|
usageMetadata: usageMetadata != null ? usageMetadata : null
|
855
890
|
}
|
856
891
|
},
|
@@ -893,6 +928,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
893
928
|
let currentReasoningBlockId = null;
|
894
929
|
let blockCounter = 0;
|
895
930
|
const emittedSourceUrls = /* @__PURE__ */ new Set();
|
931
|
+
let lastCodeExecutionToolCallId;
|
896
932
|
return {
|
897
933
|
stream: response.pipeThrough(
|
898
934
|
new TransformStream({
|
@@ -900,7 +936,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
900
936
|
controller.enqueue({ type: "stream-start", warnings });
|
901
937
|
},
|
902
938
|
transform(chunk, controller) {
|
903
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
939
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
904
940
|
if (options.includeRawChunks) {
|
905
941
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
906
942
|
}
|
@@ -937,7 +973,33 @@ var GoogleGenerativeAILanguageModel = class {
|
|
937
973
|
if (content != null) {
|
938
974
|
const parts = (_g = content.parts) != null ? _g : [];
|
939
975
|
for (const part of parts) {
|
940
|
-
if ("
|
976
|
+
if ("executableCode" in part && ((_h = part.executableCode) == null ? void 0 : _h.code)) {
|
977
|
+
const toolCallId = generateId3();
|
978
|
+
lastCodeExecutionToolCallId = toolCallId;
|
979
|
+
controller.enqueue({
|
980
|
+
type: "tool-call",
|
981
|
+
toolCallId,
|
982
|
+
toolName: "code_execution",
|
983
|
+
input: JSON.stringify(part.executableCode),
|
984
|
+
providerExecuted: true
|
985
|
+
});
|
986
|
+
hasToolCalls = true;
|
987
|
+
} else if ("codeExecutionResult" in part && part.codeExecutionResult) {
|
988
|
+
const toolCallId = lastCodeExecutionToolCallId;
|
989
|
+
if (toolCallId) {
|
990
|
+
controller.enqueue({
|
991
|
+
type: "tool-result",
|
992
|
+
toolCallId,
|
993
|
+
toolName: "code_execution",
|
994
|
+
result: {
|
995
|
+
outcome: part.codeExecutionResult.outcome,
|
996
|
+
output: part.codeExecutionResult.output
|
997
|
+
},
|
998
|
+
providerExecuted: true
|
999
|
+
});
|
1000
|
+
lastCodeExecutionToolCallId = void 0;
|
1001
|
+
}
|
1002
|
+
} else if ("text" in part && part.text != null && part.text.length > 0) {
|
941
1003
|
if (part.thought === true) {
|
942
1004
|
if (currentTextBlockId !== null) {
|
943
1005
|
controller.enqueue({
|
@@ -1028,9 +1090,9 @@ var GoogleGenerativeAILanguageModel = class {
|
|
1028
1090
|
});
|
1029
1091
|
providerMetadata = {
|
1030
1092
|
google: {
|
1031
|
-
groundingMetadata: (
|
1032
|
-
urlContextMetadata: (
|
1033
|
-
safetyRatings: (
|
1093
|
+
groundingMetadata: (_i = candidate.groundingMetadata) != null ? _i : null,
|
1094
|
+
urlContextMetadata: (_j = candidate.urlContextMetadata) != null ? _j : null,
|
1095
|
+
safetyRatings: (_k = candidate.safetyRatings) != null ? _k : null
|
1034
1096
|
}
|
1035
1097
|
};
|
1036
1098
|
if (usageMetadata != null) {
|
@@ -1116,6 +1178,14 @@ var contentSchema = import_v47.z.object({
|
|
1116
1178
|
})
|
1117
1179
|
}),
|
1118
1180
|
import_v47.z.object({
|
1181
|
+
executableCode: import_v47.z.object({
|
1182
|
+
language: import_v47.z.string(),
|
1183
|
+
code: import_v47.z.string()
|
1184
|
+
}).nullish(),
|
1185
|
+
codeExecutionResult: import_v47.z.object({
|
1186
|
+
outcome: import_v47.z.string(),
|
1187
|
+
output: import_v47.z.string()
|
1188
|
+
}).nullish(),
|
1119
1189
|
text: import_v47.z.string().nullish(),
|
1120
1190
|
thought: import_v47.z.boolean().nullish()
|
1121
1191
|
})
|
@@ -1162,6 +1232,22 @@ var chunkSchema = import_v47.z.object({
|
|
1162
1232
|
usageMetadata: usageSchema.nullish()
|
1163
1233
|
});
|
1164
1234
|
|
1235
|
+
// src/tool/code-execution.ts
|
1236
|
+
var import_provider_utils7 = require("@ai-sdk/provider-utils");
|
1237
|
+
var import_v48 = require("zod/v4");
|
1238
|
+
var codeExecution = (0, import_provider_utils7.createProviderDefinedToolFactoryWithOutputSchema)({
|
1239
|
+
id: "google.code_execution",
|
1240
|
+
name: "code_execution",
|
1241
|
+
inputSchema: import_v48.z.object({
|
1242
|
+
language: import_v48.z.string().describe("The programming language of the code."),
|
1243
|
+
code: import_v48.z.string().describe("The code to be executed.")
|
1244
|
+
}),
|
1245
|
+
outputSchema: import_v48.z.object({
|
1246
|
+
outcome: import_v48.z.string().describe('The outcome of the execution (e.g., "OUTCOME_OK").'),
|
1247
|
+
output: import_v48.z.string().describe("The output from the code execution.")
|
1248
|
+
})
|
1249
|
+
});
|
1250
|
+
|
1165
1251
|
// src/google-tools.ts
|
1166
1252
|
var googleTools = {
|
1167
1253
|
/**
|
@@ -1173,12 +1259,23 @@ var googleTools = {
|
|
1173
1259
|
* Creates a URL context tool that gives Google direct access to real-time web content.
|
1174
1260
|
* Must have name "url_context".
|
1175
1261
|
*/
|
1176
|
-
urlContext
|
1262
|
+
urlContext,
|
1263
|
+
/**
|
1264
|
+
* A tool that enables the model to generate and run Python code.
|
1265
|
+
* Must have name "code_execution".
|
1266
|
+
*
|
1267
|
+
* @note Ensure the selected model supports Code Execution.
|
1268
|
+
* Multi-tool usage with the code execution tool is typically compatible with Gemini >=2 models.
|
1269
|
+
*
|
1270
|
+
* @see https://ai.google.dev/gemini-api/docs/code-execution (Google AI)
|
1271
|
+
* @see https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/code-execution-api (Vertex AI)
|
1272
|
+
*/
|
1273
|
+
codeExecution
|
1177
1274
|
};
|
1178
1275
|
|
1179
1276
|
// src/google-generative-ai-image-model.ts
|
1180
|
-
var
|
1181
|
-
var
|
1277
|
+
var import_provider_utils8 = require("@ai-sdk/provider-utils");
|
1278
|
+
var import_v49 = require("zod/v4");
|
1182
1279
|
var GoogleGenerativeAIImageModel = class {
|
1183
1280
|
constructor(modelId, settings, config) {
|
1184
1281
|
this.modelId = modelId;
|
@@ -1220,7 +1317,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
1220
1317
|
details: "This model does not support the `seed` option through this provider."
|
1221
1318
|
});
|
1222
1319
|
}
|
1223
|
-
const googleOptions = await (0,
|
1320
|
+
const googleOptions = await (0, import_provider_utils8.parseProviderOptions)({
|
1224
1321
|
provider: "google",
|
1225
1322
|
providerOptions,
|
1226
1323
|
schema: googleImageProviderOptionsSchema
|
@@ -1239,12 +1336,12 @@ var GoogleGenerativeAIImageModel = class {
|
|
1239
1336
|
instances: [{ prompt }],
|
1240
1337
|
parameters
|
1241
1338
|
};
|
1242
|
-
const { responseHeaders, value: response } = await (0,
|
1339
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils8.postJsonToApi)({
|
1243
1340
|
url: `${this.config.baseURL}/models/${this.modelId}:predict`,
|
1244
|
-
headers: (0,
|
1341
|
+
headers: (0, import_provider_utils8.combineHeaders)(await (0, import_provider_utils8.resolve)(this.config.headers), headers),
|
1245
1342
|
body,
|
1246
1343
|
failedResponseHandler: googleFailedResponseHandler,
|
1247
|
-
successfulResponseHandler: (0,
|
1344
|
+
successfulResponseHandler: (0, import_provider_utils8.createJsonResponseHandler)(
|
1248
1345
|
googleImageResponseSchema
|
1249
1346
|
),
|
1250
1347
|
abortSignal,
|
@@ -1270,20 +1367,20 @@ var GoogleGenerativeAIImageModel = class {
|
|
1270
1367
|
};
|
1271
1368
|
}
|
1272
1369
|
};
|
1273
|
-
var googleImageResponseSchema =
|
1274
|
-
predictions:
|
1370
|
+
var googleImageResponseSchema = import_v49.z.object({
|
1371
|
+
predictions: import_v49.z.array(import_v49.z.object({ bytesBase64Encoded: import_v49.z.string() })).default([])
|
1275
1372
|
});
|
1276
|
-
var googleImageProviderOptionsSchema =
|
1277
|
-
personGeneration:
|
1278
|
-
aspectRatio:
|
1373
|
+
var googleImageProviderOptionsSchema = import_v49.z.object({
|
1374
|
+
personGeneration: import_v49.z.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
1375
|
+
aspectRatio: import_v49.z.enum(["1:1", "3:4", "4:3", "9:16", "16:9"]).nullish()
|
1279
1376
|
});
|
1280
1377
|
|
1281
1378
|
// src/google-provider.ts
|
1282
1379
|
function createGoogleGenerativeAI(options = {}) {
|
1283
1380
|
var _a;
|
1284
|
-
const baseURL = (_a = (0,
|
1381
|
+
const baseURL = (_a = (0, import_provider_utils9.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
1285
1382
|
const getHeaders = () => ({
|
1286
|
-
"x-goog-api-key": (0,
|
1383
|
+
"x-goog-api-key": (0, import_provider_utils9.loadApiKey)({
|
1287
1384
|
apiKey: options.apiKey,
|
1288
1385
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
1289
1386
|
description: "Google Generative AI"
|
@@ -1296,7 +1393,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
1296
1393
|
provider: "google.generative-ai",
|
1297
1394
|
baseURL,
|
1298
1395
|
headers: getHeaders,
|
1299
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
1396
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils9.generateId,
|
1300
1397
|
supportedUrls: () => ({
|
1301
1398
|
"*": [
|
1302
1399
|
// Only allow requests to the Google Generative Language "files" endpoint
|