Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -36,8 +36,8 @@ from security.error_handler import (
|
|
| 36 |
ValidationError, RateLimitError, AuthenticationError
|
| 37 |
)
|
| 38 |
|
| 39 |
-
# Import the
|
| 40 |
-
from
|
| 41 |
|
| 42 |
# Set up logging
|
| 43 |
logging.basicConfig(
|
|
@@ -71,15 +71,29 @@ class ProductionChatApp:
|
|
| 71 |
)
|
| 72 |
self.error_handler = ErrorHandler()
|
| 73 |
|
| 74 |
-
# Initialize
|
| 75 |
-
self.
|
| 76 |
|
| 77 |
# Application state
|
| 78 |
self.active_sessions = {}
|
| 79 |
self.request_count = 0
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
logger.info(f"Production chat app initialized in {self.config.deployment.environment.value} mode")
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
@handle_errors
|
| 84 |
async def start_conversation(self, user_id: str, message: str, session_id: Optional[str] = None) -> Tuple[str, str, str]:
|
| 85 |
"""Start or continue a conversation with security checks"""
|
|
@@ -108,13 +122,9 @@ class ProductionChatApp:
|
|
| 108 |
session_data["data"]["message_count"] = session_data["data"].get("message_count", 0) + 1
|
| 109 |
session_data["last_activity"] = datetime.now()
|
| 110 |
|
| 111 |
-
# Process conversation
|
| 112 |
try:
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
# Use robust error handling utility to safely unpack result
|
| 116 |
-
from wanderlust_ai.utils.error_handling import handle_message_processing_result
|
| 117 |
-
response, chat_session_id = handle_message_processing_result(result)
|
| 118 |
|
| 119 |
# Update request count
|
| 120 |
self.request_count += 1
|
|
|
|
| 36 |
ValidationError, RateLimitError, AuthenticationError
|
| 37 |
)
|
| 38 |
|
| 39 |
+
# Import the real API chat system for Hugging Face deployment
|
| 40 |
+
from conversational_travel_chat_real_apis import RealAPIConversationalTravelChat
|
| 41 |
|
| 42 |
# Set up logging
|
| 43 |
logging.basicConfig(
|
|
|
|
| 71 |
)
|
| 72 |
self.error_handler = ErrorHandler()
|
| 73 |
|
| 74 |
+
# Initialize real API chat system for Hugging Face
|
| 75 |
+
self.real_api_chat = RealAPIConversationalTravelChat()
|
| 76 |
|
| 77 |
# Application state
|
| 78 |
self.active_sessions = {}
|
| 79 |
self.request_count = 0
|
| 80 |
|
| 81 |
+
# Check for required API keys for Hugging Face deployment
|
| 82 |
+
self._check_api_keys()
|
| 83 |
+
|
| 84 |
logger.info(f"Production chat app initialized in {self.config.deployment.environment.value} mode")
|
| 85 |
|
| 86 |
+
def _check_api_keys(self):
|
| 87 |
+
"""Check for required API keys for Hugging Face deployment"""
|
| 88 |
+
required_vars = ['SERPAPI_API_KEY', 'TAVILY_API_KEY']
|
| 89 |
+
missing_vars = [var for var in required_vars if not os.getenv(var)]
|
| 90 |
+
|
| 91 |
+
if missing_vars:
|
| 92 |
+
logger.warning(f"Missing environment variables: {missing_vars}")
|
| 93 |
+
logger.warning("The app will run with limited functionality.")
|
| 94 |
+
else:
|
| 95 |
+
logger.info("All required API keys are configured")
|
| 96 |
+
|
| 97 |
@handle_errors
|
| 98 |
async def start_conversation(self, user_id: str, message: str, session_id: Optional[str] = None) -> Tuple[str, str, str]:
|
| 99 |
"""Start or continue a conversation with security checks"""
|
|
|
|
| 122 |
session_data["data"]["message_count"] = session_data["data"].get("message_count", 0) + 1
|
| 123 |
session_data["last_activity"] = datetime.now()
|
| 124 |
|
| 125 |
+
# Process conversation with real API chat
|
| 126 |
try:
|
| 127 |
+
response = await self.real_api_chat.process_message(user_id, message)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
|
| 129 |
# Update request count
|
| 130 |
self.request_count += 1
|