guest docs: improve extractor logic even more

This commit is contained in:
androidlover5842
2026-01-31 03:37:12 +05:30
parent b5aacfc8c6
commit 73f7d41619

View File

@@ -215,21 +215,35 @@ class GuestDocuments(
"${aiBaseUrl}/properties/$propertyId/guests/$guestId/documents/${document.id}/file?token=$token"
val results = linkedMapOf<String, String>()
val detections = listOf(
Detection(
detect = {
results["isVehiclePhoto"] = llamaClient.ask(
imageUrl,
"IS THIS A VEHICLE NUMBER PLATE PHOTO? Answer YES or NO only."
)
if (isYes(results["isVehiclePhoto"])) {
isYes(results["isVehiclePhoto"])
},
handle = {
results["vehicleNumber"] = llamaClient.ask(
imageUrl,
"VEHICLE NUMBER PLATE? Reply only number or NONE."
)
}
results["hasAadhar"] = llamaClient.ask(imageUrl, "CONTAINS AADHAAR? Answer YES or NO only.")
results["hasUidai"] = llamaClient.ask(imageUrl, "CONTAINS UIDAI? Answer YES or NO only.")
val hasAadhar = isYes(results["hasAadhar"]) || isYes(results["hasUidai"])
if (hasAadhar) {
),
Detection(
detect = {
results["hasAadhar"] = llamaClient.ask(
imageUrl,
"CONTAINS AADHAAR? Answer YES or NO only."
)
results["hasUidai"] = llamaClient.ask(
imageUrl,
"CONTAINS UIDAI? Answer YES or NO only."
)
isYes(results["hasAadhar"]) || isYes(results["hasUidai"])
},
handle = {
val aadharQuestions = linkedMapOf(
"hasAddress" to "POSTAL ADDRESS PRESENT? Answer YES or NO only.",
"hasDob" to "DOB? Reply YES or NO.",
@@ -261,8 +275,10 @@ class GuestDocuments(
results[key] = llamaClient.ask(imageUrl, question)
}
}
} else {
}
),
Detection(
detect = {
results["hasDrivingLicence"] = llamaClient.ask(
imageUrl,
"CONTAINS DRIVING LICENCE? Answer YES or NO only."
@@ -271,8 +287,9 @@ class GuestDocuments(
imageUrl,
"CONTAINS TRANSPORT DEPARTMENT? Answer YES or NO only."
)
val isDriving = isYes(results["hasDrivingLicence"]) || isYes(results["hasTransportDept"])
if (isDriving) {
isYes(results["hasDrivingLicence"]) || isYes(results["hasTransportDept"])
},
handle = {
val drivingQuestions = linkedMapOf(
DocumentPrompts.NAME,
DocumentPrompts.DOB,
@@ -286,12 +303,17 @@ class GuestDocuments(
for ((key, question) in drivingQuestions) {
results[key] = llamaClient.ask(imageUrl, question)
}
} else {
}
),
Detection(
detect = {
results["hasElectionCommission"] = llamaClient.ask(
imageUrl,
"CONTAINS ELECTION COMMISSION OF INDIA? Answer YES or NO only."
)
if (isYes(results["hasElectionCommission"])) {
isYes(results["hasElectionCommission"])
},
handle = {
val voterQuestions = linkedMapOf(
DocumentPrompts.NAME,
DocumentPrompts.DOB,
@@ -305,12 +327,17 @@ class GuestDocuments(
for ((key, question) in voterQuestions) {
results[key] = llamaClient.ask(imageUrl, question)
}
} else {
}
),
Detection(
detect = {
results["hasIncomeTaxDept"] = llamaClient.ask(
imageUrl,
"CONTAINS INCOME TAX DEPARTMENT? Answer YES or NO only."
)
if (isYes(results["hasIncomeTaxDept"])) {
isYes(results["hasIncomeTaxDept"])
},
handle = {
val panQuestions = linkedMapOf(
DocumentPrompts.NAME,
DocumentPrompts.DOB,
@@ -324,12 +351,17 @@ class GuestDocuments(
for ((key, question) in panQuestions) {
results[key] = llamaClient.ask(imageUrl, question)
}
} else {
}
),
Detection(
detect = {
results["hasPassport"] = llamaClient.ask(
imageUrl,
"CONTAINS PASSPORT? Answer YES or NO only."
)
if (isYes(results["hasPassport"])) {
isYes(results["hasPassport"])
},
handle = {
val passportQuestions = linkedMapOf(
DocumentPrompts.NAME,
DocumentPrompts.DOB,
@@ -343,7 +375,20 @@ class GuestDocuments(
for ((key, question) in passportQuestions) {
results[key] = llamaClient.ask(imageUrl, question)
}
} else {
}
)
)
var handled = false
for (detection in detections) {
if (detection.detect()) {
detection.handle()
handled = true
break
}
}
if (!handled) {
val generalQuestions = linkedMapOf(
DocumentPrompts.NAME,
DocumentPrompts.DOB,
@@ -359,12 +404,9 @@ class GuestDocuments(
results[key] = llamaClient.ask(imageUrl, question)
}
}
}
}
}
}
results["docType"] = when {
!handled -> "GENERAL"
isYes(results["hasCourt"]) ||
isYes(results["hasHighCourt"]) ||
isYes(results["hasSupremeCourt"]) ||
@@ -505,6 +547,11 @@ private fun isYes(value: String?): Boolean {
return value.orEmpty().contains("YES", ignoreCase = true)
}
private data class Detection(
val detect: () -> Boolean,
val handle: () -> Unit
)
private fun cleanedValue(value: String?): String? {
val trimmed = value?.trim().orEmpty()
if (trimmed.isBlank()) return null