Skip to content
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