Spaces:
Sleeping
Sleeping
Update app.py
Browse files298 unmodified lines2993003013023023033043056 unmodified lines3123133143153153163173186 unmodified lines3253263273283293303318 unmodified lines3403413423423433443453466 unmodified lines35335435535535635735835935635735835938 unmodified lines39839940040140240340412 unmodified lines417418419422423420298 unmodified lines
next_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) next_agent = await dispatcher.determine_next_agent(context, api_key) # Check for maximum revisions if 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. Crucially, takes the log_queue as an argument. Yields Gradio updates. """
# Run the multi-agent conversation *synchronously* within this function.6 unmodified lines msg = 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 result yield "Conversation complete." # Indicate completion. break # Exit the loop after processing the final result. else:8 unmodified lines feedback_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) yield gr.Textbox.update(visible=False), gr.update(visible=True) # Show feedback UI 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 lines time.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_text
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 messages 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 lines demo = gr.TabbedInterface([iface, dummy_iface], ["Chatbot", "Dummy"]) demo.launch(share=True)
import time #Import the time module import time #Import the time moduleapp.py+7-10