Skip to content

[Vertex AI] Add Imagen warning for invalid JPEG compression quality #14440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public struct ImagenImageFormat {
/// compression (lowest image quality, smallest file size) and `100` is the lowest level of
/// compression (highest image quality, largest file size); defaults to `75`.
public static func jpeg(compressionQuality: Int? = nil) -> ImagenImageFormat {
if let compressionQuality, compressionQuality < 0 || compressionQuality > 100 {
VertexLog.warning(code: .imagenInvalidJPEGCompressionQuality, """
Invalid JPEG compression quality of \(compressionQuality) specified; the supported range is \
[0, 100].
""")
}
return ImagenImageFormat(mimeType: "image/jpeg", compressionQuality: compressionQuality)
}
}
5 changes: 4 additions & 1 deletion FirebaseVertexAI/Sources/VertexLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ enum VertexLog {
// API Enablement Errors
case vertexAIInFirebaseAPIDisabled = 200

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

// Imagen Model Configuration
case imagenInvalidJPEGCompressionQuality = 1201

// Network Errors
case generativeAIServiceNonHTTPResponse = 2000
case loadRequestResponseError = 2001
Expand Down
Loading