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