Miquel Farré commited on
Commit ·
701026e
1
Parent(s): 28d5a31
changing behavior after failure
Browse files218 unmodified lines2192202212222232242252262272282292302312322332342352362372382392402412422432442457 unmodified lines253254255256257258259227 unmodified lines4874884894904914921 unmodified line494495496497498499500501502503504505506507508509510511512513514218 unmodified linesconsole.log("Error detected!");showBSOD('Error');clearInterval(resultsInterval);window.agentFailed = true;break;}}}, 1000);};// Add a new function to conditionally go to interactive modewindow.shouldSwitchToInteractive = function() {const resultsElements = document.querySelectorAll('textarea, .output-text');for (let elem of resultsElements) {const content = elem.value || elem.innerText || '';// If we see an error message or our flag is set, don't switch to interactiveif (content.includes('Error running agent') || window.agentFailed === true) {console.log("Error detected, not switching to interactive mode");return false;}}console.log("No errors detected, switching to interactive mode");return true;};// Start monitoring for timeouts immediately7 unmodified linesif (e.target.tagName === 'BUTTON') {if (e.target.innerText === "Let's go!") {resetBSOD();window.agentFailed = false;}setTimeout(monitorForErrors, 3000);}227 unmodified linesdef set_interactive_mode(request: gr.Request):return update_html(True, request)# Chain the events# 1. Set view-only mode when button is clickedview_only_event = update_btn.click(1 unmodified lineinputs=[task_input],outputs=html_output)# 2. Then run the agent tasktask_result = view_only_event.then(fn=run_agent_task,inputs=[task_input],outputs=results_output)# # 3. Then set back to interactive modetask_result.then(fn=set_interactive_mode,inputs=None, # No inputs needed hereoutputs=html_output,_js="() => window.shouldSwitchToInteractive() ? [] : null")# Load the sandbox on app start with initial HTML218 unmodified lines2192202212222232242252262272282297 unmodified lines237238239240241242227 unmodified lines4704714724734744754764774784794804814824834844854861 unmodified line488489490491492493494495496497498499500501502503504505506218 unmodified linesconsole.log("Error detected!");showBSOD('Error');clearInterval(resultsInterval);break;}}}, 1000);};// Start monitoring for timeouts immediately7 unmodified linesif (e.target.tagName === 'BUTTON') {if (e.target.innerText === "Let's go!") {resetBSOD();}setTimeout(monitorForErrors, 3000);}227 unmodified linesdef set_interactive_mode(request: gr.Request):return update_html(True, request)# Function to check result and conditionally set interactive modedef check_and_set_interactive(result, request: gr.Request):if result and not result.startswith("Error running agent"):# Only set interactive mode if no errorreturn update_html(True, request)else:# Return the current HTML to avoid changing the display# This will keep the BSOD visiblereturn gr.update()# Chain the events# 1. Set view-only mode when button is clickedview_only_event = update_btn.click(1 unmodified lineinputs=[task_input],outputs=html_output)# 2. Then run the agent tasktask_result = view_only_event.then(fn=run_agent_task,inputs=[task_input],outputs=results_output)# 3. Then check the result and conditionally set to interactive modetask_result.then(fn=check_and_set_interactive,inputs=[results_output], # Pass the result text to checkoutputs=html_output)# Load the sandbox on app start with initial HTML
app.py+17-25