Spaces:
Sleeping
Sleeping
Update app.py
Browse files298 unmodified lines2993003013023033043056 unmodified lines3123133143153163173186 unmodified lines3253263273283293308 unmodified lines3393403413423433443456 unmodified lines35235335435535635735835936036136238 unmodified lines40140240340440540612 unmodified lines419420421422423298 unmodified linesnext_agent = await dispatcher.determine_next_agent(context, api_key)if next_agent == "code_reviewer" and context.review_comments and "APPROVE" in [comment.get('issue',"").upper() for comment_list in context.review_comments for comment in comment_list.get("comments",[]) ]:next_agent = await dispatcher.determine_next_agent(context, api_key)# Check for maximum revisionsif next_agent == "coder" and len([entry for entry in context.conversation_history if entry["agent"] == "Coder"]) > 5:log_queue.put("Maximum revision iterations reached. Exiting.")6 unmodified linesdef process_conversation_generator(task_message: str, api_key: str, human_in_the_loop_event: threading.Event, human_input_queue: queue.Queue, log_queue: queue.Queue) -> Generator[str, None, None]:"""Wraps the conversation, yields log messages, and handles human input within a single thread.Crucially, takes the log_queue as an argument."""# Run the multi-agent conversation *synchronously* within this function.6 unmodified linesmsg = log_queue.get_nowait() # Non-blocking get from the log queue.if isinstance(msg, tuple) and msg[0] == "result":final_result = msg[1]yield "Conversation complete." # Indicate completion.break # Exit the loop after processing the final result.else:8 unmodified linesfeedback_request = human_input_queue.get(timeout=0.1) # Get the context/question for feedback.human_interface = get_human_feedback(feedback_request)yield gr.Textbox.update(visible=False), gr.update(visible=True)human_feedback = human_input_queue.get(timeout=300) # Wait (block) for human feedback, with a timeout.human_in_the_loop_event.clear() # Reset the event after getting feedback.6 unmodified linestime.sleep(0.1)if final_result:conv_text = "\n=== Conversation ===\n"for entry in final_result:conv_text += f"[{entry['agent']}]: {entry['message']}\n\n"yield conv_textdef get_human_feedback(placeholder_text):"""Gets human input using a Gradio Textbox."""38 unmodified lines# Create the main chat interfaceiface = gr.ChatInterface(fn=multi_agent_chat,additional_inputs=[gr.Textbox(label="OpenAI API Key (optional)", type="password", placeholder="Leave blank to use env variable")],title="Multi-Agent Task Solver with Human-in-the-Loop",description="""12 unmodified linesdemo = gr.TabbedInterface([iface, dummy_iface], ["Chatbot", "Dummy"])demo.launch(share=True)import time #Import the time module298 unmodified lines2993003013023033043056 unmodified lines3123133143153163173186 unmodified lines3253263273283293303318 unmodified lines3403413423433443453466 unmodified lines35335435535635735835938 unmodified lines39839940040140240340412 unmodified lines417418419420298 unmodified linesnext_agent = await dispatcher.determine_next_agent(context, api_key)if next_agent == "code_reviewer" and context.review_comments and "APPROVE" in [comment.get('issue',"").upper() for comment_list in context.review_comments for comment in comment_list.get("comments",[]) ]:next_agent = await dispatcher.determine_next_agent(context, api_key)# Check for maximum revisionsif next_agent == "coder" and len([entry for entry in context.conversation_history if entry["agent"] == "Coder"]) > 5:log_queue.put("Maximum revision iterations reached. Exiting.")6 unmodified linesdef process_conversation_generator(task_message: str, api_key: str, human_in_the_loop_event: threading.Event, human_input_queue: queue.Queue, log_queue: queue.Queue) -> Generator[str, None, None]:"""Wraps the conversation, yields log messages, and handles human input within a single thread.Crucially, takes the log_queue as an argument. Yields Gradio updates."""# Run the multi-agent conversation *synchronously* within this function.6 unmodified linesmsg = log_queue.get_nowait() # Non-blocking get from the log queue.if isinstance(msg, tuple) and msg[0] == "result":final_result = msg[1]yield gr.Chatbot.update(final_result) # Update the chatbot with the final resultyield "Conversation complete." # Indicate completion.break # Exit the loop after processing the final result.else:8 unmodified linesfeedback_request = human_input_queue.get(timeout=0.1) # Get the context/question for feedback.human_interface = get_human_feedback(feedback_request)yield gr.Textbox.update(visible=False), gr.update(visible=True) # Show feedback UIhuman_feedback = human_input_queue.get(timeout=300) # Wait (block) for human feedback, with a timeout.human_in_the_loop_event.clear() # Reset the event after getting feedback.6 unmodified linestime.sleep(0.1)def get_human_feedback(placeholder_text):"""Gets human input using a Gradio Textbox."""38 unmodified lines# Create the main chat interfaceiface = gr.ChatInterface(fn=multi_agent_chat,chatbot=gr.Chatbot(type="feed"), # Use the 'feed' type for a better display of messagesadditional_inputs=[gr.Textbox(label="OpenAI API Key (optional)", type="password", placeholder="Leave blank to use env variable")],title="Multi-Agent Task Solver with Human-in-the-Loop",description="""12 unmodified linesdemo = gr.TabbedInterface([iface, dummy_iface], ["Chatbot", "Dummy"])demo.launch(share=True)import time #Import the time module
app.py+7-10