Skip to content

Commit cacef4d

Browse files
committed
[Vertex AI] Add basic checks for invalid model names
1 parent 5b82827 commit cacef4d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

FirebaseVertexAI/Sources/VertexAI.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public class VertexAI: NSObject {
4444
///
4545
/// - Parameters:
4646
/// - app: The custom `FirebaseApp` used for initialization.
47-
/// - location: The region identifier, defaulting to `us-central1`; see [Vertex AI regions
48-
/// ](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions)
49-
/// for a list of supported regions.
47+
/// - location: The region identifier, defaulting to `us-central1`; see
48+
/// [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios)
49+
/// for a list of supported locations.
5050
/// - Returns: A `VertexAI` instance, configured with the custom `FirebaseApp`.
5151
public static func vertexAI(app: FirebaseApp, location: String = "us-central1") -> VertexAI {
5252
guard let provider = ComponentType<VertexAIProvider>.instance(for: VertexAIProvider.self,
@@ -117,18 +117,23 @@ public class VertexAI: NSObject {
117117
}
118118

119119
private func modelResourceName(modelName: String, location: String) -> String {
120-
if modelName.contains("/") {
121-
return modelName
122-
}
123120
guard let projectID = app.options.projectID else {
124121
fatalError("The Firebase app named \"\(app.name)\" has no project ID in its configuration.")
125122
}
123+
guard !modelName.isEmpty && modelName
124+
.allSatisfy({ !$0.isWhitespace && !$0.isNewline && $0 != "/" }) else {
125+
fatalError("""
126+
Invalid model name "\(modelName)" specified; see \
127+
https://firebase.google.com/docs/vertex-ai/gemini-model#available-models for a list of \
128+
available models.
129+
""")
130+
}
126131
guard !location.isEmpty && location
127132
.allSatisfy({ !$0.isWhitespace && !$0.isNewline && $0 != "/" }) else {
128133
fatalError("""
129134
Invalid location "\(location)" specified; see \
130-
https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for \
131-
a list of available regions.
135+
https://firebase.google.com/docs/vertex-ai/locations?platform=ios for a list of available \
136+
locations.
132137
""")
133138
}
134139

0 commit comments

Comments
 (0)