Skip to content

Commit 5dcf7aa

Browse files
[Vertex AI] Log warning for unsupported model names (#14610)
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
1 parent 0b5b990 commit 5dcf7aa

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

FirebaseVertexAI/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 11.11.0
2+
- [added] Emits a warning when attempting to use an incompatible model with
3+
`GenerativeModel` or `ImagenModel`. (#14610)
4+
15
# 11.10.0
26
- [feature] The Vertex AI SDK no longer requires `@preconcurrency` when imported in Swift 6.
37
- [feature] The Vertex AI Sample App now includes an image generation example.

FirebaseVertexAI/Sources/GenerativeModel.swift

+10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import Foundation
2020
/// content based on various input types.
2121
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
2222
public final class GenerativeModel: Sendable {
23+
/// Model name prefix to identify Gemini models.
24+
static let geminiModelNamePrefix = "gemini-"
25+
2326
/// The resource name of the model in the backend; has the format "models/model-name".
2427
let modelResourceName: String
2528

@@ -71,6 +74,13 @@ public final class GenerativeModel: Sendable {
7174
systemInstruction: ModelContent? = nil,
7275
requestOptions: RequestOptions,
7376
urlSession: URLSession = .shared) {
77+
if !name.starts(with: GenerativeModel.geminiModelNamePrefix) {
78+
VertexLog.warning(code: .unsupportedGeminiModel, """
79+
Unsupported Gemini model "\(name)"; see \
80+
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
81+
""")
82+
}
83+
7484
modelResourceName = name
7585
self.apiConfig = apiConfig
7686
generativeAIService = GenerativeAIService(

FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import Foundation
2828
/// could change in backwards-incompatible ways.
2929
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
3030
public final class ImagenModel {
31+
/// Model name prefix to identify Imagen models.
32+
static let imagenModelNamePrefix = "imagen-"
33+
3134
/// The resource name of the model in the backend; has the format "models/model-name".
3235
let modelResourceName: String
3336

@@ -51,6 +54,13 @@ public final class ImagenModel {
5154
safetySettings: ImagenSafetySettings?,
5255
requestOptions: RequestOptions,
5356
urlSession: URLSession = .shared) {
57+
if !name.starts(with: ImagenModel.imagenModelNamePrefix) {
58+
VertexLog.warning(code: .unsupportedImagenModel, """
59+
Unsupported Imagen model "\(name)"; see \
60+
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
61+
""")
62+
}
63+
5464
modelResourceName = name
5565
self.apiConfig = apiConfig
5666
generativeAIService = GenerativeAIService(

FirebaseVertexAI/Sources/VertexLog.swift

+2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ enum VertexLog {
3333

3434
// Generative Model Configuration
3535
case generativeModelInitialized = 1000
36+
case unsupportedGeminiModel = 1001
3637

3738
// Imagen Model Configuration
39+
case unsupportedImagenModel = 1200
3840
case imagenInvalidJPEGCompressionQuality = 1201
3941

4042
// Network Errors

0 commit comments

Comments
 (0)