Skip to content

Commit 1867333

Browse files
committed
ResponsesAPI JsonFormatsSpecs test - Input tests extended from a pure serialization to also deserialization + handling of the 'type' field added
1 parent 3101234 commit 1867333

File tree

1 file changed

+38
-30
lines changed

1 file changed

+38
-30
lines changed

openai-core/src/test/scala/io/cequence/openaiscala/domain/responsesapi/JsonFormatsSpecs.scala

+38-30
Original file line numberDiff line numberDiff line change
@@ -993,24 +993,25 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
993993
)
994994
}
995995

996-
"serialize Input.ofInputTextMessage" in {
996+
"serialize and deserialize Input.ofInputTextMessage" in {
997997
val input = Input.ofInputTextMessage(
998998
content = "Hello, world!",
999999
role = ChatRole.User
10001000
)
10011001

1002-
testSerialization[Input](
1002+
testCodec[Input](
10031003
input,
10041004
"""{
10051005
| "content" : "Hello, world!",
1006-
| "role" : "user"
1006+
| "role" : "user",
1007+
| "type" : "message"
10071008
|}""".stripMargin,
10081009
Pretty
10091010
)
10101011
}
10111012

1012-
"serialize Input.ofInputMessage" in {
1013-
testSerialization[Input](
1013+
"serialize and deserialize Input.ofInputMessage" in {
1014+
testCodec[Input](
10141015
Input.ofInputMessage(
10151016
content = Seq(
10161017
InputMessageContent.Text("Hello, I have a question about my data."),
@@ -1026,12 +1027,13 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
10261027
| "file_id" : "file_abc123",
10271028
| "type" : "input_file"
10281029
| } ],
1029-
| "role" : "user"
1030+
| "role" : "user",
1031+
| "type" : "message"
10301032
|}""".stripMargin,
10311033
Pretty
10321034
)
10331035

1034-
testSerialization[Input](
1036+
testCodec[Input](
10351037
Input.ofInputMessage(
10361038
content = Seq(
10371039
InputMessageContent.Text("Hello, I have a question about my data."),
@@ -1049,13 +1051,14 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
10491051
| "type" : "input_file"
10501052
| } ],
10511053
| "role" : "user",
1052-
| "status" : "completed"
1054+
| "status" : "completed",
1055+
| "type" : "message"
10531056
|}""".stripMargin,
10541057
Pretty
10551058
)
10561059
}
10571060

1058-
"serialize Input.ofOutputMessage" in {
1061+
"serialize and deserialize Input.ofOutputMessage" in {
10591062
val input = Input.ofOutputMessage(
10601063
content = Seq(
10611064
OutputMessageContent.OutputText(text = "Here's the analysis of your data.")
@@ -1064,7 +1067,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
10641067
status = ModelStatus.Completed
10651068
)
10661069

1067-
testSerialization[Input](
1070+
testCodec[Input](
10681071
input,
10691072
"""{
10701073
| "content" : [ {
@@ -1073,13 +1076,14 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
10731076
| "type" : "output_text"
10741077
| } ],
10751078
| "id" : "output_abc123",
1076-
| "status" : "completed"
1079+
| "status" : "completed",
1080+
| "type" : "message"
10771081
|}""".stripMargin,
10781082
Pretty
10791083
)
10801084
}
10811085

1082-
"serialize Input.ofFileSearchToolCall" in {
1086+
"serialize and deserialize Input.ofFileSearchToolCall" in {
10831087
val input = Input.ofFileSearchToolCall(
10841088
id = "search_abc123",
10851089
queries = Seq("Find documents about machine learning"),
@@ -1095,7 +1099,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
10951099
)
10961100
)
10971101

1098-
testSerialization[Input](
1102+
testCodec[Input](
10991103
input,
11001104
"""{
11011105
| "id" : "search_abc123",
@@ -1135,7 +1139,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
11351139
status = ModelStatus.InProgress
11361140
)
11371141

1138-
testSerialization[Input](
1142+
testCodec[Input](
11391143
input,
11401144
"""{
11411145
| "action" : {
@@ -1158,7 +1162,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
11581162
)
11591163
}
11601164

1161-
"serialize Input.ofComputerToolCallOutput" in {
1165+
"serialize and deserialize Input.ofComputerToolCallOutput" in {
11621166
val input = Input.ofComputerToolCallOutput(
11631167
callId = "computer_call_abc123",
11641168
output = ComputerScreenshot(
@@ -1176,7 +1180,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
11761180
status = Some(ModelStatus.Completed)
11771181
)
11781182

1179-
testSerialization[Input](
1183+
testCodec[Input](
11801184
input,
11811185
"""{
11821186
| "call_id" : "computer_call_abc123",
@@ -1191,19 +1195,20 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
11911195
| "message" : "Action confirmed"
11921196
| } ],
11931197
| "id" : "output_abc123",
1194-
| "status" : "completed"
1198+
| "status" : "completed",
1199+
| "type" : "computer_call_output"
11951200
|}""".stripMargin,
11961201
Pretty
11971202
)
11981203
}
11991204

1200-
"serialize Input.ofWebSearchToolCall" in {
1205+
"serialize and deserialize Input.ofWebSearchToolCall" in {
12011206
val input = Input.ofWebSearchToolCall(
12021207
id = "web_search_abc123",
12031208
status = ModelStatus.InProgress
12041209
)
12051210

1206-
testSerialization[Input](
1211+
testCodec[Input](
12071212
input,
12081213
"""{
12091214
| "id" : "web_search_abc123",
@@ -1214,7 +1219,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
12141219
)
12151220
}
12161221

1217-
"serialize Input.ofFunctionToolCall" in {
1222+
"serialize and deserialize Input.ofFunctionToolCall" in {
12181223
val input = Input.ofFunctionToolCall(
12191224
arguments = """{"location":"San Francisco, CA"}""",
12201225
callId = "function_call_abc123",
@@ -1223,7 +1228,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
12231228
status = Some(ModelStatus.Completed)
12241229
)
12251230

1226-
testSerialization[Input](
1231+
testCodec[Input](
12271232
input,
12281233
"""{
12291234
| "arguments" : "{\"location\":\"San Francisco, CA\"}",
@@ -1237,27 +1242,28 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
12371242
)
12381243
}
12391244

1240-
"serialize Input.ofFunctionToolCallOutput" in {
1245+
"serialize and deserialize Input.ofFunctionToolCallOutput" in {
12411246
val input = Input.ofFunctionToolCallOutput(
12421247
callId = "function_call_abc123",
12431248
output = """{"temperature":72,"unit":"F"}""",
12441249
id = Some("output_abc123"),
12451250
status = Some(ModelStatus.Completed)
12461251
)
12471252

1248-
testSerialization[Input](
1253+
testCodec[Input](
12491254
input,
12501255
"""{
12511256
| "call_id" : "function_call_abc123",
12521257
| "output" : "{\"temperature\":72,\"unit\":\"F\"}",
12531258
| "id" : "output_abc123",
1254-
| "status" : "completed"
1259+
| "status" : "completed",
1260+
| "type" : "function_call_output"
12551261
|}""".stripMargin,
12561262
Pretty
12571263
)
12581264
}
12591265

1260-
"serialize Input.ofReasoning" in {
1266+
"serialize and deserialize Input.ofReasoning" in {
12611267
val input = Input.ofReasoning(
12621268
id = "reasoning_abc123",
12631269
summary = Seq(
@@ -1267,7 +1273,7 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
12671273
status = Some(ModelStatus.Completed)
12681274
)
12691275

1270-
testSerialization[Input](
1276+
testCodec[Input](
12711277
input,
12721278
"""{
12731279
| "id" : "reasoning_abc123",
@@ -1276,21 +1282,23 @@ class JsonFormatsSpecs extends AnyWordSpecLike with Matchers {
12761282
| }, {
12771283
| "text" : "Second step: Draw conclusions"
12781284
| } ],
1279-
| "status" : "completed"
1285+
| "status" : "completed",
1286+
| "type" : "reasoning"
12801287
|}""".stripMargin,
12811288
Pretty
12821289
)
12831290
}
12841291

1285-
"serialize Input.ofItemReference" in {
1292+
"serialize and deserialize Input.ofItemReference" in {
12861293
val input = Input.ofItemReference(
12871294
id = "item_abc123"
12881295
)
12891296

1290-
testSerialization[Input](
1297+
testCodec[Input](
12911298
input,
12921299
"""{
1293-
| "id" : "item_abc123"
1300+
| "id" : "item_abc123",
1301+
| "type" : "item_reference"
12941302
|}""".stripMargin,
12951303
Pretty
12961304
)

0 commit comments

Comments
 (0)