@ai-sdk/google 3.0.25 → 3.0.27
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +125 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +127 -8
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +2 -2
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +2 -2
- package/dist/internal/index.mjs.map +1 -1
- package/docs/15-google-generative-ai.mdx +93 -4
- package/package.json +1 -1
- package/src/convert-to-google-generative-ai-messages.ts +5 -1
- package/src/google-generative-ai-image-model.ts +172 -7
- package/src/google-generative-ai-image-settings.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 3.0.27
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 051361b: fix(vertex): add fallback for providerOptions keyname
|
|
8
|
+
|
|
9
|
+
## 3.0.26
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 4c27179: feat(google): allow using Gemini image models with `generateImage`
|
|
14
|
+
|
|
3
15
|
## 3.0.25
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -160,7 +160,7 @@ interface GoogleGenerativeAIProviderMetadata {
|
|
|
160
160
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | (string & {});
|
|
163
|
+
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | (string & {});
|
|
164
164
|
interface GoogleGenerativeAIImageSettings {
|
|
165
165
|
/**
|
|
166
166
|
* Override the maximum number of images per call (default 4)
|
package/dist/index.d.ts
CHANGED
|
@@ -160,7 +160,7 @@ interface GoogleGenerativeAIProviderMetadata {
|
|
|
160
160
|
safetyRatings: GoogleGenerativeAISafetyRating[] | null;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | (string & {});
|
|
163
|
+
type GoogleGenerativeAIImageModelId = 'imagen-4.0-generate-001' | 'imagen-4.0-ultra-generate-001' | 'imagen-4.0-fast-generate-001' | 'gemini-2.5-flash-image' | 'gemini-3-pro-image-preview' | (string & {});
|
|
164
164
|
interface GoogleGenerativeAIImageSettings {
|
|
165
165
|
/**
|
|
166
166
|
* Override the maximum number of images per call (default 4)
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
30
30
|
var import_provider_utils16 = require("@ai-sdk/provider-utils");
|
|
31
31
|
|
|
32
32
|
// src/version.ts
|
|
33
|
-
var VERSION = true ? "3.0.
|
|
33
|
+
var VERSION = true ? "3.0.27" : "0.0.0-test";
|
|
34
34
|
|
|
35
35
|
// src/google-generative-ai-embedding-model.ts
|
|
36
36
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -419,8 +419,8 @@ function convertToGoogleGenerativeAIMessages(prompt, options) {
|
|
|
419
419
|
contents.push({
|
|
420
420
|
role: "model",
|
|
421
421
|
parts: content.map((part) => {
|
|
422
|
-
var _a2;
|
|
423
|
-
const providerOpts = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName];
|
|
422
|
+
var _a2, _b2, _c2;
|
|
423
|
+
const providerOpts = (_c2 = (_a2 = part.providerOptions) == null ? void 0 : _a2[providerOptionsName]) != null ? _c2 : providerOptionsName !== "google" ? (_b2 = part.providerOptions) == null ? void 0 : _b2.google : void 0;
|
|
424
424
|
const thoughtSignature = (providerOpts == null ? void 0 : providerOpts.thoughtSignature) != null ? String(providerOpts.thoughtSignature) : void 0;
|
|
425
425
|
switch (part.type) {
|
|
426
426
|
case "text": {
|
|
@@ -1786,13 +1786,24 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1786
1786
|
this.specificationVersion = "v3";
|
|
1787
1787
|
}
|
|
1788
1788
|
get maxImagesPerCall() {
|
|
1789
|
-
|
|
1790
|
-
|
|
1789
|
+
if (this.settings.maxImagesPerCall != null) {
|
|
1790
|
+
return this.settings.maxImagesPerCall;
|
|
1791
|
+
}
|
|
1792
|
+
if (isGeminiModel(this.modelId)) {
|
|
1793
|
+
return 10;
|
|
1794
|
+
}
|
|
1795
|
+
return 4;
|
|
1791
1796
|
}
|
|
1792
1797
|
get provider() {
|
|
1793
1798
|
return this.config.provider;
|
|
1794
1799
|
}
|
|
1795
1800
|
async doGenerate(options) {
|
|
1801
|
+
if (isGeminiModel(this.modelId)) {
|
|
1802
|
+
return this.doGenerateGemini(options);
|
|
1803
|
+
}
|
|
1804
|
+
return this.doGenerateImagen(options);
|
|
1805
|
+
}
|
|
1806
|
+
async doGenerateImagen(options) {
|
|
1796
1807
|
var _a, _b, _c;
|
|
1797
1808
|
const {
|
|
1798
1809
|
prompt,
|
|
@@ -1809,7 +1820,7 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1809
1820
|
const warnings = [];
|
|
1810
1821
|
if (files != null && files.length > 0) {
|
|
1811
1822
|
throw new Error(
|
|
1812
|
-
"Google Generative AI does not support image editing. Use Google Vertex AI (@ai-sdk/google-vertex) for image editing capabilities."
|
|
1823
|
+
"Google Generative AI does not support image editing with Imagen models. Use Google Vertex AI (@ai-sdk/google-vertex) for image editing capabilities."
|
|
1813
1824
|
);
|
|
1814
1825
|
}
|
|
1815
1826
|
if (mask != null) {
|
|
@@ -1865,10 +1876,10 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1865
1876
|
images: response.predictions.map(
|
|
1866
1877
|
(p) => p.bytesBase64Encoded
|
|
1867
1878
|
),
|
|
1868
|
-
warnings
|
|
1879
|
+
warnings,
|
|
1869
1880
|
providerMetadata: {
|
|
1870
1881
|
google: {
|
|
1871
|
-
images: response.predictions.map((
|
|
1882
|
+
images: response.predictions.map(() => ({
|
|
1872
1883
|
// Add any prediction-specific metadata here
|
|
1873
1884
|
}))
|
|
1874
1885
|
}
|
|
@@ -1880,7 +1891,113 @@ var GoogleGenerativeAIImageModel = class {
|
|
|
1880
1891
|
}
|
|
1881
1892
|
};
|
|
1882
1893
|
}
|
|
1894
|
+
async doGenerateGemini(options) {
|
|
1895
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1896
|
+
const {
|
|
1897
|
+
prompt,
|
|
1898
|
+
n,
|
|
1899
|
+
size,
|
|
1900
|
+
aspectRatio,
|
|
1901
|
+
seed,
|
|
1902
|
+
providerOptions,
|
|
1903
|
+
headers,
|
|
1904
|
+
abortSignal,
|
|
1905
|
+
files,
|
|
1906
|
+
mask
|
|
1907
|
+
} = options;
|
|
1908
|
+
const warnings = [];
|
|
1909
|
+
if (mask != null) {
|
|
1910
|
+
throw new Error(
|
|
1911
|
+
"Gemini image models do not support mask-based image editing."
|
|
1912
|
+
);
|
|
1913
|
+
}
|
|
1914
|
+
if (n != null && n > 1) {
|
|
1915
|
+
throw new Error(
|
|
1916
|
+
"Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter."
|
|
1917
|
+
);
|
|
1918
|
+
}
|
|
1919
|
+
if (size != null) {
|
|
1920
|
+
warnings.push({
|
|
1921
|
+
type: "unsupported",
|
|
1922
|
+
feature: "size",
|
|
1923
|
+
details: "This model does not support the `size` option. Use `aspectRatio` instead."
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
const userContent = [];
|
|
1927
|
+
if (prompt != null) {
|
|
1928
|
+
userContent.push({ type: "text", text: prompt });
|
|
1929
|
+
}
|
|
1930
|
+
if (files != null && files.length > 0) {
|
|
1931
|
+
for (const file of files) {
|
|
1932
|
+
if (file.type === "url") {
|
|
1933
|
+
userContent.push({
|
|
1934
|
+
type: "file",
|
|
1935
|
+
data: new URL(file.url),
|
|
1936
|
+
mediaType: "image/*"
|
|
1937
|
+
});
|
|
1938
|
+
} else {
|
|
1939
|
+
userContent.push({
|
|
1940
|
+
type: "file",
|
|
1941
|
+
data: typeof file.data === "string" ? file.data : new Uint8Array(file.data),
|
|
1942
|
+
mediaType: file.mediaType
|
|
1943
|
+
});
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
const languageModelPrompt = [
|
|
1948
|
+
{ role: "user", content: userContent }
|
|
1949
|
+
];
|
|
1950
|
+
const languageModel = new GoogleGenerativeAILanguageModel(this.modelId, {
|
|
1951
|
+
provider: this.config.provider,
|
|
1952
|
+
baseURL: this.config.baseURL,
|
|
1953
|
+
headers: (_a = this.config.headers) != null ? _a : {},
|
|
1954
|
+
fetch: this.config.fetch,
|
|
1955
|
+
generateId: (_b = this.config.generateId) != null ? _b : import_provider_utils14.generateId
|
|
1956
|
+
});
|
|
1957
|
+
const result = await languageModel.doGenerate({
|
|
1958
|
+
prompt: languageModelPrompt,
|
|
1959
|
+
seed,
|
|
1960
|
+
providerOptions: {
|
|
1961
|
+
google: {
|
|
1962
|
+
responseModalities: ["IMAGE"],
|
|
1963
|
+
imageConfig: aspectRatio ? { aspectRatio } : void 0,
|
|
1964
|
+
...(_c = providerOptions == null ? void 0 : providerOptions.google) != null ? _c : {}
|
|
1965
|
+
}
|
|
1966
|
+
},
|
|
1967
|
+
headers,
|
|
1968
|
+
abortSignal
|
|
1969
|
+
});
|
|
1970
|
+
const currentDate = (_f = (_e = (_d = this.config._internal) == null ? void 0 : _d.currentDate) == null ? void 0 : _e.call(_d)) != null ? _f : /* @__PURE__ */ new Date();
|
|
1971
|
+
const images = [];
|
|
1972
|
+
for (const part of result.content) {
|
|
1973
|
+
if (part.type === "file" && part.mediaType.startsWith("image/")) {
|
|
1974
|
+
images.push((0, import_provider_utils14.convertToBase64)(part.data));
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
return {
|
|
1978
|
+
images,
|
|
1979
|
+
warnings,
|
|
1980
|
+
providerMetadata: {
|
|
1981
|
+
google: {
|
|
1982
|
+
images: images.map(() => ({}))
|
|
1983
|
+
}
|
|
1984
|
+
},
|
|
1985
|
+
response: {
|
|
1986
|
+
timestamp: currentDate,
|
|
1987
|
+
modelId: this.modelId,
|
|
1988
|
+
headers: (_g = result.response) == null ? void 0 : _g.headers
|
|
1989
|
+
},
|
|
1990
|
+
usage: result.usage ? {
|
|
1991
|
+
inputTokens: result.usage.inputTokens.total,
|
|
1992
|
+
outputTokens: result.usage.outputTokens.total,
|
|
1993
|
+
totalTokens: ((_h = result.usage.inputTokens.total) != null ? _h : 0) + ((_i = result.usage.outputTokens.total) != null ? _i : 0)
|
|
1994
|
+
} : void 0
|
|
1995
|
+
};
|
|
1996
|
+
}
|
|
1883
1997
|
};
|
|
1998
|
+
function isGeminiModel(modelId) {
|
|
1999
|
+
return modelId.startsWith("gemini-");
|
|
2000
|
+
}
|
|
1884
2001
|
var googleImageResponseSchema = (0, import_provider_utils14.lazySchema)(
|
|
1885
2002
|
() => (0, import_provider_utils14.zodSchema)(
|
|
1886
2003
|
import_v413.z.object({
|