Skip to content

Commit e751bfe

Browse files
committed
[VertexAI] Log warning for unsupported model names
Added a warning message to the initializers of GenerativeModel and ImagenModel that is logged when the provided model name does not start with the expected prefix ("gemini-" for GenerativeModel and "imagen-" for ImagenModel). The warning message includes a link to the documentation for supported models. Note: No error is thrown in case the naming scheme is changed in the future, though we would want to update the logic/message at that time. Related iOS PR firebase/firebase-ios-sdk#14610
1 parent ba69975 commit e751bfe

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

firebase-vertexai/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# Unreleased
2+
* [feature] Emits a warning when attempting to use an incompatible model with
3+
`GenerativeModel` or `ImagenModel`.
24
* [changed] Added new exception type for quota exceeded scenarios.
35
* [feature] `CountTokenRequest` now includes `GenerationConfig` from the model.
46

firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseVertexAI.kt

+25
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.firebase.vertexai
1818

19+
import android.util.Log
1920
import com.google.firebase.Firebase
2021
import com.google.firebase.FirebaseApp
2122
import com.google.firebase.app
@@ -68,6 +69,15 @@ internal constructor(
6869
if (location.trim().isEmpty() || location.contains("/")) {
6970
throw InvalidLocationException(location)
7071
}
72+
if (!modelName.startsWith(GEMINI_MODEL_NAME_PREFIX)) {
73+
Log.w(
74+
TAG,
75+
"""Unsupported Gemini model "${modelName}"; see
76+
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
77+
"""
78+
.trimIndent()
79+
)
80+
}
7181
return GenerativeModel(
7282
"projects/${firebaseApp.options.projectId}/locations/${location}/publishers/google/models/${modelName}",
7383
firebaseApp.options.apiKey,
@@ -102,6 +112,15 @@ internal constructor(
102112
if (location.trim().isEmpty() || location.contains("/")) {
103113
throw InvalidLocationException(location)
104114
}
115+
if (!modelName.startsWith(IMAGEN_MODEL_NAME_PREFIX)) {
116+
Log.w(
117+
TAG,
118+
"""Unsupported Imagen model "${modelName}"; see
119+
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
120+
"""
121+
.trimIndent()
122+
)
123+
}
105124
return ImagenModel(
106125
"projects/${firebaseApp.options.projectId}/locations/${location}/publishers/google/models/${modelName}",
107126
firebaseApp.options.apiKey,
@@ -134,6 +153,12 @@ internal constructor(
134153
val multiResourceComponent = app[FirebaseVertexAIMultiResourceComponent::class.java]
135154
return multiResourceComponent.get(location)
136155
}
156+
157+
private const val GEMINI_MODEL_NAME_PREFIX = "gemini-"
158+
159+
private const val IMAGEN_MODEL_NAME_PREFIX = "imagen-"
160+
161+
private val TAG = FirebaseVertexAI::class.java.simpleName
137162
}
138163
}
139164

0 commit comments

Comments
 (0)