Spaces:
Sleeping
Sleeping
File size: 5,346 Bytes
5065491 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
#!/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() |