12
12
// See the License for the specific language governing permissions and
13
13
// limitations under the License.
14
14
15
- import GoogleGenerativeAI
15
+ import FirebaseAI // REPLACED: ` GoogleGenerativeAI` with `FirebaseAI`
16
16
import MarkdownUI
17
17
import SwiftUI
18
18
19
- extension SafetySetting . HarmCategory : CustomStringConvertible {
19
+ extension HarmCategory : CustomStringConvertible { // REMOVED: `SafetySetting.`
20
20
public var description : String {
21
21
switch self {
22
22
case . dangerousContent: " Dangerous content "
23
23
case . harassment: " Harassment "
24
24
case . hateSpeech: " Hate speech "
25
25
case . sexuallyExplicit: " Sexually explicit "
26
- case . unknown: " Unknown "
27
- case . unspecified: " Unspecified "
26
+ case . civicIntegrity: " Civic integrity " // ADDED
27
+ // REMOVED: case .unspecified: "Unspecified"
28
+ default : " Unknown " // REPLACED `case .unknown`
28
29
}
29
30
}
30
31
}
@@ -36,8 +37,7 @@ extension SafetyRating.HarmProbability: CustomStringConvertible {
36
37
case . low: " Low "
37
38
case . medium: " Medium "
38
39
case . negligible: " Negligible "
39
- case . unknown: " Unknown "
40
- case . unspecified: " Unspecified "
40
+ default : " Unknown " // REPLACED: `case .unknown`
41
41
}
42
42
}
43
43
}
@@ -102,6 +102,17 @@ struct ErrorDetailsView: View {
102
102
value: underlyingError. localizedDescription)
103
103
}
104
104
105
+ // ADDED
106
+ case let GenerateContentError . promptImageContentError( underlying: underlyingError) :
107
+ Section ( " Error Type " ) {
108
+ Text ( " Creating prompt image content failed " )
109
+ }
110
+
111
+ Section ( " Details " ) {
112
+ SubtitleFormRow ( title: " Error description " ,
113
+ value: underlyingError. localizedDescription)
114
+ }
115
+
105
116
case let GenerateContentError . promptBlocked( response: generateContentResponse) :
106
117
Section ( " Error Type " ) {
107
118
Text ( " Your prompt was blocked " )
@@ -142,36 +153,9 @@ struct ErrorDetailsView: View {
142
153
SafetyRatingsSection ( ratings: ratings)
143
154
}
144
155
145
- case GenerateContentError . invalidAPIKey:
146
- Section ( " Error Type " ) {
147
- Text ( " Invalid API Key " )
148
- }
149
-
150
- Section ( " Details " ) {
151
- SubtitleFormRow ( title: " Error description " , value: error. localizedDescription)
152
- SubtitleMarkdownFormRow (
153
- title: " Help " ,
154
- value: """
155
- Please provide a valid value for `API_KEY` in the `GenerativeAI-Info.plist` file.
156
- """
157
- )
158
- }
159
-
160
- case GenerateContentError . unsupportedUserLocation:
161
- Section ( " Error Type " ) {
162
- Text ( " Unsupported User Location " )
163
- }
156
+ // REMOVED: `GenerateContentError.invalidAPIKey`
164
157
165
- Section ( " Details " ) {
166
- SubtitleFormRow ( title: " Error description " , value: error. localizedDescription)
167
- SubtitleMarkdownFormRow (
168
- title: " Help " ,
169
- value: """
170
- The API is unsupported in your location (country / territory); please see the list of
171
- [available regions](https://ai.google.dev/available_regions#available_regions).
172
- """
173
- )
174
- }
158
+ // REMOVED: `GenerateContentError.unsupportedUserLocation`
175
159
176
160
default :
177
161
Section ( " Error Type " ) {
@@ -192,23 +176,32 @@ struct ErrorDetailsView: View {
192
176
#Preview( " Response Stopped Early " ) {
193
177
let error = GenerateContentError . responseStoppedEarly (
194
178
reason: . maxTokens,
195
- response: GenerateContentResponse ( candidates: [
196
- CandidateResponse ( content: ModelContent ( role: " model " , [
197
- """
198
- A _hypothetical_ model response.
199
- Cillum ex aliqua amet aliquip labore amet eiusmod consectetur reprehenderit sit commodo.
200
- """ ,
201
- ] ) ,
202
- safetyRatings: [
203
- SafetyRating ( category: . dangerousContent, probability: . high) ,
204
- SafetyRating ( category: . harassment, probability: . low) ,
205
- SafetyRating ( category: . hateSpeech, probability: . low) ,
206
- SafetyRating ( category: . sexuallyExplicit, probability: . low) ,
179
+ response: GenerateContentResponse (
180
+ candidates: [
181
+ Candidate ( // REPLACED: `CandidateResponse` with `Candidate`
182
+ content: ModelContent ( role: " model " , parts: [ // ADDED: `parts: `
183
+ """
184
+ A _hypothetical_ model response.
185
+ Cillum ex aliqua amet aliquip labore amet eiusmod consectetur reprehenderit sit commodo.
186
+ """ ,
187
+ ] ) ,
188
+ safetyRatings: [
189
+ // ADDED: `probabilityScore`, `severity`, `severityScore`, and `blocked`
190
+ SafetyRating ( category: . dangerousContent, probability: . high, probabilityScore: 0.0 ,
191
+ severity: . negligible, severityScore: 0.0 , blocked: false ) ,
192
+ SafetyRating ( category: . harassment, probability: . low, probabilityScore: 0.0 ,
193
+ severity: . negligible, severityScore: 0.0 , blocked: false ) ,
194
+ SafetyRating ( category: . hateSpeech, probability: . low, probabilityScore: 0.0 ,
195
+ severity: . negligible, severityScore: 0.0 , blocked: false ) ,
196
+ SafetyRating ( category: . sexuallyExplicit, probability: . low, probabilityScore: 0.0 ,
197
+ severity: . negligible, severityScore: 0.0 , blocked: false ) ,
198
+ ] ,
199
+ finishReason: FinishReason . maxTokens,
200
+ citationMetadata: nil
201
+ ) ,
207
202
] ,
208
- finishReason: FinishReason . maxTokens,
209
- citationMetadata: nil ) ,
210
- ] ,
211
- promptFeedback: nil )
203
+ promptFeedback: nil
204
+ )
212
205
)
213
206
214
207
return ErrorDetailsView ( error: error)
@@ -217,17 +210,24 @@ struct ErrorDetailsView: View {
217
210
#Preview( " Prompt Blocked " ) {
218
211
let error = GenerateContentError . promptBlocked (
219
212
response: GenerateContentResponse ( candidates: [
220
- CandidateResponse ( content: ModelContent ( role: " model " , [
213
+ // REPLACED: `CandidateResponse` with `Candidate`
214
+ Candidate ( content: ModelContent ( role: " model " , parts: [ // ADDED: `parts: `
221
215
"""
222
216
A _hypothetical_ model response.
223
217
Cillum ex aliqua amet aliquip labore amet eiusmod consectetur reprehenderit sit commodo.
224
218
""" ,
225
219
] ) ,
226
220
safetyRatings: [
227
- SafetyRating ( category: . dangerousContent, probability: . high) ,
228
- SafetyRating ( category: . harassment, probability: . low) ,
229
- SafetyRating ( category: . hateSpeech, probability: . low) ,
230
- SafetyRating ( category: . sexuallyExplicit, probability: . low) ,
221
+ // ADDED: `probabilityScore`, `severity`, `severityScore`, and `blocked`
222
+ SafetyRating ( category: . dangerousContent, probability: . high, probabilityScore: 0.0 ,
223
+ severity: . negligible, severityScore: 0.0 , blocked: false ) ,
224
+ SafetyRating ( category: . harassment, probability: . low, probabilityScore: 0.0 ,
225
+ severity: . negligible, severityScore: 0.0 , blocked: false ) ,
226
+ SafetyRating ( category: . hateSpeech, probability: . low, probabilityScore: 0.0 ,
227
+ severity: . negligible, severityScore: 0.0 , blocked: false ) ,
228
+ SafetyRating ( category: . sexuallyExplicit, probability: . low,
229
+ probabilityScore: 0.0 , severity: . negligible, severityScore: 0.0 ,
230
+ blocked: false ) ,
231
231
] ,
232
232
finishReason: FinishReason . other,
233
233
citationMetadata: nil ) ,
@@ -238,10 +238,6 @@ struct ErrorDetailsView: View {
238
238
return ErrorDetailsView ( error: error)
239
239
}
240
240
241
- #Preview( " Invalid API Key " ) {
242
- ErrorDetailsView ( error: GenerateContentError . invalidAPIKey ( message: " Fix API key placeholder " ) )
243
- }
241
+ // REMOVED: Preview for `GenerateContentError.invalidAPIKey`
244
242
245
- #Preview( " Unsupported User Location " ) {
246
- ErrorDetailsView ( error: GenerateContentError . unsupportedUserLocation)
247
- }
243
+ // REMOVED: Preview for `GenerateContentError.unsupportedUserLocation`
0 commit comments