AI-Life-Coach-Streamlit / demo_coordinated_ai.py
rdune71's picture
Implement coordinated multi-model AI system with HF endpoint monitoring
e900a8d
raw
history blame
2.93 kB
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())