Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
|
|
|
| 302 |
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 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 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
yield
|
|
|
|
| 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
|
|
|
|
| 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
|