@ai-sdk/google-vertex
Advanced tools
Comparing version 2.0.10 to 2.0.11
# @ai-sdk/google-vertex | ||
## 2.0.11 | ||
### Patch Changes | ||
- 5feec50: feat (provider/google-vertex): Add imagen support. | ||
## 2.0.10 | ||
@@ -4,0 +10,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider'; | ||
import { ProviderV1, LanguageModelV1, ImageModelV1 } from '@ai-sdk/provider'; | ||
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils'; | ||
@@ -10,2 +10,4 @@ import { InternalGoogleGenerativeAISettings } from '@ai-sdk/google/internal'; | ||
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-fast-generate-001'; | ||
interface GoogleVertexProvider extends ProviderV1 { | ||
@@ -17,2 +19,6 @@ /** | ||
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) => LanguageModelV1; | ||
/** | ||
* Creates a model for image generation. | ||
*/ | ||
image(modelId: GoogleVertexImageModelId): ImageModelV1; | ||
} | ||
@@ -19,0 +25,0 @@ interface GoogleVertexProviderSettings$1 { |
@@ -50,3 +50,3 @@ "use strict"; | ||
// src/google-vertex-provider.ts | ||
var import_provider_utils3 = require("@ai-sdk/provider-utils"); | ||
var import_provider_utils4 = require("@ai-sdk/provider-utils"); | ||
@@ -154,4 +154,61 @@ // src/google-vertex-embedding-model.ts | ||
var import_internal = require("@ai-sdk/google/internal"); | ||
// src/google-vertex-image-model.ts | ||
var import_provider_utils3 = require("@ai-sdk/provider-utils"); | ||
var import_zod3 = require("zod"); | ||
var GoogleVertexImageModel = class { | ||
constructor(modelId, config) { | ||
this.modelId = modelId; | ||
this.config = config; | ||
this.specificationVersion = "v1"; | ||
} | ||
get provider() { | ||
return this.config.provider; | ||
} | ||
async doGenerate({ | ||
prompt, | ||
n, | ||
size, | ||
providerOptions, | ||
headers, | ||
abortSignal | ||
}) { | ||
var _a; | ||
if (size) { | ||
throw new Error( | ||
"Google Vertex does not support the `size` option. Use `providerOptions.vertex.aspectRatio` instead. See https://cloud.google.com/vertex-ai/generative-ai/docs/image/generate-images#aspect-ratio" | ||
); | ||
} | ||
const body = { | ||
instances: [{ prompt }], | ||
parameters: { | ||
sampleCount: n, | ||
...(_a = providerOptions.vertex) != null ? _a : {} | ||
} | ||
}; | ||
const { value: response } = await (0, import_provider_utils3.postJsonToApi)({ | ||
url: `${this.config.baseURL}/models/${this.modelId}:predict`, | ||
headers: (0, import_provider_utils3.combineHeaders)(await (0, import_provider_utils3.resolve)(this.config.headers), headers), | ||
body, | ||
failedResponseHandler: googleVertexFailedResponseHandler, | ||
successfulResponseHandler: (0, import_provider_utils3.createJsonResponseHandler)( | ||
vertexImageResponseSchema | ||
), | ||
abortSignal, | ||
fetch: this.config.fetch | ||
}); | ||
return { | ||
images: response.predictions.map( | ||
(p) => p.bytesBase64Encoded | ||
) | ||
}; | ||
} | ||
}; | ||
var vertexImageResponseSchema = import_zod3.z.object({ | ||
predictions: import_zod3.z.array(import_zod3.z.object({ bytesBase64Encoded: import_zod3.z.string() })) | ||
}); | ||
// src/google-vertex-provider.ts | ||
function createVertex(options = {}) { | ||
const loadVertexProject = () => (0, import_provider_utils3.loadSetting)({ | ||
const loadVertexProject = () => (0, import_provider_utils4.loadSetting)({ | ||
settingValue: options.project, | ||
@@ -162,3 +219,3 @@ settingName: "project", | ||
}); | ||
const loadVertexLocation = () => (0, import_provider_utils3.loadSetting)({ | ||
const loadVertexLocation = () => (0, import_provider_utils4.loadSetting)({ | ||
settingValue: options.location, | ||
@@ -173,3 +230,3 @@ settingName: "location", | ||
const project = loadVertexProject(); | ||
return (_a = (0, import_provider_utils3.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${region}-aiplatform.googleapis.com/v1/projects/${project}/locations/${region}/publishers/google`; | ||
return (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${region}-aiplatform.googleapis.com/v1/projects/${project}/locations/${region}/publishers/google`; | ||
}; | ||
@@ -181,3 +238,3 @@ const createChatModel = (modelId, settings = {}) => { | ||
headers: (_a = options.headers) != null ? _a : {}, | ||
generateId: (_b = options.generateId) != null ? _b : import_provider_utils3.generateId, | ||
generateId: (_b = options.generateId) != null ? _b : import_provider_utils4.generateId, | ||
fetch: options.fetch, | ||
@@ -197,2 +254,11 @@ baseURL: loadBaseURL() | ||
}; | ||
const createImageModel = (modelId) => { | ||
var _a; | ||
return new GoogleVertexImageModel(modelId, { | ||
provider: `google.vertex.image`, | ||
baseURL: loadBaseURL(), | ||
headers: (_a = options.headers) != null ? _a : {}, | ||
fetch: options.fetch | ||
}); | ||
}; | ||
const provider = function(modelId, settings) { | ||
@@ -208,2 +274,3 @@ if (new.target) { | ||
provider.textEmbeddingModel = createEmbeddingModel; | ||
provider.image = createImageModel; | ||
return provider; | ||
@@ -210,0 +277,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider'; | ||
import { ProviderV1, LanguageModelV1, ImageModelV1 } from '@ai-sdk/provider'; | ||
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils'; | ||
@@ -27,2 +27,4 @@ import { InternalGoogleGenerativeAISettings } from '@ai-sdk/google/internal'; | ||
type GoogleVertexImageModelId = 'imagen-3.0-generate-001' | 'imagen-3.0-fast-generate-001'; | ||
interface GoogleVertexProvider extends ProviderV1 { | ||
@@ -34,2 +36,6 @@ /** | ||
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) => LanguageModelV1; | ||
/** | ||
* Creates a model for image generation. | ||
*/ | ||
image(modelId: GoogleVertexImageModelId): ImageModelV1; | ||
} | ||
@@ -36,0 +42,0 @@ interface GoogleVertexProviderSettings$1 { |
@@ -131,3 +131,3 @@ "use strict"; | ||
// src/google-vertex-provider.ts | ||
var import_provider_utils4 = require("@ai-sdk/provider-utils"); | ||
var import_provider_utils5 = require("@ai-sdk/provider-utils"); | ||
@@ -235,4 +235,61 @@ // src/google-vertex-embedding-model.ts | ||
var import_internal = require("@ai-sdk/google/internal"); | ||
// src/google-vertex-image-model.ts | ||
var import_provider_utils4 = require("@ai-sdk/provider-utils"); | ||
var import_zod3 = require("zod"); | ||
var GoogleVertexImageModel = class { | ||
constructor(modelId, config) { | ||
this.modelId = modelId; | ||
this.config = config; | ||
this.specificationVersion = "v1"; | ||
} | ||
get provider() { | ||
return this.config.provider; | ||
} | ||
async doGenerate({ | ||
prompt, | ||
n, | ||
size, | ||
providerOptions, | ||
headers, | ||
abortSignal | ||
}) { | ||
var _a; | ||
if (size) { | ||
throw new Error( | ||
"Google Vertex does not support the `size` option. Use `providerOptions.vertex.aspectRatio` instead. See https://cloud.google.com/vertex-ai/generative-ai/docs/image/generate-images#aspect-ratio" | ||
); | ||
} | ||
const body = { | ||
instances: [{ prompt }], | ||
parameters: { | ||
sampleCount: n, | ||
...(_a = providerOptions.vertex) != null ? _a : {} | ||
} | ||
}; | ||
const { value: response } = await (0, import_provider_utils4.postJsonToApi)({ | ||
url: `${this.config.baseURL}/models/${this.modelId}:predict`, | ||
headers: (0, import_provider_utils4.combineHeaders)(await (0, import_provider_utils4.resolve)(this.config.headers), headers), | ||
body, | ||
failedResponseHandler: googleVertexFailedResponseHandler, | ||
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)( | ||
vertexImageResponseSchema | ||
), | ||
abortSignal, | ||
fetch: this.config.fetch | ||
}); | ||
return { | ||
images: response.predictions.map( | ||
(p) => p.bytesBase64Encoded | ||
) | ||
}; | ||
} | ||
}; | ||
var vertexImageResponseSchema = import_zod3.z.object({ | ||
predictions: import_zod3.z.array(import_zod3.z.object({ bytesBase64Encoded: import_zod3.z.string() })) | ||
}); | ||
// src/google-vertex-provider.ts | ||
function createVertex(options = {}) { | ||
const loadVertexProject = () => (0, import_provider_utils4.loadSetting)({ | ||
const loadVertexProject = () => (0, import_provider_utils5.loadSetting)({ | ||
settingValue: options.project, | ||
@@ -243,3 +300,3 @@ settingName: "project", | ||
}); | ||
const loadVertexLocation = () => (0, import_provider_utils4.loadSetting)({ | ||
const loadVertexLocation = () => (0, import_provider_utils5.loadSetting)({ | ||
settingValue: options.location, | ||
@@ -254,3 +311,3 @@ settingName: "location", | ||
const project = loadVertexProject(); | ||
return (_a = (0, import_provider_utils4.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${region}-aiplatform.googleapis.com/v1/projects/${project}/locations/${region}/publishers/google`; | ||
return (_a = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL)) != null ? _a : `https://${region}-aiplatform.googleapis.com/v1/projects/${project}/locations/${region}/publishers/google`; | ||
}; | ||
@@ -262,3 +319,3 @@ const createChatModel = (modelId, settings = {}) => { | ||
headers: (_a = options.headers) != null ? _a : {}, | ||
generateId: (_b = options.generateId) != null ? _b : import_provider_utils4.generateId, | ||
generateId: (_b = options.generateId) != null ? _b : import_provider_utils5.generateId, | ||
fetch: options.fetch, | ||
@@ -278,2 +335,11 @@ baseURL: loadBaseURL() | ||
}; | ||
const createImageModel = (modelId) => { | ||
var _a; | ||
return new GoogleVertexImageModel(modelId, { | ||
provider: `google.vertex.image`, | ||
baseURL: loadBaseURL(), | ||
headers: (_a = options.headers) != null ? _a : {}, | ||
fetch: options.fetch | ||
}); | ||
}; | ||
const provider = function(modelId, settings) { | ||
@@ -289,2 +355,3 @@ if (new.target) { | ||
provider.textEmbeddingModel = createEmbeddingModel; | ||
provider.image = createImageModel; | ||
return provider; | ||
@@ -291,0 +358,0 @@ } |
{ | ||
"name": "@ai-sdk/google-vertex", | ||
"version": "2.0.10", | ||
"version": "2.0.11", | ||
"license": "Apache-2.0", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
232156
2124