Skip to content

Commit fbab9fc

Browse files
rlazotejasd
authored andcommitted
[VertexAI] Log warning for unsupported model names (#6805)
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 a4727f0 commit fbab9fc

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
* [changed] **Breaking Change**: `ImagenInlineImage.data` now returns the raw

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,
@@ -103,6 +113,15 @@ internal constructor(
103113
if (location.trim().isEmpty() || location.contains("/")) {
104114
throw InvalidLocationException(location)
105115
}
116+
if (!modelName.startsWith(IMAGEN_MODEL_NAME_PREFIX)) {
117+
Log.w(
118+
TAG,
119+
"""Unsupported Imagen model "${modelName}"; see
120+
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
121+
"""
122+
.trimIndent()
123+
)
124+
}
106125
return ImagenModel(
107126
"projects/${firebaseApp.options.projectId}/locations/${location}/publishers/google/models/${modelName}",
108127
firebaseApp.options.apiKey,
@@ -136,6 +155,12 @@ internal constructor(
136155
val multiResourceComponent = app[FirebaseVertexAIMultiResourceComponent::class.java]
137156
return multiResourceComponent.get(location)
138157
}
158+
159+
private const val GEMINI_MODEL_NAME_PREFIX = "gemini-"
160+
161+
private const val IMAGEN_MODEL_NAME_PREFIX = "imagen-"
162+
163+
private val TAG = FirebaseVertexAI::class.java.simpleName
139164
}
140165
}
141166

0 commit comments

Comments
 (0)