From cacef4dbaed930133c95413ea8506a623d53e4f4 Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Wed, 8 May 2024 18:15:27 -0400 Subject: [PATCH] [Vertex AI] Add basic checks for invalid model names --- FirebaseVertexAI/Sources/VertexAI.swift | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/FirebaseVertexAI/Sources/VertexAI.swift b/FirebaseVertexAI/Sources/VertexAI.swift index 2f9b069093b..d11ddea579d 100644 --- a/FirebaseVertexAI/Sources/VertexAI.swift +++ b/FirebaseVertexAI/Sources/VertexAI.swift @@ -44,9 +44,9 @@ public class VertexAI: NSObject { /// /// - Parameters: /// - app: The custom `FirebaseApp` used for initialization. - /// - location: The region identifier, defaulting to `us-central1`; see [Vertex AI regions - /// ](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions) - /// for a list of supported regions. + /// - location: The region identifier, defaulting to `us-central1`; see + /// [Vertex AI locations](https://firebase.google.com/docs/vertex-ai/locations?platform=ios) + /// for a list of supported locations. /// - Returns: A `VertexAI` instance, configured with the custom `FirebaseApp`. public static func vertexAI(app: FirebaseApp, location: String = "us-central1") -> VertexAI { guard let provider = ComponentType.instance(for: VertexAIProvider.self, @@ -117,18 +117,23 @@ public class VertexAI: NSObject { } private func modelResourceName(modelName: String, location: String) -> String { - if modelName.contains("/") { - return modelName - } guard let projectID = app.options.projectID else { fatalError("The Firebase app named \"\(app.name)\" has no project ID in its configuration.") } + guard !modelName.isEmpty && modelName + .allSatisfy({ !$0.isWhitespace && !$0.isNewline && $0 != "/" }) else { + fatalError(""" + Invalid model name "\(modelName)" specified; see \ + https://firebase.google.com/docs/vertex-ai/gemini-model#available-models for a list of \ + available models. + """) + } guard !location.isEmpty && location .allSatisfy({ !$0.isWhitespace && !$0.isNewline && $0 != "/" }) else { fatalError(""" Invalid location "\(location)" specified; see \ - https://cloud.google.com/vertex-ai/generative-ai/docs/learn/locations#available-regions for \ - a list of available regions. + https://firebase.google.com/docs/vertex-ai/locations?platform=ios for a list of available \ + locations. """) }