File size: 2,934 Bytes
e900a8d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import asyncio
import sys
from pathlib import Path

# Add project root to path
project_root = Path(__file__).parent
sys.path.append(str(project_root))

from core.coordinator import coordinator
from core.session import session_manager
from services.hf_endpoint_monitor import hf_monitor

async def demo_coordinated_response():
    """Demonstrate the coordinated AI response system"""
    print("=== AI Life Coach Coordinated Response Demo ===")
    print()
    
    user_id = "demo_user"
    user_query = "What's the weather like in New York today and how should I plan my day?"
    
    print(f"User Query: {user_query}")
    print()
    
    # Show HF endpoint status
    print("HF Endpoint Status:")
    print(hf_monitor.get_status_summary())
    print()
    
    # Coordinate responses
    print("Coordinating AI responses...")
    coordination_result = await coordinator.coordinate_response(user_id, user_query)
    
    # Show immediate response
    print("Immediate Response (Ollama):")
    print(coordination_result['immediate_response'])
    print()
    
    # Show external data gathered
    print("External Data Gathered:")
    for key, value in coordination_result['external_data'].items():
        print(f"  {key}: {value}")
    print()
    
    # Update session with coordination data
    session_manager.update_session_with_ai_coordination(user_id, {
        'immediate_response': coordination_result['immediate_response'],
        'external_data': coordination_result['external_data']
    })
    
    # If HF task is available, wait for it
    hf_task = coordination_result.get('hf_task')
    if hf_task:
        print("Waiting for deep analysis from HF endpoint...")
        try:
            hf_response = await hf_task
            if hf_response:
                print("Deep Analysis Response (HF Endpoint):")
                print(hf_response)
                print()
                
                # Update session with HF response
                session_manager.update_session_with_ai_coordination(user_id, {
                    'hf_response': hf_response
                })
            else:
                print("HF Endpoint did not provide a response (may still be initializing)")
        except Exception as e:
            print(f"Error getting HF response: {e}")
    
    # Show session coordination data
    session = session_manager.get_session(user_id)
    if 'ai_coordination' in session:
        coord_data = session['ai_coordination']
        print("AI Coordination Statistics:")
        print(f"  Requests Processed: {coord_data['requests_processed']}")
        print(f"  Ollama Responses: {coord_data['ollama_responses']}")
        print(f"  HF Responses: {coord_data['hf_responses']}")
        print(f"  Last Coordination: {coord_data['last_coordination']}")
    
    print()
    print("🎉 Demo completed successfully!")

if __name__ == "__main__":
    asyncio.run(demo_coordinated_response())