Rulga commited on
Commit
5d0697a
·
1 Parent(s): 2e6aca3

Generate conversation ID if none exists in respond_and_clear function, ensuring non-null ID for chat history saving

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -560,6 +560,11 @@ def save_chat_history(history, conversation_id):
560
  def respond_and_clear(message, history, conversation_id, system_prompt):
561
  """Wrapper function with proper output handling"""
562
  try:
 
 
 
 
 
563
  # Get current model parameters
564
  params = ACTIVE_MODEL['parameters']
565
 
@@ -580,9 +585,9 @@ def respond_and_clear(message, history, conversation_id, system_prompt):
580
  new_history, new_conv_id = result
581
 
582
  # Save chat history
583
- save_chat_history(new_history, new_conv_id)
584
 
585
- return new_history, new_conv_id, "" # Clear input
586
 
587
  except Exception as e:
588
  logger.error(f"Error in respond_and_clear: {str(e)}")
 
560
  def respond_and_clear(message, history, conversation_id, system_prompt):
561
  """Wrapper function with proper output handling"""
562
  try:
563
+ # Generate a conversation ID if none exists
564
+ if not conversation_id:
565
+ conversation_id = f"conv_{datetime.datetime.now().strftime('%Y%m%d%H%M%S')}_{os.urandom(4).hex()}"
566
+ logger.info(f"Generated new conversation ID: {conversation_id}")
567
+
568
  # Get current model parameters
569
  params = ACTIVE_MODEL['parameters']
570
 
 
585
  new_history, new_conv_id = result
586
 
587
  # Save chat history
588
+ save_chat_history(new_history, conversation_id) # Use our guaranteed non-null ID
589
 
590
+ return new_history, conversation_id, "" # Return our guaranteed non-null ID
591
 
592
  except Exception as e:
593
  logger.error(f"Error in respond_and_clear: {str(e)}")