Shreyas094 commited on
Commit
5e31c67
·
verified ·
1 Parent(s): f6d00d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -23
app.py CHANGED
@@ -298,35 +298,30 @@ def chatbot_interface(message, history, model, temperature, num_calls, use_web_s
298
  else:
299
  return history # Return if both text and audio are empty
300
 
301
- history.append((input_text, ""))
 
302
 
303
- for response in respond(input_text, history, model, temperature, num_calls, use_web_search, selected_docs):
304
- # Ensure the response is a string
305
- if isinstance(response, (list, tuple)):
306
- response = ' '.join(str(item) for item in response if item is not None)
307
- elif not isinstance(response, str):
308
- response = str(response)
309
-
310
- # Truncate response if it's too long
311
- max_length = 32000 # Adjust this value as needed
312
- if len(response) > max_length:
313
- response = response[:max_length] + "... (truncated)"
314
-
315
  # Update the last message in history
316
- if history:
317
- history[-1] = (input_text, response)
318
- else:
319
- history.append((input_text, response))
320
-
321
- # Yield a copy of the history to avoid reference issues
322
- yield list(history)
 
323
  except Exception as e:
324
  logging.error(f"Error in chatbot_interface: {str(e)}")
325
  error_message = f"An error occurred: {str(e)}"
326
- if not isinstance(history, list):
327
- history = []
328
  history.append((input_text if 'input_text' in locals() else "Error", error_message))
329
- yield list(history)
 
330
  def retry_last_response(history, model, temperature, num_calls):
331
  if not history:
332
  return history
 
298
  else:
299
  return history # Return if both text and audio are empty
300
 
301
+ # Add user message to history
302
+ history.append((input_text, None))
303
 
304
+ # Get response from the model
305
+ response_generator = respond(input_text, history, model, temperature, num_calls, use_web_search, selected_docs)
306
+
307
+ full_response = ""
308
+ for partial_response in response_generator:
309
+ full_response += str(partial_response)
 
 
 
 
 
 
310
  # Update the last message in history
311
+ history[-1] = (input_text, full_response)
312
+ yield history
313
+
314
+ # If no response was generated, yield an error message
315
+ if not full_response:
316
+ history[-1] = (input_text, "I'm sorry, I couldn't generate a response. Please try again.")
317
+ yield history
318
+
319
  except Exception as e:
320
  logging.error(f"Error in chatbot_interface: {str(e)}")
321
  error_message = f"An error occurred: {str(e)}"
 
 
322
  history.append((input_text if 'input_text' in locals() else "Error", error_message))
323
+ yield history
324
+
325
  def retry_last_response(history, model, temperature, num_calls):
326
  if not history:
327
  return history