diff --git a/FirebaseVertexAI/CHANGELOG.md b/FirebaseVertexAI/CHANGELOG.md index 2c84aaaafa3..cd38e2bec67 100644 --- a/FirebaseVertexAI/CHANGELOG.md +++ b/FirebaseVertexAI/CHANGELOG.md @@ -1,3 +1,7 @@ +# 11.11.0 +- [added] Emits a warning when attempting to use an incompatible model with + `GenerativeModel` or `ImagenModel`. (#14610) + # 11.10.0 - [feature] The Vertex AI SDK no longer requires `@preconcurrency` when imported in Swift 6. - [feature] The Vertex AI Sample App now includes an image generation example. diff --git a/FirebaseVertexAI/Sources/GenerativeModel.swift b/FirebaseVertexAI/Sources/GenerativeModel.swift index 3d37be52061..6df2620bc7f 100644 --- a/FirebaseVertexAI/Sources/GenerativeModel.swift +++ b/FirebaseVertexAI/Sources/GenerativeModel.swift @@ -20,6 +20,9 @@ import Foundation /// content based on various input types. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) public final class GenerativeModel: Sendable { + /// Model name prefix to identify Gemini models. + static let geminiModelNamePrefix = "gemini-" + /// The resource name of the model in the backend; has the format "models/model-name". let modelResourceName: String @@ -71,6 +74,13 @@ public final class GenerativeModel: Sendable { systemInstruction: ModelContent? = nil, requestOptions: RequestOptions, urlSession: URLSession = .shared) { + if !name.starts(with: GenerativeModel.geminiModelNamePrefix) { + VertexLog.warning(code: .unsupportedGeminiModel, """ + Unsupported Gemini model "\(name)"; see \ + https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names. + """) + } + modelResourceName = name self.apiConfig = apiConfig generativeAIService = GenerativeAIService( diff --git a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift index f0224ec8fdb..13b0b0dba35 100644 --- a/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift +++ b/FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift @@ -28,6 +28,9 @@ import Foundation /// could change in backwards-incompatible ways. @available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *) public final class ImagenModel { + /// Model name prefix to identify Imagen models. + static let imagenModelNamePrefix = "imagen-" + /// The resource name of the model in the backend; has the format "models/model-name". let modelResourceName: String @@ -51,6 +54,13 @@ public final class ImagenModel { safetySettings: ImagenSafetySettings?, requestOptions: RequestOptions, urlSession: URLSession = .shared) { + if !name.starts(with: ImagenModel.imagenModelNamePrefix) { + VertexLog.warning(code: .unsupportedImagenModel, """ + Unsupported Imagen model "\(name)"; see \ + https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names. + """) + } + modelResourceName = name self.apiConfig = apiConfig generativeAIService = GenerativeAIService( diff --git a/FirebaseVertexAI/Sources/VertexLog.swift b/FirebaseVertexAI/Sources/VertexLog.swift index 9332aa87961..ff94a2d435e 100644 --- a/FirebaseVertexAI/Sources/VertexLog.swift +++ b/FirebaseVertexAI/Sources/VertexLog.swift @@ -33,8 +33,10 @@ enum VertexLog { // Generative Model Configuration case generativeModelInitialized = 1000 + case unsupportedGeminiModel = 1001 // Imagen Model Configuration + case unsupportedImagenModel = 1200 case imagenInvalidJPEGCompressionQuality = 1201 // Network Errors