Retry OpenAI fallback with focused Aadhaar prompt
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 32s
This commit is contained in:
@@ -29,6 +29,24 @@ class OpenAIVisionClient(
|
|||||||
return null
|
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(
|
val payload = mapOf(
|
||||||
"model" to model,
|
"model" to model,
|
||||||
"instructions" to "Read extremely carefully. Reply ONLY the 12 digits or NONE. No extra text.",
|
"instructions" to "Read extremely carefully. Reply ONLY the 12 digits or NONE. No extra text.",
|
||||||
@@ -41,7 +59,7 @@ class OpenAIVisionClient(
|
|||||||
"content" to listOf(
|
"content" to listOf(
|
||||||
mapOf(
|
mapOf(
|
||||||
"type" to "input_text",
|
"type" to "input_text",
|
||||||
"text" to "Read extremely carefully. Aadhaar number = 12 digits. Reply ONLY the 12 digits or NONE."
|
"text" to prompt
|
||||||
),
|
),
|
||||||
mapOf(
|
mapOf(
|
||||||
"type" to "input_image",
|
"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)
|
val entity = HttpEntity(payload, headers)
|
||||||
return try {
|
return try {
|
||||||
logger.info("OpenAI fallback request model={} url={}", model, baseUrl)
|
logger.info("OpenAI fallback request model={} url={}", model, baseUrl)
|
||||||
|
|||||||
Reference in New Issue
Block a user