Spaces:
Sleeping
Sleeping
Update app.py
Browse files48 unmodified lines4950515253545556575859606162636465666768699 unmodified lines798081826783848586221 unmodified lines30830931031129531231331431521 unmodified lines3373383393233403413423434 unmodified lines34834935033435135235335448 unmodified lines raise raise Exception(f"Failed to get response after {max_retries} attempts.")
# -------------------- Conversation History Conversion --------------------def convert_history(history: List[Dict[str, str]]) -> List[Dict[str, str]]: """ Convert our internal conversation history format (with 'agent' and 'message' keys) into the Gradio messages format (with 'role' and 'content'). """ converted = [] for entry in history: if entry["agent"].lower() == "user": converted.append({"role": "user", "content": entry["message"]}) else: # You can customize the formatting below as desired. converted.append({"role": "assistant", "content": f'{entry["agent"]}: {entry["message"]}'}) return converted
# -------------------- Shared Context --------------------class Context: def __init__(self, original_task: str, optimized_task: Optional[str] = None,9 unmodified lines self.test_cases = test_cases self.test_results = test_results self.documentation = documentation # Initialize conversation history with the user's original task. self.conversation_history = conversation_history or [] self.conversation_history = conversation_history or [{"agent": "User", "message": original_task}]
def add_conversation_entry(self, agent_name: str, message: str): self.conversation_history.append({"agent": agent_name, "message": message})221 unmodified lines try: msg = log_queue.get(timeout=0.1) if isinstance(msg, tuple) and msg[0] == "result": # Convert conversation history to the required messages format. yield gr.Chatbot.update(value=msg[1], visible=True) yield gr.Chatbot.update(value=convert_history(msg[1])) else: yield msg except queue.Empty:21 unmodified lines gr.Markdown("## Multi-Agent Task Solver with Human-in-the-Loop") with gr.Row(): # Set type="messages" to avoid deprecation warnings. # Set type="messages" to match the expected format. chat_output = gr.Chatbot(label="Conversation", type="messages") with gr.Row():4 unmodified lines send_button = gr.Button("Send") # Remove stream=True (not supported in your Gradio version). # Note: 'stream=True' has been removed. send_button.click(fn=multi_agent_chat, inputs=[message_input, api_key_input], outputs=chat_output)
if __name__ == "__main__":app.py+21-4