Skip to content
Merged
10 changes: 10 additions & 0 deletions FirebaseVertexAI/Sources/GenerativeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import Foundation
/// content based on various input types.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public final class GenerativeModel: Sendable {
/// Model name prefix to identify Gemini models.
static let geminiModelNamePrefix = "gemini-"

/// The resource name of the model in the backend; has the format "models/model-name".
let modelResourceName: String

Expand Down Expand Up @@ -71,6 +74,13 @@ public final class GenerativeModel: Sendable {
systemInstruction: ModelContent? = nil,
requestOptions: RequestOptions,
urlSession: URLSession = .shared) {
if !name.starts(with: GenerativeModel.geminiModelNamePrefix) {
VertexLog.warning(code: .unsupportedGeminiModel, """
Unsupported Gemini model "\(name)"; see \
https://firebase.google.com/docs/vertex-ai/models for a list supported Gemini model names.
""")
}

modelResourceName = name
self.apiConfig = apiConfig
generativeAIService = GenerativeAIService(
Expand Down
10 changes: 10 additions & 0 deletions FirebaseVertexAI/Sources/Types/Public/Imagen/ImagenModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import Foundation
/// could change in backwards-incompatible ways.
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
public final class ImagenModel {
/// Model name prefix to identify Imagen models.
static let imagenModelNamePrefix = "imagen-"

/// The resource name of the model in the backend; has the format "models/model-name".
let modelResourceName: String

Expand All @@ -51,6 +54,13 @@ public final class ImagenModel {
safetySettings: ImagenSafetySettings?,
requestOptions: RequestOptions,
urlSession: URLSession = .shared) {
if !name.starts(with: ImagenModel.imagenModelNamePrefix) {
VertexLog.warning(code: .unsupportedImagenModel, """
Unsupported Imagen model "\(name)"; see \
https://firebase.google.com/docs/vertex-ai/models for a list supported Imagen model names.
""")
}

modelResourceName = name
self.apiConfig = apiConfig
generativeAIService = GenerativeAIService(
Expand Down
2 changes: 2 additions & 0 deletions FirebaseVertexAI/Sources/VertexLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ enum VertexLog {

// Generative Model Configuration
case generativeModelInitialized = 1000
case unsupportedGeminiModel = 1001

// Imagen Model Configuration
case imagenInvalidJPEGCompressionQuality = 1201
case unsupportedImagenModel = 1200

// Network Errors
case generativeAIServiceNonHTTPResponse = 2000
Expand Down
Loading