Skip to content

Commit 748a6fc

Browse files
committed
Reverting
1 parent cfdcf27 commit 748a6fc

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

openai-client/src/main/scala/io/cequence/openaiscala/service/impl/OpenAIChatCompletionServiceImpl.scala

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,33 @@ trait ChatCompletionBodyMaker {
170170
case Right(schema) => schema
171171
}
172172

173-
val adjustedSchema: Map[String, Any] =
174-
if (strict)
175-
OpenAIChatCompletionExtra.toStrictSchema(structure)
176-
else
177-
schemaMap
173+
val adjustedSchema: Map[String, Any] = if (strict) {
174+
// set "additionalProperties" -> false on "object" types if strict
175+
def addFlagAux(map: Map[String, Any]): Map[String, Any] = {
176+
val newMap = map.map { case (key, value) =>
177+
val unwrappedValue = value match {
178+
case Some(value) => value
179+
case other => other
180+
}
181+
182+
val newValue = unwrappedValue match {
183+
case obj: Map[String, Any] =>
184+
addFlagAux(obj)
185+
186+
case other =>
187+
other
188+
}
189+
key -> newValue
190+
}
191+
192+
if (Seq("object", Some("object")).contains(map.getOrElse("type", ""))) {
193+
newMap + ("additionalProperties" -> false)
194+
} else
195+
newMap
196+
}
197+
198+
addFlagAux(schemaMap)
199+
} else schemaMap
178200

179201
Map(
180202
"type" -> "json_schema",
@@ -188,5 +210,4 @@ trait ChatCompletionBodyMaker {
188210
// TODO: is it legal?
189211
Map("type" -> "json_schema")
190212
)
191-
192213
}

0 commit comments

Comments
 (0)