Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions FirebaseVertexAI/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 11.11.0
- [added] Emits a warning when attempting to use an incompatible model with
`GenerativeModel` or `ImagenModel`. (#14610)

# 11.10.0
- [feature] The Vertex AI SDK no longer requires `@preconcurrency` when imported in Swift 6.
- [feature] The Vertex AI Sample App now includes an image generation example.
Expand Down
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,8 +33,10 @@ enum VertexLog {

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

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

// Network Errors
Expand Down
Loading