Skip to content

Commit 7facac9

Browse files
committed
[Vertex AI] Fix unsupported model name check introduced in #14610
1 parent 5dcf7aa commit 7facac9

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

FirebaseVertexAI/Sources/GenerativeModel.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public final class GenerativeModel: Sendable {
5353
/// Initializes a new remote model with the given parameters.
5454
///
5555
/// - Parameters:
56-
/// - name: The name of the model to use, for example `"gemini-1.0-pro"`.
56+
/// - modelResourceName: The resource name of the model to use, for example
57+
/// `"projects/{project-id}/locations/{location-id}/publishers/google/models/{model-name}"`.
5758
/// - firebaseInfo: Firebase data used by the SDK, including project ID and API key.
5859
/// - apiConfig: Configuration for the backend API used by this model.
5960
/// - generationConfig: The content generation parameters your model should use.
@@ -64,7 +65,7 @@ public final class GenerativeModel: Sendable {
6465
/// only text content is supported.
6566
/// - requestOptions: Configuration parameters for sending requests to the backend.
6667
/// - urlSession: The `URLSession` to use for requests; defaults to `URLSession.shared`.
67-
init(name: String,
68+
init(modelResourceName: String,
6869
firebaseInfo: FirebaseInfo,
6970
apiConfig: APIConfig,
7071
generationConfig: GenerationConfig? = nil,
@@ -74,14 +75,7 @@ public final class GenerativeModel: Sendable {
7475
systemInstruction: ModelContent? = nil,
7576
requestOptions: RequestOptions,
7677
urlSession: URLSession = .shared) {
77-
if !name.starts(with: GenerativeModel.geminiModelNamePrefix) {
78-
VertexLog.warning(code: .unsupportedGeminiModel, """
79-
Unsupported Gemini model "\(name)"; see \
80-
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
81-
""")
82-
}
83-
84-
modelResourceName = name
78+
self.modelResourceName = modelResourceName
8579
self.apiConfig = apiConfig
8680
generativeAIService = GenerativeAIService(
8781
firebaseInfo: firebaseInfo,
@@ -108,7 +102,7 @@ public final class GenerativeModel: Sendable {
108102
`\(VertexLog.enableArgumentKey)` as a launch argument in Xcode.
109103
""")
110104
}
111-
VertexLog.debug(code: .generativeModelInitialized, "Model \(name) initialized.")
105+
VertexLog.debug(code: .generativeModelInitialized, "Model \(modelResourceName) initialized.")
112106
}
113107

114108
/// Generates content from String and/or image inputs, given to the model as a prompt, that are

FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,14 @@ public final class ImagenModel {
4747
/// Configuration parameters for sending requests to the backend.
4848
let requestOptions: RequestOptions
4949

50-
init(name: String,
50+
init(modelResourceName: String,
5151
firebaseInfo: FirebaseInfo,
5252
apiConfig: APIConfig,
5353
generationConfig: ImagenGenerationConfig?,
5454
safetySettings: ImagenSafetySettings?,
5555
requestOptions: RequestOptions,
5656
urlSession: URLSession = .shared) {
57-
if !name.starts(with: ImagenModel.imagenModelNamePrefix) {
58-
VertexLog.warning(code: .unsupportedImagenModel, """
59-
Unsupported Imagen model "\(name)"; see \
60-
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
61-
""")
62-
}
63-
64-
modelResourceName = name
57+
self.modelResourceName = modelResourceName
6558
self.apiConfig = apiConfig
6659
generativeAIService = GenerativeAIService(
6760
firebaseInfo: firebaseInfo,

FirebaseVertexAI/Sources/VertexAI.swift

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@ public class VertexAI {
7070
systemInstruction: ModelContent? = nil,
7171
requestOptions: RequestOptions = RequestOptions())
7272
-> GenerativeModel {
73+
if !modelName.starts(with: GenerativeModel.geminiModelNamePrefix) {
74+
VertexLog.warning(code: .unsupportedGeminiModel, """
75+
Unsupported Gemini model "\(modelName)"; see \
76+
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
77+
""")
78+
}
79+
7380
return GenerativeModel(
74-
name: modelResourceName(modelName: modelName),
81+
modelResourceName: modelResourceName(modelName: modelName),
7582
firebaseInfo: firebaseInfo,
7683
apiConfig: apiConfig,
7784
generationConfig: generationConfig,
@@ -102,8 +109,15 @@ public class VertexAI {
102109
public func imagenModel(modelName: String, generationConfig: ImagenGenerationConfig? = nil,
103110
safetySettings: ImagenSafetySettings? = nil,
104111
requestOptions: RequestOptions = RequestOptions()) -> ImagenModel {
112+
if !modelName.starts(with: ImagenModel.imagenModelNamePrefix) {
113+
VertexLog.warning(code: .unsupportedImagenModel, """
114+
Unsupported Imagen model "\(modelName)"; see \
115+
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
116+
""")
117+
}
118+
105119
return ImagenModel(
106-
name: modelResourceName(modelName: modelName),
120+
modelResourceName: modelResourceName(modelName: modelName),
107121
firebaseInfo: firebaseInfo,
108122
apiConfig: apiConfig,
109123
generationConfig: generationConfig,

0 commit comments

Comments
 (0)