@@ -41,7 +41,7 @@ public struct SafetyRating: Equatable, Hashable, Sendable {
41
41
/// The probability that a given model output falls under a harmful content category.
42
42
///
43
43
/// > Note: This does not indicate the severity of harm for a piece of content.
44
- public struct HarmProbability : Sendable , Equatable , Hashable {
44
+ public struct HarmProbability : DecodableProtoEnum , Hashable , Sendable {
45
45
enum Kind : String {
46
46
case negligible = " NEGLIGIBLE "
47
47
case low = " LOW "
@@ -79,24 +79,8 @@ public struct SafetyRating: Equatable, Hashable, Sendable {
79
79
/// > API](https://cloud.google.com/vertex-ai/docs/reference/rest/v1beta1/GenerateContentResponse#SafetyRating).
80
80
public let rawValue : String
81
81
82
- init ( kind: Kind ) {
83
- rawValue = kind. rawValue
84
- }
85
-
86
- init ( rawValue: String ) {
87
- if Kind ( rawValue: rawValue) == nil {
88
- VertexLog . error (
89
- code: . generateContentResponseUnrecognizedHarmProbability,
90
- """
91
- Unrecognized HarmProbability with value " \( rawValue) " :
92
- - Check for updates to the SDK as support for " \( rawValue) " may have been added; see \
93
- release notes at https://firebase.google.com/support/release-notes/ios
94
- - Search for " \( rawValue) " in the Firebase Apple SDK Issue Tracker at \
95
- https://github.com/firebase/firebase-ios-sdk/issues and file a Bug Report if none found
96
- """
97
- )
98
- }
99
- self . rawValue = rawValue
82
+ var unrecognizedValueMessageCode : VertexLog . MessageCode {
83
+ . generateContentResponseUnrecognizedHarmProbability
100
84
}
101
85
}
102
86
}
@@ -139,7 +123,7 @@ public struct SafetySetting {
139
123
}
140
124
141
125
/// Categories describing the potential harm a piece of content may pose.
142
- public struct HarmCategory : Sendable , Equatable , Hashable {
126
+ public struct HarmCategory : CodableProtoEnum , Hashable , Sendable {
143
127
enum Kind : String {
144
128
case harassment = " HARM_CATEGORY_HARASSMENT "
145
129
case hateSpeech = " HARM_CATEGORY_HATE_SPEECH "
@@ -179,48 +163,16 @@ public struct HarmCategory: Sendable, Equatable, Hashable {
179
163
/// > [REST API](https://cloud.google.com/vertex-ai/docs/reference/rest/v1beta1/HarmCategory).
180
164
public let rawValue : String
181
165
182
- init ( kind: Kind ) {
183
- rawValue = kind. rawValue
184
- }
185
-
186
- init ( rawValue: String ) {
187
- if Kind ( rawValue: rawValue) == nil {
188
- VertexLog . error (
189
- code: . generateContentResponseUnrecognizedHarmCategory,
190
- """
191
- Unrecognized HarmCategory with value " \( rawValue) " :
192
- - Check for updates to the SDK as support for " \( rawValue) " may have been added; see \
193
- release notes at https://firebase.google.com/support/release-notes/ios
194
- - Search for " \( rawValue) " in the Firebase Apple SDK Issue Tracker at \
195
- https://github.com/firebase/firebase-ios-sdk/issues and file a Bug Report if none found
196
- """
197
- )
198
- }
199
- self . rawValue = rawValue
166
+ var unrecognizedValueMessageCode : VertexLog . MessageCode {
167
+ . generateContentResponseUnrecognizedHarmCategory
200
168
}
201
169
}
202
170
203
171
// MARK: - Codable Conformances
204
172
205
- @available ( iOS 15 . 0 , macOS 11 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
206
- extension SafetyRating . HarmProbability : Decodable {
207
- public init ( from decoder: Decoder ) throws {
208
- let rawValue = try decoder. singleValueContainer ( ) . decode ( String . self)
209
- self = SafetyRating . HarmProbability ( rawValue: rawValue)
210
- }
211
- }
212
-
213
173
@available ( iOS 15 . 0 , macOS 11 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
214
174
extension SafetyRating : Decodable { }
215
175
216
- @available ( iOS 15 . 0 , macOS 11 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
217
- extension HarmCategory : Codable {
218
- public init ( from decoder: Decoder ) throws {
219
- let rawValue = try decoder. singleValueContainer ( ) . decode ( String . self)
220
- self = HarmCategory ( rawValue: rawValue)
221
- }
222
- }
223
-
224
176
@available ( iOS 15 . 0 , macOS 11 . 0 , macCatalyst 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
225
177
extension SafetySetting . HarmBlockThreshold : Encodable { }
226
178
0 commit comments