Spaces:
Sleeping
Sleeping
Commit
·
fde5743
1
Parent(s):
295d256
✨ Add role-based evidence pack generation and fix empty fields
Browse files- Implement role-specific evidence pack content for citizen/employee/officer/pensioner
- Add comprehensive role-based checklists and guidance
- Fix empty clause text, summary, and checklist fields in evidence packs
- Enhance PDF and CSV export with better formatting and role context
- Add user role and language preference to evidence pack metadata
- Create test scripts to validate role-based functionality
- Ensure evidence pack buttons show for all bot responses with content
- app.py +143 -33
- evidence_pack_export.py +13 -0
- test_role_based_evidence.py +152 -0
app.py
CHANGED
|
@@ -24,6 +24,7 @@ def transform_message_to_evidence_pack(raw_data):
|
|
| 24 |
# Extract relevant information from the message
|
| 25 |
message_text = ""
|
| 26 |
sources = []
|
|
|
|
| 27 |
|
| 28 |
if isinstance(raw_data, dict):
|
| 29 |
# Handle different message formats
|
|
@@ -36,6 +37,9 @@ def transform_message_to_evidence_pack(raw_data):
|
|
| 36 |
else:
|
| 37 |
message_text = str(raw_data)
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
# Extract sources if available
|
| 40 |
if 'sources' in raw_data:
|
| 41 |
sources = raw_data.get('sources', [])
|
|
@@ -44,16 +48,17 @@ def transform_message_to_evidence_pack(raw_data):
|
|
| 44 |
else:
|
| 45 |
message_text = str(raw_data)
|
| 46 |
|
| 47 |
-
# Create evidence pack data structure
|
| 48 |
evidence_data = {
|
| 49 |
-
"clause_text": extract_clause_from_message(message_text),
|
| 50 |
-
"summary": create_summary_from_message(message_text),
|
| 51 |
-
"role_checklist": extract_checklist_from_message(message_text),
|
| 52 |
-
"source_title": "Rajasthan Pension Rules - Voice Bot Response",
|
| 53 |
-
"clause_id": f"VB_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
| 54 |
"date": datetime.now().strftime("%Y-%m-%d"),
|
| 55 |
"url": "https://chabhishek28-pensionbot.hf.space",
|
| 56 |
"original_query": raw_data.get('query', '') if isinstance(raw_data, dict) else '',
|
|
|
|
| 57 |
"sources": sources,
|
| 58 |
"timestamp": datetime.now().isoformat()
|
| 59 |
}
|
|
@@ -74,56 +79,161 @@ def transform_message_to_evidence_pack(raw_data):
|
|
| 74 |
"timestamp": datetime.now().isoformat()
|
| 75 |
}
|
| 76 |
|
| 77 |
-
def extract_clause_from_message(text):
|
| 78 |
-
"""Extract or generate clause information from message text"""
|
| 79 |
# Look for pension-related keywords to categorize
|
| 80 |
text_lower = text.lower()
|
| 81 |
|
| 82 |
if any(word in text_lower for word in ['pension', 'retirement', 'superannuation']):
|
| 83 |
if 'commutation' in text_lower:
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
elif 'eligibility' in text_lower:
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
elif 'family pension' in text_lower:
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
| 89 |
else:
|
| 90 |
-
return "Rajasthan Pension Rules - General Provisions: Pension benefits are governed by applicable government rules and regulations."
|
| 91 |
else:
|
| 92 |
-
return f"Government Policy Response: {text[:200]}..." if len(text) > 200 else text
|
| 93 |
|
| 94 |
-
def create_summary_from_message(text):
|
| 95 |
-
"""Create a summary for the evidence pack"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
if len(text) > 100:
|
| 97 |
-
return f"
|
| 98 |
else:
|
| 99 |
-
return f"
|
| 100 |
|
| 101 |
-
def extract_checklist_from_message(text):
|
| 102 |
-
"""Extract or generate checklist items from message"""
|
| 103 |
text_lower = text.lower()
|
| 104 |
checklist = []
|
| 105 |
|
| 106 |
-
#
|
| 107 |
if 'pension' in text_lower:
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
if 'application' in text_lower or 'apply' in text_lower:
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
|
| 115 |
if 'commutation' in text_lower:
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
-
# Default checklist items
|
| 120 |
if not checklist:
|
| 121 |
-
|
| 122 |
-
"
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
return checklist
|
| 129 |
|
|
|
|
| 24 |
# Extract relevant information from the message
|
| 25 |
message_text = ""
|
| 26 |
sources = []
|
| 27 |
+
user_role = "citizen" # default role
|
| 28 |
|
| 29 |
if isinstance(raw_data, dict):
|
| 30 |
# Handle different message formats
|
|
|
|
| 37 |
else:
|
| 38 |
message_text = str(raw_data)
|
| 39 |
|
| 40 |
+
# Extract user role from the data
|
| 41 |
+
user_role = raw_data.get('user_role', raw_data.get('role', 'citizen'))
|
| 42 |
+
|
| 43 |
# Extract sources if available
|
| 44 |
if 'sources' in raw_data:
|
| 45 |
sources = raw_data.get('sources', [])
|
|
|
|
| 48 |
else:
|
| 49 |
message_text = str(raw_data)
|
| 50 |
|
| 51 |
+
# Create evidence pack data structure with role-based customization
|
| 52 |
evidence_data = {
|
| 53 |
+
"clause_text": extract_clause_from_message(message_text, user_role),
|
| 54 |
+
"summary": create_summary_from_message(message_text, user_role),
|
| 55 |
+
"role_checklist": extract_checklist_from_message(message_text, user_role),
|
| 56 |
+
"source_title": f"Rajasthan Pension Rules - Voice Bot Response ({user_role.title()})",
|
| 57 |
+
"clause_id": f"VB_{user_role.upper()}_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
| 58 |
"date": datetime.now().strftime("%Y-%m-%d"),
|
| 59 |
"url": "https://chabhishek28-pensionbot.hf.space",
|
| 60 |
"original_query": raw_data.get('query', '') if isinstance(raw_data, dict) else '',
|
| 61 |
+
"user_role": user_role,
|
| 62 |
"sources": sources,
|
| 63 |
"timestamp": datetime.now().isoformat()
|
| 64 |
}
|
|
|
|
| 79 |
"timestamp": datetime.now().isoformat()
|
| 80 |
}
|
| 81 |
|
| 82 |
+
def extract_clause_from_message(text, user_role="citizen"):
|
| 83 |
+
"""Extract or generate clause information from message text based on user role"""
|
| 84 |
# Look for pension-related keywords to categorize
|
| 85 |
text_lower = text.lower()
|
| 86 |
|
| 87 |
if any(word in text_lower for word in ['pension', 'retirement', 'superannuation']):
|
| 88 |
if 'commutation' in text_lower:
|
| 89 |
+
if user_role == "employee":
|
| 90 |
+
return "Rajasthan Pension Rules - Commutation of Pension (Employee): As a government employee, you may commute up to one-third of your pension. Calculate commutation value using prescribed formula: (Pension × Commutation Factor × 12)."
|
| 91 |
+
elif user_role == "officer":
|
| 92 |
+
return "Rajasthan Pension Rules - Commutation of Pension (Officer): Administrative guidance: Officers may authorize commutation up to 1/3rd pension. Ensure proper documentation and verification before approval."
|
| 93 |
+
elif user_role == "pensioner":
|
| 94 |
+
return "Rajasthan Pension Rules - Commutation of Pension (Pensioner): Your commuted pension amount is calculated based on age at retirement and commutation factors. Contact pension disbursing office for arrears or revision queries."
|
| 95 |
+
else:
|
| 96 |
+
return "Rajasthan Pension Rules - Commutation of Pension (Citizen): Eligible government employees may commute up to one-third of their pension as lump sum. Consult with pension department for eligibility."
|
| 97 |
+
|
| 98 |
elif 'eligibility' in text_lower:
|
| 99 |
+
if user_role == "employee":
|
| 100 |
+
return "Rajasthan Pension Rules - Eligibility Criteria (Employee): You need minimum 10 years qualifying service for pension eligibility. Check your service record and ensure all periods are counted."
|
| 101 |
+
elif user_role == "officer":
|
| 102 |
+
return "Rajasthan Pension Rules - Eligibility Criteria (Officer): Verify employee's qualifying service, break periods, and ensure proper service verification before pension processing."
|
| 103 |
+
elif user_role == "pensioner":
|
| 104 |
+
return "Rajasthan Pension Rules - Eligibility Criteria (Pensioner): Your pension eligibility was established at retirement. For revision queries, check service verification and pay fixation records."
|
| 105 |
+
else:
|
| 106 |
+
return "Rajasthan Pension Rules - Eligibility Criteria (Citizen): Government employees are eligible for pension after completing minimum qualifying service as per rules."
|
| 107 |
+
|
| 108 |
elif 'family pension' in text_lower:
|
| 109 |
+
if user_role == "pensioner":
|
| 110 |
+
return "Rajasthan Pension Rules - Family Pension (Pensioner): Your spouse/family is entitled to family pension after your demise. Ensure nomination and family details are updated."
|
| 111 |
+
else:
|
| 112 |
+
return "Rajasthan Pension Rules - Family Pension: Family members are entitled to family pension as per prescribed conditions and rates."
|
| 113 |
else:
|
| 114 |
+
return f"Rajasthan Pension Rules - General Provisions ({user_role.title()}): Pension benefits are governed by applicable government rules and regulations."
|
| 115 |
else:
|
| 116 |
+
return f"Government Policy Response ({user_role.title()}): {text[:200]}..." if len(text) > 200 else text
|
| 117 |
|
| 118 |
+
def create_summary_from_message(text, user_role="citizen"):
|
| 119 |
+
"""Create a summary for the evidence pack based on user role"""
|
| 120 |
+
role_prefixes = {
|
| 121 |
+
"citizen": "Rajasthan Pension Rules: Citizen Guidance",
|
| 122 |
+
"employee": "Rajasthan Pension Rules: Employee Information",
|
| 123 |
+
"officer": "Rajasthan Pension Rules: Administrative Guidance",
|
| 124 |
+
"pensioner": "Rajasthan Pension Rules: Pensioner Support"
|
| 125 |
+
}
|
| 126 |
+
|
| 127 |
+
prefix = role_prefixes.get(user_role, "Rajasthan Pension Rules: AI Assistant Response")
|
| 128 |
+
|
| 129 |
if len(text) > 100:
|
| 130 |
+
return f"{prefix} - {text[:100]}..."
|
| 131 |
else:
|
| 132 |
+
return f"{prefix} - {text}"
|
| 133 |
|
| 134 |
+
def extract_checklist_from_message(text, user_role="citizen"):
|
| 135 |
+
"""Extract or generate checklist items from message based on user role"""
|
| 136 |
text_lower = text.lower()
|
| 137 |
checklist = []
|
| 138 |
|
| 139 |
+
# Role-specific checklist items based on content
|
| 140 |
if 'pension' in text_lower:
|
| 141 |
+
if user_role == "citizen":
|
| 142 |
+
checklist.extend([
|
| 143 |
+
"Check your eligibility for pension scheme",
|
| 144 |
+
"Gather required documents (service certificate, age proof)",
|
| 145 |
+
"Visit nearest pension office for application",
|
| 146 |
+
"Keep copies of all submitted documents"
|
| 147 |
+
])
|
| 148 |
+
elif user_role == "employee":
|
| 149 |
+
checklist.extend([
|
| 150 |
+
"Verify your service record for pension eligibility",
|
| 151 |
+
"Check pension calculation with current pay scale",
|
| 152 |
+
"Update nomination and family details",
|
| 153 |
+
"Submit pension papers 6 months before retirement"
|
| 154 |
+
])
|
| 155 |
+
elif user_role == "officer":
|
| 156 |
+
checklist.extend([
|
| 157 |
+
"Verify employee's qualifying service period",
|
| 158 |
+
"Check all service breaks and regularization",
|
| 159 |
+
"Ensure proper documentation and approvals",
|
| 160 |
+
"Process pension papers as per rules and timeline"
|
| 161 |
+
])
|
| 162 |
+
elif user_role == "pensioner":
|
| 163 |
+
checklist.extend([
|
| 164 |
+
"Verify pension calculation and arrears",
|
| 165 |
+
"Check family pension eligibility and nomination",
|
| 166 |
+
"Update bank details and address changes",
|
| 167 |
+
"Submit life certificate annually for pension continuity"
|
| 168 |
+
])
|
| 169 |
|
| 170 |
if 'application' in text_lower or 'apply' in text_lower:
|
| 171 |
+
if user_role == "citizen":
|
| 172 |
+
checklist.extend([
|
| 173 |
+
"Download application form from official website",
|
| 174 |
+
"Prepare required documents and attestation",
|
| 175 |
+
"Submit application within prescribed timeline"
|
| 176 |
+
])
|
| 177 |
+
elif user_role == "employee":
|
| 178 |
+
checklist.extend([
|
| 179 |
+
"Fill pension application form completely",
|
| 180 |
+
"Attach service verification certificates",
|
| 181 |
+
"Get departmental clearances before submission"
|
| 182 |
+
])
|
| 183 |
+
else:
|
| 184 |
+
checklist.extend([
|
| 185 |
+
"Prepare required documents",
|
| 186 |
+
"Submit application to concerned department"
|
| 187 |
+
])
|
| 188 |
|
| 189 |
if 'commutation' in text_lower:
|
| 190 |
+
if user_role == "employee":
|
| 191 |
+
checklist.extend([
|
| 192 |
+
"Calculate commutation value using current pay scale",
|
| 193 |
+
"Consider tax implications of lump sum amount",
|
| 194 |
+
"Submit commutation application with pension papers"
|
| 195 |
+
])
|
| 196 |
+
elif user_role == "pensioner":
|
| 197 |
+
checklist.extend([
|
| 198 |
+
"Check commutation arrears calculation",
|
| 199 |
+
"Verify commutation factor used in calculation",
|
| 200 |
+
"Contact pension office for payment status"
|
| 201 |
+
])
|
| 202 |
+
else:
|
| 203 |
+
checklist.extend([
|
| 204 |
+
"Calculate commutation amount",
|
| 205 |
+
"Consider financial implications"
|
| 206 |
+
])
|
| 207 |
|
| 208 |
+
# Default role-specific checklist items if no specific matches
|
| 209 |
if not checklist:
|
| 210 |
+
default_checklists = {
|
| 211 |
+
"citizen": [
|
| 212 |
+
"Review information for your specific situation",
|
| 213 |
+
"Consult with local government office",
|
| 214 |
+
"Verify eligibility criteria",
|
| 215 |
+
"Keep records for future reference"
|
| 216 |
+
],
|
| 217 |
+
"employee": [
|
| 218 |
+
"Check departmental circulars and updates",
|
| 219 |
+
"Verify with your administrative office",
|
| 220 |
+
"Update your service records if needed",
|
| 221 |
+
"Follow proper departmental procedures"
|
| 222 |
+
],
|
| 223 |
+
"officer": [
|
| 224 |
+
"Refer to latest government rules and circulars",
|
| 225 |
+
"Ensure compliance with administrative procedures",
|
| 226 |
+
"Verify delegated authority for decision making",
|
| 227 |
+
"Document all actions taken"
|
| 228 |
+
],
|
| 229 |
+
"pensioner": [
|
| 230 |
+
"Verify pension calculation and payments",
|
| 231 |
+
"Keep pension payment order copy safe",
|
| 232 |
+
"Update address and bank details regularly",
|
| 233 |
+
"Contact pension disbursing office for queries"
|
| 234 |
+
]
|
| 235 |
+
}
|
| 236 |
+
checklist = default_checklists.get(user_role, default_checklists["citizen"])
|
| 237 |
|
| 238 |
return checklist
|
| 239 |
|
evidence_pack_export.py
CHANGED
|
@@ -50,6 +50,13 @@ def export_evidence_pack_pdf(data, filename=None):
|
|
| 50 |
pdf.multi_cell(0, 6, f"Clause ID: {data.get('clause_id', 'Not assigned')}")
|
| 51 |
pdf.multi_cell(0, 6, f"Date: {data.get('date', 'Not specified')}")
|
| 52 |
pdf.multi_cell(0, 6, f"URL: {data.get('url', 'Not available')}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
pdf.ln(5)
|
| 54 |
scenario = data.get('scenario_analysis',{})
|
| 55 |
if scenario:
|
|
@@ -98,6 +105,12 @@ def export_evidence_pack_csv(data, filename=None):
|
|
| 98 |
# Add original query if available
|
| 99 |
if 'original_query' in data:
|
| 100 |
writer.writerow(["Original Query", data.get('original_query', '')])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
scenario = data.get('scenario_analysis', {})
|
| 103 |
if scenario:
|
|
|
|
| 50 |
pdf.multi_cell(0, 6, f"Clause ID: {data.get('clause_id', 'Not assigned')}")
|
| 51 |
pdf.multi_cell(0, 6, f"Date: {data.get('date', 'Not specified')}")
|
| 52 |
pdf.multi_cell(0, 6, f"URL: {data.get('url', 'Not available')}")
|
| 53 |
+
|
| 54 |
+
# User role and context information
|
| 55 |
+
if data.get('user_role'):
|
| 56 |
+
pdf.multi_cell(0, 6, f"User Role: {data.get('user_role', '').title()}")
|
| 57 |
+
if data.get('language_preference'):
|
| 58 |
+
pdf.multi_cell(0, 6, f"Language: {data.get('language_preference', '').title()}")
|
| 59 |
+
|
| 60 |
pdf.ln(5)
|
| 61 |
scenario = data.get('scenario_analysis',{})
|
| 62 |
if scenario:
|
|
|
|
| 105 |
# Add original query if available
|
| 106 |
if 'original_query' in data:
|
| 107 |
writer.writerow(["Original Query", data.get('original_query', '')])
|
| 108 |
+
|
| 109 |
+
# Add user context information
|
| 110 |
+
if 'user_role' in data:
|
| 111 |
+
writer.writerow(["User Role", data.get('user_role', '').title()])
|
| 112 |
+
if 'language_preference' in data:
|
| 113 |
+
writer.writerow(["Language Preference", data.get('language_preference', '').title()])
|
| 114 |
|
| 115 |
scenario = data.get('scenario_analysis', {})
|
| 116 |
if scenario:
|
test_role_based_evidence.py
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Test script to verify role-based evidence pack generation
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
import os
|
| 8 |
+
sys.path.append(os.path.dirname(__file__))
|
| 9 |
+
|
| 10 |
+
from datetime import datetime
|
| 11 |
+
|
| 12 |
+
# Test data for different user roles
|
| 13 |
+
test_scenarios = [
|
| 14 |
+
{
|
| 15 |
+
"role": "citizen",
|
| 16 |
+
"query": "What are the pension eligibility criteria in Rajasthan?",
|
| 17 |
+
"expected_focus": "Simple eligibility explanation, application process"
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"role": "employee",
|
| 21 |
+
"query": "How to calculate my pension amount?",
|
| 22 |
+
"expected_focus": "Service record verification, calculation formula"
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"role": "officer",
|
| 26 |
+
"query": "What is the process for pension approval?",
|
| 27 |
+
"expected_focus": "Administrative procedures, verification steps"
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"role": "pensioner",
|
| 31 |
+
"query": "How to get my pension arrears?",
|
| 32 |
+
"expected_focus": "Arrears calculation, payment procedures"
|
| 33 |
+
}
|
| 34 |
+
]
|
| 35 |
+
|
| 36 |
+
def simulate_transform_message_to_evidence_pack(message_text, user_role):
|
| 37 |
+
"""Simulate the evidence pack transformation for testing"""
|
| 38 |
+
|
| 39 |
+
# Simulate role-based clause extraction
|
| 40 |
+
def extract_clause_simulation(text, role):
|
| 41 |
+
if "pension" in text.lower():
|
| 42 |
+
if role == "citizen":
|
| 43 |
+
return "Rajasthan Pension Rules - For Citizens: Basic eligibility and application guidance for government pension schemes."
|
| 44 |
+
elif role == "employee":
|
| 45 |
+
return "Rajasthan Pension Rules - For Employees: Detailed service requirements and pension calculation procedures for government servants."
|
| 46 |
+
elif role == "officer":
|
| 47 |
+
return "Rajasthan Pension Rules - For Officers: Administrative guidelines for pension processing, verification, and approval procedures."
|
| 48 |
+
elif role == "pensioner":
|
| 49 |
+
return "Rajasthan Pension Rules - For Pensioners: Information on pension disbursement, revisions, and grievance procedures."
|
| 50 |
+
return f"Government Policy Response ({role.title()}): General guidance based on your role."
|
| 51 |
+
|
| 52 |
+
# Simulate role-based checklist
|
| 53 |
+
def extract_checklist_simulation(text, role):
|
| 54 |
+
base_items = []
|
| 55 |
+
if "pension" in text.lower():
|
| 56 |
+
if role == "citizen":
|
| 57 |
+
base_items = [
|
| 58 |
+
"Check eligibility criteria for pension scheme",
|
| 59 |
+
"Gather required documents (service certificate, age proof)",
|
| 60 |
+
"Visit local pension office for application",
|
| 61 |
+
"Keep copies of all documents"
|
| 62 |
+
]
|
| 63 |
+
elif role == "employee":
|
| 64 |
+
base_items = [
|
| 65 |
+
"Verify service record and qualifying service",
|
| 66 |
+
"Calculate pension with current pay scale",
|
| 67 |
+
"Update nomination and family details",
|
| 68 |
+
"Submit pension application 6 months before retirement"
|
| 69 |
+
]
|
| 70 |
+
elif role == "officer":
|
| 71 |
+
base_items = [
|
| 72 |
+
"Verify employee's complete service record",
|
| 73 |
+
"Check all service breaks and regularization",
|
| 74 |
+
"Ensure proper documentation and approvals",
|
| 75 |
+
"Process within prescribed timeline"
|
| 76 |
+
]
|
| 77 |
+
elif role == "pensioner":
|
| 78 |
+
base_items = [
|
| 79 |
+
"Verify pension calculation and any arrears due",
|
| 80 |
+
"Check family pension nomination status",
|
| 81 |
+
"Update bank details and address regularly",
|
| 82 |
+
"Submit annual life certificate"
|
| 83 |
+
]
|
| 84 |
+
return base_items
|
| 85 |
+
|
| 86 |
+
return {
|
| 87 |
+
"clause_text": extract_clause_simulation(message_text, user_role),
|
| 88 |
+
"summary": f"Rajasthan Pension Rules: {user_role.title()} Guidance - {message_text[:50]}...",
|
| 89 |
+
"role_checklist": extract_checklist_simulation(message_text, user_role),
|
| 90 |
+
"source_title": f"Rajasthan Pension Rules - Voice Bot Response ({user_role.title()})",
|
| 91 |
+
"clause_id": f"VB_{user_role.upper()}_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
| 92 |
+
"user_role": user_role,
|
| 93 |
+
"date": datetime.now().strftime("%Y-%m-%d")
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
def test_role_based_evidence_packs():
|
| 97 |
+
"""Test evidence pack generation for different user roles"""
|
| 98 |
+
print("🎭 Testing Role-Based Evidence Pack Generation\n")
|
| 99 |
+
|
| 100 |
+
for i, scenario in enumerate(test_scenarios, 1):
|
| 101 |
+
role = scenario["role"]
|
| 102 |
+
query = scenario["query"]
|
| 103 |
+
expected = scenario["expected_focus"]
|
| 104 |
+
|
| 105 |
+
print(f"=== Test {i}: {role.upper()} ROLE ===")
|
| 106 |
+
print(f"Query: {query}")
|
| 107 |
+
print(f"Expected Focus: {expected}")
|
| 108 |
+
|
| 109 |
+
# Generate evidence pack
|
| 110 |
+
evidence = simulate_transform_message_to_evidence_pack(query, role)
|
| 111 |
+
|
| 112 |
+
print(f"\n📋 Generated Evidence Pack:")
|
| 113 |
+
print(f" Clause: {evidence['clause_text'][:80]}...")
|
| 114 |
+
print(f" Summary: {evidence['summary']}")
|
| 115 |
+
print(f" Role-specific Checklist:")
|
| 116 |
+
for item in evidence['role_checklist']:
|
| 117 |
+
print(f" • {item}")
|
| 118 |
+
print(f" Source: {evidence['source_title']}")
|
| 119 |
+
print(f" Clause ID: {evidence['clause_id']}\n")
|
| 120 |
+
|
| 121 |
+
# Check if role is properly reflected
|
| 122 |
+
if role.upper() in evidence['clause_id']:
|
| 123 |
+
print(f"✅ Role properly reflected in Clause ID")
|
| 124 |
+
else:
|
| 125 |
+
print(f"❌ Role not found in Clause ID")
|
| 126 |
+
|
| 127 |
+
if role.title() in evidence['source_title']:
|
| 128 |
+
print(f"✅ Role properly reflected in Source Title")
|
| 129 |
+
else:
|
| 130 |
+
print(f"❌ Role not found in Source Title")
|
| 131 |
+
|
| 132 |
+
print("-" * 60)
|
| 133 |
+
|
| 134 |
+
def demonstrate_role_differences():
|
| 135 |
+
"""Demonstrate how the same query gets different responses for different roles"""
|
| 136 |
+
print("\n🔍 Demonstrating Role-Based Response Differences")
|
| 137 |
+
print("Same Query: 'How to apply for pension?'\n")
|
| 138 |
+
|
| 139 |
+
query = "How to apply for pension?"
|
| 140 |
+
|
| 141 |
+
for role in ["citizen", "employee", "officer", "pensioner"]:
|
| 142 |
+
evidence = simulate_transform_message_to_evidence_pack(query, role)
|
| 143 |
+
print(f"👤 {role.upper()} perspective:")
|
| 144 |
+
print(f" Checklist highlights:")
|
| 145 |
+
for i, item in enumerate(evidence['role_checklist'][:3], 1):
|
| 146 |
+
print(f" {i}. {item}")
|
| 147 |
+
print()
|
| 148 |
+
|
| 149 |
+
if __name__ == "__main__":
|
| 150 |
+
test_role_based_evidence_packs()
|
| 151 |
+
demonstrate_role_differences()
|
| 152 |
+
print("🎯 Role-based evidence pack testing completed!")
|