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()
|
val headers = HttpHeaders()
|
||||||
headers.contentType = MediaType.APPLICATION_JSON
|
headers.contentType = MediaType.APPLICATION_JSON
|
||||||
headers.setBearerAuth(apiKey)
|
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)) {
|
if (!first.isNullOrBlank() && !first.equals("NONE", ignoreCase = true)) {
|
||||||
return first
|
return first
|
||||||
}
|
}
|
||||||
@@ -42,11 +47,12 @@ class OpenAIVisionClient(
|
|||||||
return call(
|
return call(
|
||||||
imageUrl,
|
imageUrl,
|
||||||
"Focus on the 12-digit Aadhaar number printed on the card (often vertical on the left). Reply ONLY the 12 digits or NONE.",
|
"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
|
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(
|
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.",
|
||||||
@@ -79,7 +85,11 @@ class OpenAIVisionClient(
|
|||||||
|
|
||||||
val outputText = node.path("output_text").asText()
|
val outputText = node.path("output_text").asText()
|
||||||
if (outputText.isNotBlank()) {
|
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
|
return outputText
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +99,11 @@ class OpenAIVisionClient(
|
|||||||
if (content.isArray && content.size() > 0) {
|
if (content.isArray && content.size() > 0) {
|
||||||
val text = content[0].path("text").asText()
|
val text = content[0].path("text").asText()
|
||||||
if (text.isNotBlank()) {
|
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
|
return text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -109,4 +123,11 @@ class OpenAIVisionClient(
|
|||||||
null
|
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