Commit ·
4bc617b
1
Parent(s): fd70375
Fix GeneratorExit exception in cancel generation by adding proper exception handling
Browse files566 unmodified lines56756856957057157286 unmodified lines659660661662663664566 unmodified linesgen_thread.join()yield history, debug + prompt_debugexcept Exception as e:history.append({'role': 'assistant', 'content': f"Error: {e}"})yield history, debug86 unmodified lineschat: response_chunk[0],dbg: response_chunk[1],}except Exception as e:print(f"An error occurred during generation: {e}")# If an error happens, add it to the chat history to inform the user.566 unmodified lines56756856957057157257357457557657786 unmodified lines664665666667668669670671672673674566 unmodified linesgen_thread.join()yield history, debug + prompt_debugexcept GeneratorExit:# Handle cancellation gracefullyprint("Chat response cancelled.")# Don't yield anything - let the cancellation propagatereturnexcept Exception as e:history.append({'role': 'assistant', 'content': f"Error: {e}"})yield history, debug86 unmodified lineschat: response_chunk[0],dbg: response_chunk[1],}except GeneratorExit:# Handle Gradio's cancellation signal gracefullyprint("Generation cancelled by user.")# Don't yield anything here - let the finally block handle UI resetreturnexcept Exception as e:print(f"An error occurred during generation: {e}")# If an error happens, add it to the chat history to inform the user.
app.py+10