Update app.py
Browse files
app.py
CHANGED
@@ -240,7 +240,10 @@ def chat():
|
|
240 |
if 'message' not in request.form:
|
241 |
logger.error("Missing 'message' in POST request form data.")
|
242 |
return jsonify({'error': 'Missing message parameter'}), 400
|
243 |
-
user_input = request.form['message']
|
|
|
|
|
|
|
244 |
logger.info(f"Received chat input: {user_input}")
|
245 |
reply = get_krishna_response(user_input)
|
246 |
logger.info(f"Generated reply: {reply}")
|
@@ -250,10 +253,11 @@ def chat():
|
|
250 |
logger.info("Successfully saved chat message to Firebase.")
|
251 |
except Exception as e:
|
252 |
logger.error(f"Failed to save chat message to Firebase: {str(e)}")
|
|
|
253 |
return jsonify({'reply': reply})
|
254 |
try:
|
255 |
chat_history = get_chat_history() if firebase_enabled else []
|
256 |
-
logger.info(f"Retrieved chat history: {chat_history}")
|
257 |
except Exception as e:
|
258 |
logger.error(f"Failed to retrieve chat history from Firebase: {str(e)}")
|
259 |
chat_history = []
|
|
|
240 |
if 'message' not in request.form:
|
241 |
logger.error("Missing 'message' in POST request form data.")
|
242 |
return jsonify({'error': 'Missing message parameter'}), 400
|
243 |
+
user_input = request.form['message'].strip()
|
244 |
+
if not user_input:
|
245 |
+
logger.error("Empty message received.")
|
246 |
+
return jsonify({'error': 'Message cannot be empty'}), 400
|
247 |
logger.info(f"Received chat input: {user_input}")
|
248 |
reply = get_krishna_response(user_input)
|
249 |
logger.info(f"Generated reply: {reply}")
|
|
|
253 |
logger.info("Successfully saved chat message to Firebase.")
|
254 |
except Exception as e:
|
255 |
logger.error(f"Failed to save chat message to Firebase: {str(e)}")
|
256 |
+
# Continue even if Firebase fails
|
257 |
return jsonify({'reply': reply})
|
258 |
try:
|
259 |
chat_history = get_chat_history() if firebase_enabled else []
|
260 |
+
logger.info(f"Retrieved chat history: {len(chat_history)} messages")
|
261 |
except Exception as e:
|
262 |
logger.error(f"Failed to retrieve chat history from Firebase: {str(e)}")
|
263 |
chat_history = []
|