PensionBot / test_conversational.py
ChAbhishek28's picture
Add 899999999999999999999999999999
5065491
raw
history blame
5.35 kB
#!/usr/bin/env python3
"""
Test Conversational Voice Bot Features
Demonstrates how the bot now asks for clarification like your friend's bot
"""
import asyncio
import logging
# Setup logging
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
logger = logging.getLogger(__name__)
async def test_conversational_features():
"""Test the conversational clarity detection"""
print("🎯 Testing Conversational Voice Bot Features")
print("=" * 60)
print("This demonstrates how your bot now asks for clarification")
print("just like your friend's superior voice bot!")
print()
try:
from conversational_service import conversational_service
# Test queries that should trigger clarification
test_cases = [
{
"query": "pension",
"description": "Vague pension query",
"expected": "Should ask for specific pension topic"
},
{
"query": "what",
"description": "Too generic query",
"expected": "Should ask what topic user wants help with"
},
{
"query": "help",
"description": "General help request",
"expected": "Should provide topic options"
},
{
"query": "tender",
"description": "Vague procurement query",
"expected": "Should ask about specific procurement aspect"
},
{
"query": "What are the pension rules?",
"description": "Clear specific query",
"expected": "Should proceed with search (no clarification needed)"
}
]
for i, test_case in enumerate(test_cases, 1):
print(f"πŸ” Test {i}: {test_case['description']}")
print(f"Query: \"{test_case['query']}\"")
print(f"Expected: {test_case['expected']}")
print("-" * 50)
# Analyze query clarity
clarity_analysis = conversational_service.analyze_query_clarity(
test_case['query'],
[] # Empty search results for testing
)
if clarity_analysis['clarification_needed']:
print("βœ… RESULT: Bot will ask for clarification")
print("πŸ€– Bot response:")
print()
for question in clarity_analysis['clarification_questions']:
print(f" {question}")
print()
if 'suggested_responses' in clarity_analysis:
for suggestion in clarity_analysis['suggested_responses']:
print(f" {suggestion}")
else:
print("βœ… RESULT: Query is clear, will proceed with search")
print(f"🎯 Confidence: {clarity_analysis['confidence']:.2f}")
print()
print("=" * 60)
print()
except ImportError as e:
print(f"❌ Import error: {e}")
print("πŸ’‘ Make sure you're running from the PensionBot directory")
except Exception as e:
print(f"❌ Test error: {e}")
def demonstrate_conversation_flow():
"""Demonstrate a full conversation flow"""
print("πŸ’¬ Conversation Flow Demonstration")
print("=" * 40)
print("Here's how a conversation now works:")
print()
conversation = [
{"speaker": "πŸ‘€ User", "message": "pension"},
{"speaker": "πŸ€– Bot", "message": """I can help with pension-related questions! To give you the most accurate information, could you specify:
πŸ“‹ What specifically about pension?
β€’ How to calculate pension amount?
β€’ Pension eligibility criteria?
β€’ How to apply for pension?
β€’ Family pension benefits?
β€’ Commutation of pension?
Please let me know which aspect interests you most!"""},
{"speaker": "πŸ‘€ User", "message": "calculation"},
{"speaker": "πŸ€– Bot", "message": """Here's the pension calculation formula:
**Formula**: (Last drawn basic pay + DA) Γ— service years Γ· 70
**Minimum pension**: β‚Ή9,000 per month
**Maximum pension**: No upper limit
**Example calculation**:
- Last basic pay: β‚Ή50,000
- DA: β‚Ή25,000 (50% of basic)
- Service years: 30
- Pension = (50,000 + 25,000) Γ— 30 Γ· 70 = β‚Ή32,143 per month
Would you like me to help with a specific pension calculation for your situation?"""}
]
for exchange in conversation:
print(f"{exchange['speaker']}: {exchange['message']}")
print()
print("🎯 Key Improvements:")
print("βœ… Bot asks for clarification instead of guessing")
print("βœ… Provides structured options for user to choose")
print("βœ… Follows up with specific, detailed information")
print("βœ… Encourages further conversation")
print()
print("This is exactly how your friend's bot works! πŸŽ‰")
if __name__ == "__main__":
print("🎯 Conversational Voice Bot Test")
print("Testing enhanced conversational features")
print()
# Run the tests
asyncio.run(test_conversational_features())
print("\n" + "="*60)
demonstrate_conversation_flow()