@@ -289,6 +289,13 @@ void main() {
289289 'HARM_CATEGORY_SEXUALLY_EXPLICIT' );
290290 expect (HarmCategory .dangerousContent.toJson (),
291291 'HARM_CATEGORY_DANGEROUS_CONTENT' );
292+ expect (HarmCategory .imageHate.toJson (), 'HARM_CATEGORY_IMAGE_HATE' );
293+ expect (HarmCategory .imageDangerousContent.toJson (),
294+ 'HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT' );
295+ expect (HarmCategory .imageHarassment.toJson (),
296+ 'HARM_CATEGORY_IMAGE_HARASSMENT' );
297+ expect (HarmCategory .imageSexuallyExplicit.toJson (),
298+ 'HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT' );
292299 });
293300
294301 test ('HarmProbability toJson and toString' , () {
@@ -736,6 +743,75 @@ void main() {
736743 expect (response.usageMetadata! .candidatesTokensDetails, hasLength (1 ));
737744 });
738745
746+ test ('parses image harm categories in safetyRatings' , () {
747+ final json = {
748+ 'candidates' : [
749+ {
750+ 'content' : {
751+ 'role' : 'model' ,
752+ 'parts' : [
753+ {'text' : '' }
754+ ]
755+ },
756+ 'finishReason' : 'STOP' ,
757+ 'safetyRatings' : [
758+ {
759+ 'category' : 'HARM_CATEGORY_IMAGE_DANGEROUS_CONTENT' ,
760+ 'probability' : 'NEGLIGIBLE'
761+ },
762+ {
763+ 'category' : 'HARM_CATEGORY_IMAGE_SEXUALLY_EXPLICIT' ,
764+ 'probability' : 'NEGLIGIBLE'
765+ },
766+ {
767+ 'category' : 'HARM_CATEGORY_IMAGE_HATE' ,
768+ 'probability' : 'NEGLIGIBLE'
769+ },
770+ {
771+ 'category' : 'HARM_CATEGORY_IMAGE_HARASSMENT' ,
772+ 'probability' : 'NEGLIGIBLE'
773+ },
774+ ]
775+ }
776+ ]
777+ };
778+ final response =
779+ VertexSerialization ().parseGenerateContentResponse (json);
780+ final ratings = response.candidates.first.safetyRatings! ;
781+ expect (ratings.map ((r) => r.category), [
782+ HarmCategory .imageDangerousContent,
783+ HarmCategory .imageSexuallyExplicit,
784+ HarmCategory .imageHate,
785+ HarmCategory .imageHarassment,
786+ ]);
787+ });
788+
789+ test ('falls back to HarmCategory.unknown for unrecognized values' , () {
790+ final json = {
791+ 'candidates' : [
792+ {
793+ 'content' : {
794+ 'role' : 'model' ,
795+ 'parts' : [
796+ {'text' : '' }
797+ ]
798+ },
799+ 'finishReason' : 'STOP' ,
800+ 'safetyRatings' : [
801+ {
802+ 'category' : 'HARM_CATEGORY_SOMETHING_NEW' ,
803+ 'probability' : 'NEGLIGIBLE'
804+ }
805+ ]
806+ }
807+ ]
808+ };
809+ final response =
810+ VertexSerialization ().parseGenerateContentResponse (json);
811+ expect (response.candidates.first.safetyRatings! .first.category,
812+ HarmCategory .unknown);
813+ });
814+
739815 group ('usageMetadata parsing' , () {
740816 test ('parses usageMetadata when thoughtsTokenCount is set' , () {
741817 final json = {
0 commit comments