File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
packages/firebase_ai/firebase_ai Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -1372,6 +1372,12 @@ Candidate _parseCandidate(Object? jsonObject) {
1372
1372
}
1373
1373
1374
1374
PromptFeedback _parsePromptFeedback (Object jsonObject) {
1375
+ if (jsonObject is ! Map ) {
1376
+ throw unhandledFormat ('PromptFeedback' , jsonObject);
1377
+ }
1378
+ if (jsonObject.isEmpty) {
1379
+ return PromptFeedback (null , null , []);
1380
+ }
1375
1381
return switch (jsonObject) {
1376
1382
{
1377
1383
'safetyRatings' : final List <Object ?> safetyRatings,
Original file line number Diff line number Diff line change @@ -67,6 +67,32 @@ void main() {
67
67
);
68
68
});
69
69
70
+ test ('with empty promptFeedback' , () {
71
+ const response = '''
72
+ {
73
+ "candidates": [
74
+ {
75
+ "content": {
76
+ "parts": [
77
+ {
78
+ "text": "Mountain View, California, United States"
79
+ }
80
+ ],
81
+ "role": "model"
82
+ },
83
+ "index": 0
84
+ }
85
+ ],
86
+ "promptFeedback": {}
87
+ }
88
+ ''' ;
89
+ final decoded = jsonDecode (response) as Object ;
90
+ expect (
91
+ VertexSerialization ().parseGenerateContentResponse (decoded),
92
+ isA <GenerateContentResponse >(),
93
+ );
94
+ });
95
+
70
96
test ('with a blocked prompt' , () {
71
97
const response = '''
72
98
{
You can’t perform that action at this time.
0 commit comments