@ai-sdk/google 3.0.24 → 3.0.26
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 +12 -0
- package/dist/index.d.mts +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +132 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +134 -15
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +3 -3
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +3 -3
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +111 -20
- package/package.json +3 -3
- package/src/google-generative-ai-embedding-model.ts +2 -2
- package/src/google-generative-ai-embedding-options.ts +3 -3
- package/src/google-generative-ai-image-model.ts +176 -11
- package/src/google-generative-ai-image-settings.ts +4 -0
- package/src/google-generative-ai-language-model.ts +3 -3
- package/src/google-generative-ai-options.ts +3 -3
- package/src/google-generative-ai-video-model.ts +5 -5
- package/src/index.ts +20 -4
package/dist/index.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "3.0.
|
|
10
|
+
var VERSION = true ? "3.0.26" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-generative-ai-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
zodSchema as zodSchema2
|
|
54
54
|
} from "@ai-sdk/provider-utils";
|
|
55
55
|
import { z as z2 } from "zod/v4";
|
|
56
|
-
var
|
|
56
|
+
var googleEmbeddingModelOptions = lazySchema2(
|
|
57
57
|
() => zodSchema2(
|
|
58
58
|
z2.object({
|
|
59
59
|
/**
|
|
@@ -108,7 +108,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
|
108
108
|
const googleOptions = await parseProviderOptions({
|
|
109
109
|
provider: "google",
|
|
110
110
|
providerOptions,
|
|
111
|
-
schema:
|
|
111
|
+
schema: googleEmbeddingModelOptions
|
|
112
112
|
});
|
|
113
113
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
114
114
|
throw new TooManyEmbeddingValuesForCallError({
|
|
@@ -548,7 +548,7 @@ function getModelPath(modelId) {
|
|
|
548
548
|
// src/google-generative-ai-options.ts
|
|
549
549
|
import { lazySchema as lazySchema4, zodSchema as zodSchema4 } from "@ai-sdk/provider-utils";
|
|
550
550
|
import { z as z4 } from "zod/v4";
|
|
551
|
-
var
|
|
551
|
+
var googleLanguageModelOptions = lazySchema4(
|
|
552
552
|
() => zodSchema4(
|
|
553
553
|
z4.object({
|
|
554
554
|
responseModalities: z4.array(z4.enum(["TEXT", "IMAGE"])).optional(),
|
|
@@ -932,13 +932,13 @@ var GoogleGenerativeAILanguageModel = class {
|
|
|
932
932
|
let googleOptions = await parseProviderOptions2({
|
|
933
933
|
provider: providerOptionsName,
|
|
934
934
|
providerOptions,
|
|
935
|
-
schema:
|
|
935
|
+
schema: googleLanguageModelOptions
|
|
936
936
|
});
|
|
937
937
|
if (googleOptions == null && providerOptionsName !== "google") {
|
|
938
938
|
googleOptions = await parseProviderOptions2({
|
|
939
939
|
provider: "google",
|
|
940
940
|
providerOptions,
|
|
941
|
-
schema:
|
|
941
|
+
schema: googleLanguageModelOptions
|
|
942
942
|
});
|
|
943
943
|
}
|
|
944
944
|
if ((tools == null ? void 0 : tools.some(
|
|
@@ -1806,7 +1806,9 @@ var googleTools = {
|
|
|
1806
1806
|
// src/google-generative-ai-image-model.ts
|
|
1807
1807
|
import {
|
|
1808
1808
|
combineHeaders as combineHeaders3,
|
|
1809
|
+
convertToBase64 as convertToBase642,
|
|
1809
1810
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
1811
|
+
generateId as defaultGenerateId,
|
|
1810
1812
|
lazySchema as lazySchema11,
|
|
1811
1813
|
parseProviderOptions as parseProviderOptions3,
|
|
1812
1814
|
postJsonToApi as postJsonToApi3,
|
|
@@ -1822,13 +1824,24 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1822
1824
|
this.specificationVersion = "v3";
|
|
1823
1825
|
}
|
|
1824
1826
|
get maxImagesPerCall() {
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
+
if (this.settings.maxImagesPerCall != null) {
|
|
1828
|
+
return this.settings.maxImagesPerCall;
|
|
1829
|
+
}
|
|
1830
|
+
if (isGeminiModel(this.modelId)) {
|
|
1831
|
+
return 10;
|
|
1832
|
+
}
|
|
1833
|
+
return 4;
|
|
1827
1834
|
}
|
|
1828
1835
|
get provider() {
|
|
1829
1836
|
return this.config.provider;
|
|
1830
1837
|
}
|
|
1831
1838
|
async doGenerate(options) {
|
|
1839
|
+
if (isGeminiModel(this.modelId)) {
|
|
1840
|
+
return this.doGenerateGemini(options);
|
|
1841
|
+
}
|
|
1842
|
+
return this.doGenerateImagen(options);
|
|
1843
|
+
}
|
|
1844
|
+
async doGenerateImagen(options) {
|
|
1832
1845
|
var _a, _b, _c;
|
|
1833
1846
|
const {
|
|
1834
1847
|
prompt,
|
|
@@ -1845,7 +1858,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1845
1858
|
const warnings = [];
|
|
1846
1859
|
if (files != null && files.length > 0) {
|
|
1847
1860
|
throw new Error(
|
|
1848
|
-
"Google Generative AI does not support image editing. Use Google Vertex AI (@ai-sdk/google-vertex) for image editing capabilities."
|
|
1861
|
+
"Google Generative AI does not support image editing with Imagen models. Use Google Vertex AI (@ai-sdk/google-vertex) for image editing capabilities."
|
|
1849
1862
|
);
|
|
1850
1863
|
}
|
|
1851
1864
|
if (mask != null) {
|
|
@@ -1870,7 +1883,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1870
1883
|
const googleOptions = await parseProviderOptions3({
|
|
1871
1884
|
provider: "google",
|
|
1872
1885
|
providerOptions,
|
|
1873
|
-
schema:
|
|
1886
|
+
schema: googleImageModelOptionsSchema
|
|
1874
1887
|
});
|
|
1875
1888
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
1876
1889
|
const parameters = {
|
|
@@ -1901,10 +1914,10 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1901
1914
|
images: response.predictions.map(
|
|
1902
1915
|
(p) => p.bytesBase64Encoded
|
|
1903
1916
|
),
|
|
1904
|
-
warnings
|
|
1917
|
+
warnings,
|
|
1905
1918
|
providerMetadata: {
|
|
1906
1919
|
google: {
|
|
1907
|
-
images: response.predictions.map((
|
|
1920
|
+
images: response.predictions.map(() => ({
|
|
1908
1921
|
// Add any prediction-specific metadata here
|
|
1909
1922
|
}))
|
|
1910
1923
|
}
|
|
@@ -1916,7 +1929,113 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1916
1929
|
}
|
|
1917
1930
|
};
|
|
1918
1931
|
}
|
|
1932
|
+
async doGenerateGemini(options) {
|
|
1933
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1934
|
+
const {
|
|
1935
|
+
prompt,
|
|
1936
|
+
n,
|
|
1937
|
+
size,
|
|
1938
|
+
aspectRatio,
|
|
1939
|
+
seed,
|
|
1940
|
+
providerOptions,
|
|
1941
|
+
headers,
|
|
1942
|
+
abortSignal,
|
|
1943
|
+
files,
|
|
1944
|
+
mask
|
|
1945
|
+
} = options;
|
|
1946
|
+
const warnings = [];
|
|
1947
|
+
if (mask != null) {
|
|
1948
|
+
throw new Error(
|
|
1949
|
+
"Gemini image models do not support mask-based image editing."
|
|
1950
|
+
);
|
|
1951
|
+
}
|
|
1952
|
+
if (n != null && n > 1) {
|
|
1953
|
+
throw new Error(
|
|
1954
|
+
"Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter."
|
|
1955
|
+
);
|
|
1956
|
+
}
|
|
1957
|
+
if (size != null) {
|
|
1958
|
+
warnings.push({
|
|
1959
|
+
type: "unsupported",
|
|
1960
|
+
feature: "size",
|
|
1961
|
+
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
const userContent = [];
|
|
1965
|
+
if (prompt != null) {
|
|
1966
|
+
userContent.push({ type: "text", text: prompt });
|
|
1967
|
+
}
|
|
1968
|
+
if (files != null && files.length > 0) {
|
|
1969
|
+
for (const file of files) {
|
|
1970
|
+
if (file.type === "url") {
|
|
1971
|
+
userContent.push({
|
|
1972
|
+
type: "file",
|
|
1973
|
+
data: new URL(file.url),
|
|
1974
|
+
mediaType: "image/*"
|
|
1975
|
+
});
|
|
1976
|
+
} else {
|
|
1977
|
+
userContent.push({
|
|
1978
|
+
type: "file",
|
|
1979
|
+
data: typeof file.data === "string" ? file.data : new Uint8Array(file.data),
|
|
1980
|
+
mediaType: file.mediaType
|
|
1981
|
+
});
|
|
1982
|
+
}
|
|
1983
|
+
}
|
|
1984
|
+
}
|
|
1985
|
+
const languageModelPrompt = [
|
|
1986
|
+
{ role: "user", content: userContent }
|
|
1987
|
+
];
|
|
1988
|
+
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
1989
|
+
provider: this.config.provider,
|
|
1990
|
+
baseURL: this.config.baseURL,
|
|
1991
|
+
headers: (_a = this.config.headers) != null ? _a : {},
|
|
1992
|
+
fetch: this.config.fetch,
|
|
1993
|
+
generateId: (_b = this.config.generateId) != null ? _b : defaultGenerateId
|
|
1994
|
+
});
|
|
1995
|
+
const result = await languageModel.doGenerate({
|
|
1996
|
+
prompt: languageModelPrompt,
|
|
1997
|
+
seed,
|
|
1998
|
+
providerOptions: {
|
|
1999
|
+
google: {
|
|
2000
|
+
responseModalities: ["IMAGE"],
|
|
2001
|
+
imageConfig: aspectRatio ? { aspectRatio } : void 0,
|
|
2002
|
+
...(_c = providerOptions == null ? void 0 : providerOptions.google) != null ? _c : {}
|
|
2003
|
+
}
|
|
2004
|
+
},
|
|
2005
|
+
headers,
|
|
2006
|
+
abortSignal
|
|
2007
|
+
});
|
|
2008
|
+
const currentDate = (_f = (_e = (_d = this.config._internal) == null ? void 0 : _d.currentDate) == null ? void 0 : _e.call(_d)) != null ? _f : /* @__PURE__ */ new Date();
|
|
2009
|
+
const images = [];
|
|
2010
|
+
for (const part of result.content) {
|
|
2011
|
+
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
2012
|
+
images.push(convertToBase642(part.data));
|
|
2013
|
+
}
|
|
2014
|
+
}
|
|
2015
|
+
return {
|
|
2016
|
+
images,
|
|
2017
|
+
warnings,
|
|
2018
|
+
providerMetadata: {
|
|
2019
|
+
google: {
|
|
2020
|
+
images: images.map(() => ({}))
|
|
2021
|
+
}
|
|
2022
|
+
},
|
|
2023
|
+
response: {
|
|
2024
|
+
timestamp: currentDate,
|
|
2025
|
+
modelId: this.modelId,
|
|
2026
|
+
headers: (_g = result.response) == null ? void 0 : _g.headers
|
|
2027
|
+
},
|
|
2028
|
+
usage: result.usage ? {
|
|
2029
|
+
inputTokens: result.usage.inputTokens.total,
|
|
2030
|
+
outputTokens: result.usage.outputTokens.total,
|
|
2031
|
+
totalTokens: ((_h = result.usage.inputTokens.total) != null ? _h : 0) + ((_i = result.usage.outputTokens.total) != null ? _i : 0)
|
|
2032
|
+
} : void 0
|
|
2033
|
+
};
|
|
2034
|
+
}
|
|
1919
2035
|
};
|
|
2036
|
+
function isGeminiModel(modelId) {
|
|
2037
|
+
return modelId.startsWith("gemini-");
|
|
2038
|
+
}
|
|
1920
2039
|
var googleImageResponseSchema = lazySchema11(
|
|
1921
2040
|
() => zodSchema11(
|
|
1922
2041
|
z13.object({
|
|
@@ -1924,7 +2043,7 @@ var googleImageResponseSchema = lazySchema11(
|
|
|
1924
2043
|
})
|
|
1925
2044
|
)
|
|
1926
2045
|
);
|
|
1927
|
-
var
|
|
2046
|
+
var googleImageModelOptionsSchema = lazySchema11(
|
|
1928
2047
|
() => zodSchema11(
|
|
1929
2048
|
z13.object({
|
|
1930
2049
|
personGeneration: z13.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
@@ -1969,7 +2088,7 @@ var GoogleGenerativeAIVideoModel = class {
|
|
|
1969
2088
|
const googleOptions = await parseProviderOptions4({
|
|
1970
2089
|
provider: "google",
|
|
1971
2090
|
providerOptions: options.providerOptions,
|
|
1972
|
-
schema:
|
|
2091
|
+
schema: googleVideoModelOptionsSchema
|
|
1973
2092
|
});
|
|
1974
2093
|
const instances = [{}];
|
|
1975
2094
|
const instance = instances[0];
|
|
@@ -2181,7 +2300,7 @@ var googleOperationSchema = z14.object({
|
|
|
2181
2300
|
}).nullish()
|
|
2182
2301
|
}).nullish()
|
|
2183
2302
|
});
|
|
2184
|
-
var
|
|
2303
|
+
var googleVideoModelOptionsSchema = lazySchema12(
|
|
2185
2304
|
() => zodSchema12(
|
|
2186
2305
|
z14.object({
|
|
2187
2306
|
pollIntervalMs: z14.number().positive().nullish(),
|