The AI Chat Assistant is the core feature of CitizenAI, providing intelligent, real-time responses to citizen inquiries using advanced AI technology.
The Chat Assistant leverages IBM Granite models and Watson AI to understand citizen queries and provide accurate, contextual responses about government services, policies, and procedures.
The AI understands queries in natural, everyday language:
=== âExample Queriesâ - âWhat are your office hours?â - âHow do I apply for a business license?â - âWhere can I pay my water bill?â - âWhatâs the process for reporting a pothole?â
=== âAI Capabilitiesâ - Intent Recognition: Identifies what users are trying to accomplish - Entity Extraction: Pulls out important details from queries - Context Awareness: Maintains conversation context - Multi-turn Conversations: Handles follow-up questions
sequenceDiagram
participant C as Citizen
participant UI as Chat Interface
participant AI as AI Engine
participant W as Watson API
C->>UI: Types message
UI->>AI: Process message
AI->>W: Send to Watson
W->>AI: Return response
AI->>UI: Format response
UI->>C: Display answer
!!! tip âGetting the Best Responsesâ - Be specific: âHow do I renew my driverâs license?â vs âdriverâs licenseâ - Use natural language: Write as you would speak to a person - Provide context: Include relevant details about your situation - Ask follow-ups: The AI remembers the conversation context
đ¤ User: What services are available for new residents?
đ¤ AI: Welcome! New residents can access several services:
⢠**Voter Registration**: Register to vote at City Hall or online
⢠**Utility Setup**: Connect water, electric, and waste services
⢠**Library Card**: Get a free library card with proof of residency
⢠**Business Licenses**: Information for starting a business
⢠**Property Records**: Access property tax and assessment information
Would you like specific information about any of these services?
đ¤ User: Tell me more about voter registration
đ¤ AI: Voter registration for new residents:
**Required Documents:**
⢠Photo ID (driver's license or state ID)
⢠Proof of residence (utility bill, lease agreement)
**Registration Options:**
⢠Online: Visit our voter portal
⢠In-person: City Hall, Room 204
⢠By mail: Download and mail the form
**Deadlines:**
⢠Register at least 30 days before any election
⢠Same-day registration available for some elections
**Office Hours:**
⢠Monday-Friday: 8:00 AM - 5:00 PM
⢠Saturday: 9:00 AM - 1:00 PM (election months only)
Need help with anything else?
The AI automatically analyzes the sentiment of conversations:
# Example sentiment analysis result
{
"sentiment": "negative",
"confidence": 0.85,
"indicators": ["frustrated", "angry", "problem"],
"suggested_actions": ["escalate_to_human", "priority_response"]
}
The system recognizes common intents:
| Intent | Description | Example |
|---|---|---|
| Service Request | User needs a specific service | âI need to pay my water billâ |
| Information Inquiry | User seeks information | âWhat are your hours?â |
| Complaint | User has a complaint | âThe streetlight is brokenâ |
| Emergency | Urgent situation | âThereâs a water main breakâ |
The AI maintains conversation context:
graph LR
A[Previous Messages] --> B[Current Context]
C[User Profile] --> B
D[Session Data] --> B
B --> E[Contextual Response]
=== âDemo Modeâ
python
# Uses pre-defined responses
CHAT_MODE = "demo"
RESPONSES = {
"greeting": "Hello! How can I help you today?",
"hours": "Our office hours are Monday-Friday, 8 AM to 5 PM.",
"default": "I'd be happy to help you with that!"
}
=== âAI Modeâ
python
# Uses IBM Watson AI
CHAT_MODE = "ai"
WATSON_CONFIG = {
"api_key": "your_watson_api_key",
"url": "your_watson_url",
"version": "2021-06-14"
}
# Chat configuration
CHAT_CONFIG = {
"max_message_length": 500,
"session_timeout": 1800, # 30 minutes
"enable_history": True,
"enable_sentiment": True,
"escalation_threshold": 0.7 # Negative sentiment threshold
}
import requests
response = requests.post('/api/v1/chat/message', json={
'message': 'What are your office hours?',
'session_id': 'user_session_123'
})
# Response
{
"success": true,
"data": {
"response": "Our office hours are Monday through Friday...",
"confidence": 0.95,
"intent": "hours_inquiry",
"sentiment": "neutral"
}
}
response = requests.get('/api/v1/chat/history', params={
'session_id': 'user_session_123',
'limit': 10
})
pie title AI Response Accuracy
"Accurate Responses" : 85
"Partially Accurate" : 10
"Inaccurate" : 3
"Escalated to Human" : 2
# Verify Watson credentials
echo $WATSON_API_KEY
curl -I https://api.us-south.assistant.watson.cloud.ibm.com
tail -f logs/citizenai.log
When AI is unavailable:
# Language detection and response
SUPPORTED_LANGUAGES = ['en', 'es', 'fr']
def detect_language(message):
# Auto-detect user's language
return language_detector.detect(message)
def respond_in_language(response, target_language):
# Translate response if needed
return translator.translate(response, target_language)
ESCALATION_RULES = {
"negative_sentiment": {"threshold": 0.8, "action": "human_agent"},
"complex_query": {"confidence": 0.3, "action": "specialist"},
"emergency": {"keywords": ["emergency", "urgent"], "action": "priority_queue"}
}
The chat system automatically tracks: