From a1767362db08f2f9a654c3ed4b4d17dd7018b9ad Mon Sep 17 00:00:00 2001 From: Alejandro Serrano Date: Sun, 21 May 2023 11:53:35 +0200 Subject: [PATCH] Fix problem with deserializer (#80) * Fix never-ending deserialization agent * Fix never-ending deserialization agent --- .../com/xebia/functional/xef/auto/DeserializerLLMAgent.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/src/commonMain/kotlin/com/xebia/functional/xef/auto/DeserializerLLMAgent.kt b/core/src/commonMain/kotlin/com/xebia/functional/xef/auto/DeserializerLLMAgent.kt index f2596f922..aa348eee6 100644 --- a/core/src/commonMain/kotlin/com/xebia/functional/xef/auto/DeserializerLLMAgent.kt +++ b/core/src/commonMain/kotlin/com/xebia/functional/xef/auto/DeserializerLLMAgent.kt @@ -143,8 +143,12 @@ suspend fun AIScope.tryDeserialize( while (currentAttempts < maxDeserializationAttempts) { currentAttempts++ val result = ensureNotNull(agent().firstOrNull()) { AIError.NoResponse } - catch({ json.decodeFromString(serializationConfig.deserializationStrategy, result) }) { - e: IllegalArgumentException -> + catch({ + return@tryDeserialize json.decodeFromString( + serializationConfig.deserializationStrategy, + result + ) + }) { e: IllegalArgumentException -> if (currentAttempts == maxDeserializationAttempts) raise(AIError.JsonParsing(result, maxDeserializationAttempts, e)) // else continue with the next attempt