| 
16 | 16 | 
 
  | 
17 | 17 | package com.google.firebase.vertexai  | 
18 | 18 | 
 
  | 
 | 19 | +import android.util.Log  | 
19 | 20 | import com.google.firebase.Firebase  | 
20 | 21 | import com.google.firebase.FirebaseApp  | 
21 | 22 | import com.google.firebase.app  | 
@@ -69,6 +70,15 @@ internal constructor(  | 
69 | 70 |     if (location.trim().isEmpty() || location.contains("/")) {  | 
70 | 71 |       throw InvalidLocationException(location)  | 
71 | 72 |     }  | 
 | 73 | +    if (!modelName.startsWith(GEMINI_MODEL_NAME_PREFIX)) {  | 
 | 74 | +      Log.w(  | 
 | 75 | +        TAG,  | 
 | 76 | +        """Unsupported Gemini model "${modelName}"; see  | 
 | 77 | +      https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.  | 
 | 78 | +      """  | 
 | 79 | +          .trimIndent()  | 
 | 80 | +      )  | 
 | 81 | +    }  | 
72 | 82 |     return GenerativeModel(  | 
73 | 83 |       "projects/${firebaseApp.options.projectId}/locations/${location}/publishers/google/models/${modelName}",  | 
74 | 84 |       firebaseApp.options.apiKey,  | 
@@ -140,6 +150,15 @@ internal constructor(  | 
140 | 150 |     if (location.trim().isEmpty() || location.contains("/")) {  | 
141 | 151 |       throw InvalidLocationException(location)  | 
142 | 152 |     }  | 
 | 153 | +    if (!modelName.startsWith(IMAGEN_MODEL_NAME_PREFIX)) {  | 
 | 154 | +      Log.w(  | 
 | 155 | +        TAG,  | 
 | 156 | +        """Unsupported Imagen model "${modelName}"; see  | 
 | 157 | +      https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.  | 
 | 158 | +      """  | 
 | 159 | +          .trimIndent()  | 
 | 160 | +      )  | 
 | 161 | +    }  | 
143 | 162 |     return ImagenModel(  | 
144 | 163 |       "projects/${firebaseApp.options.projectId}/locations/${location}/publishers/google/models/${modelName}",  | 
145 | 164 |       firebaseApp.options.apiKey,  | 
@@ -173,6 +192,12 @@ internal constructor(  | 
173 | 192 |       val multiResourceComponent = app[FirebaseVertexAIMultiResourceComponent::class.java]  | 
174 | 193 |       return multiResourceComponent.get(location)  | 
175 | 194 |     }  | 
 | 195 | + | 
 | 196 | +    private const val GEMINI_MODEL_NAME_PREFIX = "gemini-"  | 
 | 197 | + | 
 | 198 | +    private const val IMAGEN_MODEL_NAME_PREFIX = "imagen-"  | 
 | 199 | + | 
 | 200 | +    private val TAG = FirebaseVertexAI::class.java.simpleName  | 
176 | 201 |   }  | 
177 | 202 | }  | 
178 | 203 | 
 
  | 
 | 
0 commit comments