From f743d50d7f308bf182efbcdadd62569ca177bcb0 Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Sat, 31 Jan 2026 05:21:11 +0530 Subject: [PATCH] Improve OpenAI fallback diagnostics --- .../component/OpenAIVisionClient.kt | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/android/trisolarisserver/component/OpenAIVisionClient.kt b/src/main/kotlin/com/android/trisolarisserver/component/OpenAIVisionClient.kt index 0ff1ef0..528c38d 100644 --- a/src/main/kotlin/com/android/trisolarisserver/component/OpenAIVisionClient.kt +++ b/src/main/kotlin/com/android/trisolarisserver/component/OpenAIVisionClient.kt @@ -7,6 +7,7 @@ import org.springframework.http.HttpHeaders import org.springframework.http.MediaType import org.springframework.stereotype.Component import org.springframework.web.client.RestTemplate +import org.springframework.web.client.HttpStatusCodeException import org.slf4j.LoggerFactory @Component @@ -30,6 +31,10 @@ class OpenAIVisionClient( val payload = mapOf( "model" to model, + "instructions" to "Read extremely carefully. Reply ONLY the 12 digits or NONE. No extra text.", + "temperature" to 0.0, + "top_p" to 1.0, + "max_output_tokens" to 12, "input" to listOf( mapOf( "role" to "user", @@ -40,7 +45,10 @@ class OpenAIVisionClient( ), mapOf( "type" to "input_image", - "image_url" to imageUrl + "image_url" to mapOf( + "url" to imageUrl, + "detail" to "high" + ) ) ) ) @@ -58,16 +66,31 @@ class OpenAIVisionClient( val node = objectMapper.readTree(body) val outputText = node.path("output_text").asText() - if (outputText.isNotBlank()) return outputText + if (outputText.isNotBlank()) { + logger.info("OpenAI fallback output_text length={}", outputText.trim().length) + return outputText + } val outputArray = node.path("output") if (outputArray.isArray && outputArray.size() > 0) { val content = outputArray[0].path("content") if (content.isArray && content.size() > 0) { val text = content[0].path("text").asText() - if (text.isNotBlank()) return text + if (text.isNotBlank()) { + logger.info("OpenAI fallback content text length={}", text.trim().length) + return text + } } } + val errorNode = node.path("error") + if (!errorNode.isMissingNode) { + val code = errorNode.path("code").asText() + val type = errorNode.path("type").asText() + logger.warn("OpenAI fallback error code={} type={}", code, type) + } + null + } catch (e: HttpStatusCodeException) { + logger.warn("OpenAI fallback HTTP error status={} body={}", e.statusCode.value(), e.responseBodyAsString.take(200)) null } catch (e: Exception) { logger.warn("OpenAI fallback failed: {}", e.message)