File tree 2 files changed +27
-1
lines changed
main/scala/io/cequence/openaiscala/gemini
test/scala/io/cequence/openaiscala/gemini
2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -79,7 +79,20 @@ trait JsonFormats {
79
79
80
80
implicit val partFormat : Format [Part ] = Format (partReads, partWrites)
81
81
82
- implicit val contentFormat : Format [Content ] = Json .format[Content ]
82
+ implicit val contentWrites : Writes [Content ] = (
83
+ (__ \ " parts" ).write[Seq [Part ]] and
84
+ (__ \ " role" ).writeNullable[ChatRole ]
85
+ )(
86
+ // somehow unlift(Content.unapply) is not working in Scala3
87
+ (x : Content ) => (x.parts, x.role)
88
+ )
89
+
90
+ implicit val contentReads : Reads [Content ] = (
91
+ (__ \ " parts" ).readWithDefault[Seq [Part ]](Nil ) and
92
+ (__ \ " role" ).readNullable[ChatRole ]
93
+ )(Content .apply(_ : Seq [Part ], _ : Option [ChatRole ]))
94
+
95
+ implicit val contentFormat : Format [Content ] = Format (contentReads, contentWrites)
83
96
84
97
// Tools
85
98
implicit val toolPrefixFormat : Format [ToolPrefix ] = enumFormat(ToolPrefix .values: _* )
Original file line number Diff line number Diff line change @@ -67,6 +67,19 @@ class JsonFormatsSpec extends AnyWordSpecLike with Matchers {
67
67
)
68
68
}
69
69
70
+ " deserialize candidate with empty content" in {
71
+ testDeserialization[Candidate ](
72
+ Candidate (
73
+ content = Content .apply()
74
+ ),
75
+ """ {
76
+ | "content" : {},
77
+ | "safetyRatings" : [ ],
78
+ | "groundingAttributions" : [ ]
79
+ |}""" .stripMargin
80
+ )
81
+ }
82
+
70
83
" serialize and deserialize top candidate" in {
71
84
prettyTestCodec[TopCandidates ](
72
85
TopCandidates (
You can’t perform that action at this time.
0 commit comments