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) {
13721372}
13731373
13741374PromptFeedback _parsePromptFeedback (Object jsonObject) {
1375+ if (jsonObject is ! Map ) {
1376+ throw unhandledFormat ('PromptFeedback' , jsonObject);
1377+ }
1378+ if (jsonObject.isEmpty) {
1379+ return PromptFeedback (null , null , []);
1380+ }
13751381 return switch (jsonObject) {
13761382 {
13771383 'safetyRatings' : final List <Object ?> safetyRatings,
Original file line number Diff line number Diff line change @@ -67,6 +67,32 @@ void main() {
6767 );
6868 });
6969
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+
7096 test ('with a blocked prompt' , () {
7197 const response = '''
7298{
You can’t perform that action at this time.
0 commit comments