Log OpenAI fallback prompt and output summary
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:
@@ -32,7 +32,12 @@ class OpenAIVisionClient(
|
||||
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)
|
||||
val first = call(
|
||||
imageUrl,
|
||||
"Read extremely carefully. Aadhaar number = 12 digits. Reply ONLY the 12 digits or NONE.",
|
||||
"aadhaar_default",
|
||||
headers
|
||||
)
|
||||
if (!first.isNullOrBlank() && !first.equals("NONE", ignoreCase = true)) {
|
||||
return first
|
||||
}
|
||||
@@ -42,11 +47,12 @@ class OpenAIVisionClient(
|
||||
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.",
|
||||
"aadhaar_left_strip",
|
||||
headers
|
||||
)
|
||||
}
|
||||
|
||||
private fun call(imageUrl: String, prompt: String, headers: HttpHeaders): String? {
|
||||
private fun call(imageUrl: String, prompt: String, promptId: 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.",
|
||||
@@ -79,7 +85,11 @@ class OpenAIVisionClient(
|
||||
|
||||
val outputText = node.path("output_text").asText()
|
||||
if (outputText.isNotBlank()) {
|
||||
logger.info("OpenAI fallback output_text length={}", outputText.trim().length)
|
||||
logger.info(
|
||||
"OpenAI fallback output_text prompt={} result={}",
|
||||
promptId,
|
||||
summarizeOutput(outputText)
|
||||
)
|
||||
return outputText
|
||||
}
|
||||
|
||||
@@ -89,7 +99,11 @@ class OpenAIVisionClient(
|
||||
if (content.isArray && content.size() > 0) {
|
||||
val text = content[0].path("text").asText()
|
||||
if (text.isNotBlank()) {
|
||||
logger.info("OpenAI fallback content text length={}", text.trim().length)
|
||||
logger.info(
|
||||
"OpenAI fallback content text prompt={} result={}",
|
||||
promptId,
|
||||
summarizeOutput(text)
|
||||
)
|
||||
return text
|
||||
}
|
||||
}
|
||||
@@ -109,4 +123,11 @@ class OpenAIVisionClient(
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun summarizeOutput(value: String): String {
|
||||
val trimmed = value.trim()
|
||||
if (trimmed.equals("NONE", ignoreCase = true)) return "NONE"
|
||||
val digits = trimmed.filter { it.isDigit() }
|
||||
return if (digits.isNotBlank()) "digits_len=${digits.length}" else "text_len=${trimmed.length}"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user