Retry OpenAI fallback with focused Aadhaar prompt
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s

This commit is contained in:
androidlover5842
2026-01-31 05:30:07 +05:30
parent 124945dddb
commit e60e70a6b0

View File

@@ -29,6 +29,24 @@ class OpenAIVisionClient(
return null
}
val headers = HttpHeaders()
headers.contentType = MediaType.APPLICATION_JSON
headers.setBearerAuth(apiKey)
val first = call(imageUrl, "Read extremely carefully. Aadhaar number = 12 digits. Reply ONLY the 12 digits or NONE.", headers)
if (!first.isNullOrBlank() && !first.equals("NONE", ignoreCase = true)) {
return first
}
if (first != null) {
logger.info("OpenAI fallback returned NONE; retrying with focused prompt")
}
return call(
imageUrl,
"Focus on the 12-digit Aadhaar number printed on the card (often vertical on the left). Reply ONLY the 12 digits or NONE.",
headers
)
}
private fun call(imageUrl: String, prompt: String, headers: HttpHeaders): String? {
val payload = mapOf(
"model" to model,
"instructions" to "Read extremely carefully. Reply ONLY the 12 digits or NONE. No extra text.",
@@ -41,7 +59,7 @@ class OpenAIVisionClient(
"content" to listOf(
mapOf(
"type" to "input_text",
"text" to "Read extremely carefully. Aadhaar number = 12 digits. Reply ONLY the 12 digits or NONE."
"text" to prompt
),
mapOf(
"type" to "input_image",
@@ -52,10 +70,6 @@ class OpenAIVisionClient(
)
)
)
val headers = HttpHeaders()
headers.contentType = MediaType.APPLICATION_JSON
headers.setBearerAuth(apiKey)
val entity = HttpEntity(payload, headers)
return try {
logger.info("OpenAI fallback request model={} url={}", model, baseUrl)