Skip to content

[VertexAI] Log warning for unsupported model names #6805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions firebase-vertexai/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Unreleased
* [feature] Emits a warning when attempting to use an incompatible model with
`GenerativeModel` or `ImagenModel`.
* [changed] Added new exception type for quota exceeded scenarios.
* [feature] `CountTokenRequest` now includes `GenerationConfig` from the model.
* [changed] **Breaking Change**: `ImagenInlineImage.data` now returns the raw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.firebase.vertexai

import android.util.Log
import com.google.firebase.Firebase
import com.google.firebase.FirebaseApp
import com.google.firebase.app
Expand Down Expand Up @@ -68,6 +69,15 @@ internal constructor(
if (location.trim().isEmpty() || location.contains("/")) {
throw InvalidLocationException(location)
}
if (!modelName.startsWith(GEMINI_MODEL_NAME_PREFIX)) {
Log.w(
TAG,
"""Unsupported Gemini model "${modelName}"; see
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
"""
.trimIndent()
)
}
return GenerativeModel(
"projects/${firebaseApp.options.projectId}/locations/${location}/publishers/google/models/${modelName}",
firebaseApp.options.apiKey,
Expand Down Expand Up @@ -103,6 +113,15 @@ internal constructor(
if (location.trim().isEmpty() || location.contains("/")) {
throw InvalidLocationException(location)
}
if (!modelName.startsWith(IMAGEN_MODEL_NAME_PREFIX)) {
Log.w(
TAG,
"""Unsupported Imagen model "${modelName}"; see
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
"""
.trimIndent()
)
}
return ImagenModel(
"projects/${firebaseApp.options.projectId}/locations/${location}/publishers/google/models/${modelName}",
firebaseApp.options.apiKey,
Expand Down Expand Up @@ -136,6 +155,12 @@ internal constructor(
val multiResourceComponent = app[FirebaseVertexAIMultiResourceComponent::class.java]
return multiResourceComponent.get(location)
}

private const val GEMINI_MODEL_NAME_PREFIX = "gemini-"

private const val IMAGEN_MODEL_NAME_PREFIX = "imagen-"

private val TAG = FirebaseVertexAI::class.java.simpleName
}
}

Expand Down
Loading