Spaces:
Sleeping
Sleeping
Update app.py
Browse files236 unmodified lines23723823924024124224355 unmodified lines2993003013023033043053 unmodified lines30931031131231331431531631731831932032132232332432532632732860 unmodified lines38939039139239339439539619 unmodified lines416417418419236 unmodified linesif not agent:raise ValueError(f"Unknown agent: {agent_name}")self.log_queue.put(f"[{agent_name.replace('_', ' ').title()}]: Starting task...")if agent_name == "prompt_optimizer":context = await agent.optimize_prompt(context, api_key)elif agent_name == "orchestrator":55 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.")3 unmodified lineslog_queue.put(("result", context.conversation_history))# -------------------- Process Generator and Human Input --------------------def process_conversation_generator(task_message: str, api_key: str, human_in_the_loop_event: threading.Event, human_input_queue: queue.Queue) -> Generator[str, None, None]:"""Wraps the conversation, yields log messages, and handles human input within a single thread."""log_q: queue.Queue = queue.Queue()# Run the multi-agent conversation *synchronously* within this function.asyncio.run(multi_agent_conversation(task_message, log_q, api_key, human_in_the_loop_event, human_input_queue))# Process the log queue and handle human-in-the-loopfinal_result = Nonewhile True: # Loop indefinitely to handle multiple potential human feedback requests.try:msg = log_q.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.60 unmodified lineshuman_in_the_loop_event = threading.Event()human_input_queue = queue.Queue() # Use a single queue for both requests and responsesyield from process_conversation_generator(message, openai_api_key, human_in_the_loop_event, human_input_queue)# -------------------- Launch the Chatbot --------------------19 unmodified linesdemo = gr.TabbedInterface([iface, dummy_iface], ["Chatbot", "Dummy"])demo.launch(share=True)import time #Import the time module236 unmodified lines23723823924024124224355 unmodified lines2993003013023033043053 unmodified lines30931031131231331431531631731831932032132232332432532632732860 unmodified lines38939039139239339439539639739839919 unmodified lines419420421422423236 unmodified linesif not agent:raise ValueError(f"Unknown agent: {agent_name}")self.log_queue.put(f"[{agent_name.replace('_', ' ').title()}]: Starting task...") # Log hereif agent_name == "prompt_optimizer":context = await agent.optimize_prompt(context, api_key)elif agent_name == "orchestrator":55 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.")3 unmodified lineslog_queue.put(("result", context.conversation_history))# -------------------- Process Generator and Human Input --------------------def 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.asyncio.run(multi_agent_conversation(task_message, log_queue, api_key, human_in_the_loop_event, human_input_queue))# Process the log queue and handle human-in-the-loopfinal_result = Nonewhile True: # Loop indefinitely to handle multiple potential human feedback requests.try: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 "Conversation complete." # Indicate completion.60 unmodified lineshuman_in_the_loop_event = threading.Event()human_input_queue = queue.Queue() # Use a single queue for both requests and responseslog_queue = queue.Queue() #Create log queue hereyield from process_conversation_generator(message, openai_api_key, human_in_the_loop_event, human_input_queue, log_queue)# -------------------- Launch the Chatbot --------------------19 unmodified linesdemo = gr.TabbedInterface([iface, dummy_iface], ["Chatbot", "Dummy"])demo.launch(share=True)import time #Import the time module
app.py+12-8