Skip to content

Commit 46865e2

Browse files
committed
Fix logging code and add static constants
1 parent 5e17190 commit 46865e2

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

FirebaseVertexAI/Sources/GenerativeModel.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ import Foundation
2020
/// content based on various input types.
2121
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
2222
public final class GenerativeModel: Sendable {
23+
/// Model name prefix to identify Gemini models.
24+
static let geminiModelNamePrefix = "gemini-"
25+
2326
/// The resource name of the model in the backend; has the format "models/model-name".
2427
let modelResourceName: String
2528

@@ -71,6 +74,13 @@ public final class GenerativeModel: Sendable {
7174
systemInstruction: ModelContent? = nil,
7275
requestOptions: RequestOptions,
7376
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+
7484
modelResourceName = name
7585
self.apiConfig = apiConfig
7686
generativeAIService = GenerativeAIService(
@@ -90,13 +100,6 @@ public final class GenerativeModel: Sendable {
90100
}
91101
self.requestOptions = requestOptions
92102

93-
if !name.starts(with: "gemini-") {
94-
VertexLog.warn(code: .unsupportedModelName, """
95-
Unsupported Gemini model "\(name)"; see \
96-
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
97-
""")
98-
}
99-
100103
if VertexLog.additionalLoggingEnabled() {
101104
VertexLog.debug(code: .verboseLoggingEnabled, "Verbose logging enabled.")
102105
} else {

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ import Foundation
2828
/// could change in backwards-incompatible ways.
2929
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
3030
public final class ImagenModel {
31+
/// Model name prefix to identify Imagen models.
32+
static let imagenModelNamePrefix = "imagen-"
33+
3134
/// The resource name of the model in the backend; has the format "models/model-name".
3235
let modelResourceName: String
3336

@@ -51,6 +54,13 @@ public final class ImagenModel {
5154
safetySettings: ImagenSafetySettings?,
5255
requestOptions: RequestOptions,
5356
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+
5464
modelResourceName = name
5565
self.apiConfig = apiConfig
5666
generativeAIService = GenerativeAIService(
@@ -60,13 +70,6 @@ public final class ImagenModel {
6070
self.generationConfig = generationConfig
6171
self.safetySettings = safetySettings
6272
self.requestOptions = requestOptions
63-
64-
if !name.starts(with: "imagen-") {
65-
VertexLog.warn(code: .unsupportedModelName, """
66-
Unsupported Imagen model "\(name)"; see \
67-
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
68-
""")
69-
}
7073
}
7174

7275
/// **[Public Preview]** Generates images using the Imagen model and returns them as inline data.

0 commit comments

Comments
 (0)