Skip to content

Commit 9e6bb8d

Browse files
committed
Add ImagenSafetyAttributes type
1 parent 6f36ea9 commit 9e6bb8d

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import Foundation
16+
17+
/// A `safetyAttributes` "prediction" from Imagen.
18+
///
19+
/// This prediction is currently unused by the SDK and is only checked to be valid JSON. This type
20+
/// is currently only used to avoid logging unsupported prediction types.
21+
@available(iOS 15.0, macOS 12.0, macCatalyst 15.0, tvOS 15.0, watchOS 8.0, *)
22+
struct ImagenSafetyAttributes: Decodable {
23+
let safetyAttributes: JSONObject
24+
}

FirebaseAI/Sources/Types/Public/Imagen/ImagenGenerationResponse.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ extension ImagenGenerationResponse: Decodable where T: Decodable {
6060
images.append(image)
6161
} else if let filteredReason = try? predictionsContainer.decode(RAIFilteredReason.self) {
6262
filteredReasons.append(filteredReason.raiFilteredReason)
63+
} else if let _ = try? predictionsContainer.decode(ImagenSafetyAttributes.self) {
64+
// Ignore SafetyAttributes "prediction" to avoid logging in `unsupportedPrediction` below.
6365
} else if let unsupportedPrediction = try? predictionsContainer.decode(JSONObject.self) {
6466
AILog.warning(
6567
code: .decodedUnsupportedImagenPredictionType,

0 commit comments

Comments
 (0)