Skip to content

Commit 656a3fc

Browse files
committed
Formatting
1 parent cc8b6f9 commit 656a3fc

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

core/src/main/scala/sttp/openai/requests/completions/chat/ChatRequestBody.scala

+19-22
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,13 @@ object ChatRequestBody {
3333

3434
/** OpenAI's JSON schema support imposes two requirements:
3535
*
36-
* 1. All fields must be `required`:
37-
* https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required
36+
* 1. All fields must be `required`: https://platform.openai.com/docs/guides/structured-outputs/all-fields-must-be-required
3837
*
39-
* 2. `additionalProperties: false` must always be set in objects:
40-
* https://platform.openai.com/docs/guides/structured-outputs/additionalproperties-false-must-always-be-set-in-objects
38+
* 2. `additionalProperties: false` must always be set in objects:
39+
* https://platform.openai.com/docs/guides/structured-outputs/additionalproperties-false-must-always-be-set-in-objects
4140
*
42-
* We implement these by folding over the JSON structure.
43-
* However, if a schema uses discriminated unions (indicated by a `discriminator` property),
44-
* we skip forcing `additionalProperties: false` to preserve flexibility in selecting sub-schemas.
41+
* We implement these by folding over the JSON structure. However, if a schema uses discriminated unions (indicated by a
42+
* `discriminator` property), we skip forcing `additionalProperties: false` to preserve flexibility in selecting sub-schemas.
4543
*/
4644
private val schemaFolder: Json.Folder[Json] = new Json.Folder[Json] {
4745
lazy val onNull = Json.Null
@@ -50,21 +48,20 @@ object ChatRequestBody {
5048
def onString(value: String): Json = Json.fromString(value)
5149
def onArray(value: Vector[Json]): Json = Json.fromValues(value.map(_.foldWith(this)))
5250
def onObject(value: JsonObject): Json = {
53-
val state = value.toList.foldRight(FolderState(Nil, false, Nil)) {
54-
case ((k, v), acc) =>
55-
if (k == "properties")
56-
acc.copy(
57-
fields = (k, v.foldWith(this)) :: acc.fields,
58-
addAdditionalProperties = true,
59-
requiredProperties = v.asObject.fold(List.empty[String])(_.keys.toList)
60-
)
61-
else if (k == "type")
62-
acc.copy(
63-
fields = (k, v.foldWith(this)) :: acc.fields,
64-
addAdditionalProperties = acc.addAdditionalProperties || v.asString.contains("object")
65-
)
66-
else
67-
acc.copy(fields = (k, v.foldWith(this)) :: acc.fields)
51+
val state = value.toList.foldRight(FolderState(Nil, false, Nil)) { case ((k, v), acc) =>
52+
if (k == "properties")
53+
acc.copy(
54+
fields = (k, v.foldWith(this)) :: acc.fields,
55+
addAdditionalProperties = true,
56+
requiredProperties = v.asObject.fold(List.empty[String])(_.keys.toList)
57+
)
58+
else if (k == "type")
59+
acc.copy(
60+
fields = (k, v.foldWith(this)) :: acc.fields,
61+
addAdditionalProperties = acc.addAdditionalProperties || v.asString.contains("object")
62+
)
63+
else
64+
acc.copy(fields = (k, v.foldWith(this)) :: acc.fields)
6865
}
6966

7067
// Detect if this object is part of a discriminated union by checking for a "discriminator" property.

0 commit comments

Comments
 (0)