Spaces:
Sleeping
Sleeping
Update app.py
Browse files77 unmodified lines7879808182838434 unmodified lines11912012112212312412533 unmodified lines15916016116216316474 unmodified lines2392402412422432442454 unmodified lines25025125225325425525621 unmodified lines2782792802812822832842852862872882892902916 unmodified lines2982993003013023033047 unmodified lines31231331431531631731831932032132232332432532632777 unmodified linesself.test_cases = test_casesself.test_results = test_resultsself.documentation = documentation# Initialize with the user's taskself.conversation_history = conversation_history or [{"agent": "User", "message": original_task}]def add_conversation_entry(self, agent_name: str, message: str):34 unmodified lines)plan = await call_model(prompt, model="gpt-4o", api_key=api_key)context.add_conversation_entry("Orchestrator", f"Plan:\n{plan}")# Report update after planningself.log_queue.put(("update", context.conversation_history))if "REQUEST_HUMAN_FEEDBACK" in plan:question = plan.split("REQUEST_HUMAN_FEEDBACK\n", 1)[1].strip()33 unmodified lines)review = await call_model(prompt, model="gpt-4o", api_key=api_key)context.add_conversation_entry("Code Reviewer", f"Review:\n{review}")if "APPROVE" not in review.upper():structured_review = {"comments": []}for line in review.splitlines():74 unmodified linescontext = await self.agents[agent_name].generate_documentation(context, api_key)else:raise ValueError(f"Unknown agent: {agent_name}")# After each dispatch, push an update with the current conversation history.self.log_queue.put(("update", context.conversation_history))return context4 unmodified linesreturn "orchestrator"if not context.code:return "coder"if not any("APPROVE" in comment.get("issue", "").upper() for review in context.review_comments for comment in review.get("comments", [])):return "code_reviewer"if not context.test_cases:return "qa_tester"21 unmodified linescontext = await dispatcher.dispatch(next_agent, context, api_key, model="gpt-3.5-turbo-16k")else:context = await dispatcher.dispatch(next_agent, context, api_key)if next_agent == "code_reviewer":approved = any("APPROVE" in comment.get("issue", "").upper()for review in context.review_commentsfor comment in review.get("comments", []))if not approved:next_agent = "coder"else:next_agent = await dispatcher.determine_next_agent(context, api_key)else:next_agent = await dispatcher.determine_next_agent(context, api_key)if next_agent == "coder" and coder_iterations > 5:6 unmodified lineshuman_event: threading.Event, human_input_queue: queue.Queue,log_queue: queue.Queue) -> Generator[Any, None, None]:"""Runs the multi-agent conversation in a background thread and yields only conversation history updatesin the proper messages format."""def run_conversation():7 unmodified linesmsg = log_queue.get(timeout=0.1)if isinstance(msg, tuple):if msg[0] in ("update", "result"):# Yield the updated conversation history in proper format.yield gr.update(value=convert_history(msg[1]), visible=True)else:# Log messages can be printed or handled here if needed.passexcept queue.Empty:passtime.sleep(0.1)# Final update if neededyield gr.update(visible=True)# -------------------- Multi-Agent Chat Function --------------------77 unmodified lines7879808182838434 unmodified lines11912012112212312433 unmodified lines15815916016116216316474 unmodified lines2392402412422432442454 unmodified lines25025125225325425525625725821 unmodified lines2802812822832842852862872882892902912922932946 unmodified lines3013023033043053063077 unmodified lines31531631731831932032132232332432532632732877 unmodified linesself.test_cases = test_casesself.test_results = test_resultsself.documentation = documentation# Initialize with the user's task.self.conversation_history = conversation_history or [{"agent": "User", "message": original_task}]def add_conversation_entry(self, agent_name: str, message: str):34 unmodified lines)plan = await call_model(prompt, model="gpt-4o", api_key=api_key)context.add_conversation_entry("Orchestrator", f"Plan:\n{plan}")self.log_queue.put(("update", context.conversation_history))if "REQUEST_HUMAN_FEEDBACK" in plan:question = plan.split("REQUEST_HUMAN_FEEDBACK\n", 1)[1].strip()33 unmodified lines)review = await call_model(prompt, model="gpt-4o", api_key=api_key)context.add_conversation_entry("Code Reviewer", f"Review:\n{review}")# If review is not "APPROVE", store the review comments.if "APPROVE" not in review.upper():structured_review = {"comments": []}for line in review.splitlines():74 unmodified linescontext = await self.agents[agent_name].generate_documentation(context, api_key)else:raise ValueError(f"Unknown agent: {agent_name}")# Push an update with the current conversation history.self.log_queue.put(("update", context.conversation_history))return context4 unmodified linesreturn "orchestrator"if not context.code:return "coder"# Instead of checking review_comments (which may be empty if reviewer approved),# check the conversation history for a Code Reviewer entry containing "APPROVE".if not any("APPROVE" in entry["message"].upper() for entry in context.conversation_history if entry["agent"].lower() == "code reviewer"):return "code_reviewer"if not context.test_cases:return "qa_tester"21 unmodified linescontext = await dispatcher.dispatch(next_agent, context, api_key, model="gpt-3.5-turbo-16k")else:context = await dispatcher.dispatch(next_agent, context, api_key)# Check approval by scanning the conversation history for a Code Reviewer entry that includes "APPROVE"if next_agent == "code_reviewer":approved = any("APPROVE" in entry["message"].upper()for entry in context.conversation_historyif entry["agent"].lower() == "code reviewer")if approved:next_agent = await dispatcher.determine_next_agent(context, api_key)else:next_agent = "coder"else:next_agent = await dispatcher.determine_next_agent(context, api_key)if next_agent == "coder" and coder_iterations > 5:6 unmodified lineshuman_event: threading.Event, human_input_queue: queue.Queue,log_queue: queue.Queue) -> Generator[Any, None, None]:"""Runs the multi-agent conversation in a background thread and yields conversation history updatesin the proper messages format."""def run_conversation():7 unmodified linesmsg = log_queue.get(timeout=0.1)if isinstance(msg, tuple):if msg[0] in ("update", "result"):yield gr.update(value=convert_history(msg[1]), visible=True)else:# Optionally handle log messages here.passexcept queue.Empty:passtime.sleep(0.1)yield gr.update(visible=True)# -------------------- Multi-Agent Chat Function --------------------
app.py+15-14