Skip to content

Commit b9ac83f

Browse files
committed
OpenAIChatCompletionExtra - JSON repair triggered on more general JsonProcessingException instead of JsonParseException
1 parent 91f932e commit b9ac83f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

openai-core/src/main/scala/io/cequence/openaiscala/service/OpenAIChatCompletionExtra.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import org.slf4j.{Logger, LoggerFactory}
2222
import play.api.libs.json.{Format, JsValue, Json}
2323

2424
import scala.concurrent.{ExecutionContext, Future}
25+
import com.fasterxml.jackson.core.JsonProcessingException
2526

2627
object OpenAIChatCompletionExtra {
2728

@@ -161,8 +162,10 @@ object OpenAIChatCompletionExtra {
161162
): JsValue = try {
162163
Json.parse(jsonString)
163164
} catch {
164-
case e: JsonParseException =>
165-
logger.error(s"Failed to parse JSON response due to: ${e.getMessage}. Repairing...")
165+
case e: JsonProcessingException =>
166+
logger.error(
167+
s"Failed to parse JSON response normally; attempting to repair it now. Error: ${e.getMessage()}."
168+
)
166169
val repairedJsonString = JsonRepair.repair(jsonString)
167170
Json.parse(repairedJsonString)
168171
}

0 commit comments

Comments
 (0)