Compare commits
2 Commits
45862dc7f3
...
e0643ce695
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0643ce695 | ||
|
|
d4a9a06725 |
@@ -0,0 +1,13 @@
|
|||||||
|
package com.android.trisolarisserver.controller
|
||||||
|
|
||||||
|
object DocumentPrompts {
|
||||||
|
val NAME = "name" to "NAME? Reply only the name or NONE."
|
||||||
|
val DOB = "dob" to "DOB? Reply only date or NONE."
|
||||||
|
val ID_NUMBER = "idNumber" to "ID NUMBER? Reply only number or NONE."
|
||||||
|
val ADDRESS = "address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE."
|
||||||
|
val PIN_CODE = "pinCode" to "POSTAL PIN CODE? Reply only pin or NONE."
|
||||||
|
val CITY = "city" to "CITY? Reply only city or NONE."
|
||||||
|
val GENDER = "gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE."
|
||||||
|
val NATIONALITY = "nationality" to "NATIONALITY? Reply only nationality or NONE."
|
||||||
|
val VEHICLE_NUMBER = "vehicleNumber" to "VEHICLE NUMBER? Reply only number or NONE."
|
||||||
|
}
|
||||||
@@ -212,6 +212,17 @@ 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>()
|
||||||
|
results["isVehiclePhoto"] = llamaClient.ask(
|
||||||
|
imageUrl,
|
||||||
|
"IS THIS A VEHICLE NUMBER PLATE PHOTO? Answer YES or NO only."
|
||||||
|
)
|
||||||
|
if (isYes(results["isVehiclePhoto"])) {
|
||||||
|
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["hasAadhar"] = llamaClient.ask(imageUrl, "CONTAINS AADHAAR? Answer YES or NO only.")
|
||||||
results["hasUidai"] = llamaClient.ask(imageUrl, "CONTAINS UIDAI? 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"])
|
val hasAadhar = isYes(results["hasAadhar"]) || isYes(results["hasUidai"])
|
||||||
@@ -227,8 +238,8 @@ class GuestDocuments(
|
|||||||
val hasAddress = isYes(results["hasAddress"])
|
val hasAddress = isYes(results["hasAddress"])
|
||||||
if (hasAddress) {
|
if (hasAddress) {
|
||||||
val addressQuestions = linkedMapOf(
|
val addressQuestions = linkedMapOf(
|
||||||
"pinCode" to "POSTAL ADDRESS PIN CODE (6 digit)? Reply only pin or NONE.",
|
DocumentPrompts.PIN_CODE,
|
||||||
"address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE."
|
DocumentPrompts.ADDRESS
|
||||||
)
|
)
|
||||||
for ((key, question) in addressQuestions) {
|
for ((key, question) in addressQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
@@ -238,10 +249,10 @@ class GuestDocuments(
|
|||||||
val hasGender = isYes(results["hasGenderMentioned"])
|
val hasGender = isYes(results["hasGenderMentioned"])
|
||||||
if (hasDob && hasGender) {
|
if (hasDob && hasGender) {
|
||||||
val aadharFrontQuestions = linkedMapOf(
|
val aadharFrontQuestions = linkedMapOf(
|
||||||
"name" to "NAME? Reply only the name or NONE.",
|
DocumentPrompts.NAME,
|
||||||
"dob" to "DOB? Reply only date or NONE.",
|
DocumentPrompts.DOB,
|
||||||
"idNumber" to "ID NUMBER? Reply only number or NONE.",
|
DocumentPrompts.ID_NUMBER,
|
||||||
"gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE."
|
DocumentPrompts.GENDER
|
||||||
)
|
)
|
||||||
for ((key, question) in aadharFrontQuestions) {
|
for ((key, question) in aadharFrontQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
@@ -249,91 +260,114 @@ class GuestDocuments(
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
val detectionQuestions = linkedMapOf(
|
if (isYes(results["isVehiclePhoto"])) {
|
||||||
"hasDrivingLicence" to "CONTAINS DRIVING LICENCE? Answer YES or NO only.",
|
val vehicleQuestions = linkedMapOf(
|
||||||
"hasTransportDept" to "CONTAINS TRANSPORT DEPARTMENT? Answer YES or NO only.",
|
"vehicleNumber" to "VEHICLE NUMBER PLATE? Reply only number or NONE."
|
||||||
"hasElectionCommission" to "CONTAINS ELECTION COMMISSION OF INDIA? Answer YES or NO only.",
|
|
||||||
"hasIncomeTaxDept" to "CONTAINS INCOME TAX DEPARTMENT? Answer YES or NO only.",
|
|
||||||
"hasPassport" to "CONTAINS PASSPORT? Answer YES or NO only."
|
|
||||||
)
|
)
|
||||||
for ((key, question) in detectionQuestions) {
|
for ((key, question) in vehicleQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
results["hasDrivingLicence"] = llamaClient.ask(
|
||||||
|
imageUrl,
|
||||||
|
"CONTAINS DRIVING LICENCE? Answer YES or NO only."
|
||||||
|
)
|
||||||
|
results["hasTransportDept"] = llamaClient.ask(
|
||||||
|
imageUrl,
|
||||||
|
"CONTAINS TRANSPORT DEPARTMENT? Answer YES or NO only."
|
||||||
|
)
|
||||||
val isDriving = isYes(results["hasDrivingLicence"]) || isYes(results["hasTransportDept"])
|
val isDriving = isYes(results["hasDrivingLicence"]) || isYes(results["hasTransportDept"])
|
||||||
if (isDriving) {
|
if (isDriving) {
|
||||||
val drivingQuestions = linkedMapOf(
|
val drivingQuestions = linkedMapOf(
|
||||||
"name" to "NAME? Reply only the name or NONE.",
|
DocumentPrompts.NAME,
|
||||||
"dob" to "DOB? Reply only date or NONE.",
|
DocumentPrompts.DOB,
|
||||||
"idNumber" to "DL NUMBER? Reply only number or NONE.",
|
"idNumber" to "DL NUMBER? Reply only number or NONE.",
|
||||||
"address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE.",
|
DocumentPrompts.ADDRESS,
|
||||||
"pinCode" to "PIN CODE? Reply only pin or NONE.",
|
DocumentPrompts.PIN_CODE,
|
||||||
"city" to "CITY? Reply only city or NONE.",
|
DocumentPrompts.CITY,
|
||||||
"gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE.",
|
DocumentPrompts.GENDER,
|
||||||
"nationality" to "NATIONALITY? Reply only nationality or NONE."
|
DocumentPrompts.NATIONALITY
|
||||||
)
|
)
|
||||||
for ((key, question) in drivingQuestions) {
|
for ((key, question) in drivingQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
}
|
}
|
||||||
} else if (isYes(results["hasElectionCommission"])) {
|
} else {
|
||||||
|
results["hasElectionCommission"] = llamaClient.ask(
|
||||||
|
imageUrl,
|
||||||
|
"CONTAINS ELECTION COMMISSION OF INDIA? Answer YES or NO only."
|
||||||
|
)
|
||||||
|
if (isYes(results["hasElectionCommission"])) {
|
||||||
val voterQuestions = linkedMapOf(
|
val voterQuestions = linkedMapOf(
|
||||||
"name" to "NAME? Reply only the name or NONE.",
|
DocumentPrompts.NAME,
|
||||||
"dob" to "DOB? Reply only date or NONE.",
|
DocumentPrompts.DOB,
|
||||||
"idNumber" to "VOTER ID NUMBER? Reply only number or NONE.",
|
"idNumber" to "VOTER ID NUMBER? Reply only number or NONE.",
|
||||||
"address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE.",
|
DocumentPrompts.ADDRESS,
|
||||||
"pinCode" to "PIN CODE? Reply only pin or NONE.",
|
DocumentPrompts.PIN_CODE,
|
||||||
"city" to "CITY? Reply only city or NONE.",
|
DocumentPrompts.CITY,
|
||||||
"gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE.",
|
DocumentPrompts.GENDER,
|
||||||
"nationality" to "NATIONALITY? Reply only nationality or NONE."
|
DocumentPrompts.NATIONALITY
|
||||||
)
|
)
|
||||||
for ((key, question) in voterQuestions) {
|
for ((key, question) in voterQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
}
|
}
|
||||||
} else if (isYes(results["hasIncomeTaxDept"])) {
|
} else {
|
||||||
|
results["hasIncomeTaxDept"] = llamaClient.ask(
|
||||||
|
imageUrl,
|
||||||
|
"CONTAINS INCOME TAX DEPARTMENT? Answer YES or NO only."
|
||||||
|
)
|
||||||
|
if (isYes(results["hasIncomeTaxDept"])) {
|
||||||
val panQuestions = linkedMapOf(
|
val panQuestions = linkedMapOf(
|
||||||
"name" to "NAME? Reply only the name or NONE.",
|
DocumentPrompts.NAME,
|
||||||
"dob" to "DOB? Reply only date or NONE.",
|
DocumentPrompts.DOB,
|
||||||
"idNumber" to "PAN NUMBER? Reply only number or NONE.",
|
"idNumber" to "PAN NUMBER? Reply only number or NONE.",
|
||||||
"address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE.",
|
DocumentPrompts.ADDRESS,
|
||||||
"pinCode" to "PIN CODE? Reply only pin or NONE.",
|
DocumentPrompts.PIN_CODE,
|
||||||
"city" to "CITY? Reply only city or NONE.",
|
DocumentPrompts.CITY,
|
||||||
"gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE.",
|
DocumentPrompts.GENDER,
|
||||||
"nationality" to "NATIONALITY? Reply only nationality or NONE."
|
DocumentPrompts.NATIONALITY
|
||||||
)
|
)
|
||||||
for ((key, question) in panQuestions) {
|
for ((key, question) in panQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
}
|
}
|
||||||
} else if (isYes(results["hasPassport"])) {
|
} else {
|
||||||
|
results["hasPassport"] = llamaClient.ask(
|
||||||
|
imageUrl,
|
||||||
|
"CONTAINS PASSPORT? Answer YES or NO only."
|
||||||
|
)
|
||||||
|
if (isYes(results["hasPassport"])) {
|
||||||
val passportQuestions = linkedMapOf(
|
val passportQuestions = linkedMapOf(
|
||||||
"name" to "NAME? Reply only the name or NONE.",
|
DocumentPrompts.NAME,
|
||||||
"dob" to "DOB? Reply only date or NONE.",
|
DocumentPrompts.DOB,
|
||||||
"idNumber" to "PASSPORT NUMBER? Reply only number or NONE.",
|
"idNumber" to "PASSPORT NUMBER? Reply only number or NONE.",
|
||||||
"address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE.",
|
DocumentPrompts.ADDRESS,
|
||||||
"pinCode" to "PIN CODE? Reply only pin or NONE.",
|
DocumentPrompts.PIN_CODE,
|
||||||
"city" to "CITY? Reply only city or NONE.",
|
DocumentPrompts.CITY,
|
||||||
"gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE.",
|
DocumentPrompts.GENDER,
|
||||||
"nationality" to "NATIONALITY? Reply only nationality or NONE."
|
DocumentPrompts.NATIONALITY
|
||||||
)
|
)
|
||||||
for ((key, question) in passportQuestions) {
|
for ((key, question) in passportQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val generalQuestions = linkedMapOf(
|
val generalQuestions = linkedMapOf(
|
||||||
"name" to "NAME? Reply only the name or NONE.",
|
DocumentPrompts.NAME,
|
||||||
"dob" to "DOB? Reply only date or NONE.",
|
DocumentPrompts.DOB,
|
||||||
"idNumber" to "ID NUMBER? Reply only number or NONE.",
|
DocumentPrompts.ID_NUMBER,
|
||||||
"address" to "POSTAL ADDRESS ONLY (street/area/city/state). Ignore IDs, UUIDs, and codes. Reply only address or NONE.",
|
DocumentPrompts.ADDRESS,
|
||||||
"vehicleNumber" to "VEHICLE NUMBER? Reply only number or NONE.",
|
DocumentPrompts.VEHICLE_NUMBER,
|
||||||
"pinCode" to "PIN CODE? Reply only pin or NONE.",
|
DocumentPrompts.PIN_CODE,
|
||||||
"city" to "CITY? Reply only city or NONE.",
|
DocumentPrompts.CITY,
|
||||||
"gender" to "GENDER? Reply only MALE/FEMALE/OTHER or NONE.",
|
DocumentPrompts.GENDER,
|
||||||
"nationality" to "NATIONALITY? Reply only nationality or NONE."
|
DocumentPrompts.NATIONALITY
|
||||||
)
|
)
|
||||||
for ((key, question) in generalQuestions) {
|
for ((key, question) in generalQuestions) {
|
||||||
results[key] = llamaClient.ask(imageUrl, question)
|
results[key] = llamaClient.ask(imageUrl, question)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
results["docType"] = when {
|
results["docType"] = when {
|
||||||
isYes(results["hasCourt"]) ||
|
isYes(results["hasCourt"]) ||
|
||||||
@@ -359,7 +393,7 @@ class GuestDocuments(
|
|||||||
document.extractedAt = OffsetDateTime.now()
|
document.extractedAt = OffsetDateTime.now()
|
||||||
guestDocumentRepo.save(document)
|
guestDocumentRepo.save(document)
|
||||||
guestDocumentEvents.emit(propertyId, guestId)
|
guestDocumentEvents.emit(propertyId, guestId)
|
||||||
} catch (_: Exception) {
|
} }catch (_: Exception) {
|
||||||
// Keep upload successful even if AI extraction fails.
|
// Keep upload successful even if AI extraction fails.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user