Spaces:
Sleeping
Sleeping
| #!/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() |