Spaces:
Sleeping
Sleeping
Update app.py
Browse files48 unmodified lines4950515253549 unmodified lines64656667686970221 unmodified lines29229329429529629729821 unmodified lines3203213223233243253264 unmodified lines33133233333433533633748 unmodified linesraiseraise Exception(f"Failed to get response after {max_retries} attempts.")# -------------------- Shared Context --------------------class Context:def __init__(self, original_task: str, optimized_task: Optional[str] = None,9 unmodified linesself.test_cases = test_casesself.test_results = test_resultsself.documentation = documentationself.conversation_history = conversation_history or []def add_conversation_entry(self, agent_name: str, message: str):self.conversation_history.append({"agent": agent_name, "message": message})221 unmodified linestry:msg = log_queue.get(timeout=0.1)if isinstance(msg, tuple) and msg[0] == "result":yield gr.Chatbot.update(value=msg[1], visible=True)else:yield msgexcept queue.Empty:21 unmodified linesgr.Markdown("## Multi-Agent Task Solver with Human-in-the-Loop")with gr.Row():# Set type="messages" to avoid deprecation warnings.chat_output = gr.Chatbot(label="Conversation", type="messages")with gr.Row():4 unmodified linessend_button = gr.Button("Send")# Remove stream=True (not supported in your Gradio version).send_button.click(fn=multi_agent_chat, inputs=[message_input, api_key_input], outputs=chat_output)if __name__ == "__main__":48 unmodified lines4950515253545556575859606162636465666768699 unmodified lines7980818283848586221 unmodified lines30830931031131231331431521 unmodified lines3373383393403413423434 unmodified lines34834935035135235335448 unmodified linesraiseraise 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 linesself.test_cases = test_casesself.test_results = test_resultsself.documentation = documentation# Initialize conversation history with the user's original task.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 linestry: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=convert_history(msg[1]))else:yield msgexcept queue.Empty:21 unmodified linesgr.Markdown("## Multi-Agent Task Solver with Human-in-the-Loop")with gr.Row():# Set type="messages" to match the expected format.chat_output = gr.Chatbot(label="Conversation", type="messages")with gr.Row():4 unmodified linessend_button = gr.Button("Send")# 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