| import asyncio |
| import sys |
| from pathlib import 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() |
| |
| |
| print("HF Endpoint Status:") |
| print(hf_monitor.get_status_summary()) |
| print() |
| |
| |
| print("Coordinating AI responses...") |
| coordination_result = await coordinator.coordinate_response(user_id, user_query) |
| |
| |
| print("Immediate Response (Ollama):") |
| print(coordination_result['immediate_response']) |
| print() |
| |
| |
| print("External Data Gathered:") |
| for key, value in coordination_result['external_data'].items(): |
| print(f" {key}: {value}") |
| print() |
| |
| |
| session_manager.update_session_with_ai_coordination(user_id, { |
| 'immediate_response': coordination_result['immediate_response'], |
| 'external_data': coordination_result['external_data'] |
| }) |
| |
| |
| 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() |
| |
| |
| 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}") |
| |
| |
| 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()) |
|
|