Fix Chatbot for Gradio 6.0: use dict messages (role/content), not type=tuples. Also **kwargs typing + CSS move.
Browse files
app.py
CHANGED
|
@@ -599,15 +599,16 @@ class ChatInterface:
|
|
| 599 |
self.config = config
|
| 600 |
self.agent = agent
|
| 601 |
self.defense = defense
|
| 602 |
-
self.chat_history: List[
|
| 603 |
self.context = ""
|
| 604 |
|
| 605 |
-
def chat(self, message: str, history: List[
|
| 606 |
sanitized, was_modified, report = self.defense.sanitize(message)
|
| 607 |
note = f"\n\n⚠️ **Defense Active**: {', '.join(report.get('detected_patterns', []))}" if was_modified else ""
|
| 608 |
if sanitized.strip().lower() in ("/status", "/tools", "/help"):
|
| 609 |
resp = self._handle_command(sanitized.strip().lower())
|
| 610 |
-
history.append(
|
|
|
|
| 611 |
return history, self.context
|
| 612 |
resp = self.agent.run_autonomous_task(sanitized, self.context)
|
| 613 |
try:
|
|
@@ -616,7 +617,8 @@ class ChatInterface:
|
|
| 616 |
resp = self._format_response(parsed) + note
|
| 617 |
except (json.JSONDecodeError, TypeError):
|
| 618 |
resp += note
|
| 619 |
-
history.append(
|
|
|
|
| 620 |
self.chat_history = history
|
| 621 |
return history, self.context
|
| 622 |
|
|
@@ -671,7 +673,7 @@ def create_ui(config: AgentZeroConfig, chat_interface: ChatInterface, defense: P
|
|
| 671 |
</div>""")
|
| 672 |
with gr.Row():
|
| 673 |
with gr.Column(scale=3):
|
| 674 |
-
chatbot = gr.Chatbot(
|
| 675 |
with gr.Row():
|
| 676 |
msg_input = gr.Textbox(label="Pentesting task", placeholder="e.g., 'Scan ports on scanme.nmap.org' or '/help'", scale=8, container=False)
|
| 677 |
send_btn = gr.Button("▶ Execute", variant="primary", scale=1)
|
|
|
|
| 599 |
self.config = config
|
| 600 |
self.agent = agent
|
| 601 |
self.defense = defense
|
| 602 |
+
self.chat_history: List[Dict[str, str]] = []
|
| 603 |
self.context = ""
|
| 604 |
|
| 605 |
+
def chat(self, message: str, history: List[Dict[str, str]]) -> Tuple[List[Dict[str, str]], str]:
|
| 606 |
sanitized, was_modified, report = self.defense.sanitize(message)
|
| 607 |
note = f"\n\n⚠️ **Defense Active**: {', '.join(report.get('detected_patterns', []))}" if was_modified else ""
|
| 608 |
if sanitized.strip().lower() in ("/status", "/tools", "/help"):
|
| 609 |
resp = self._handle_command(sanitized.strip().lower())
|
| 610 |
+
history.append({"role": "user", "content": message})
|
| 611 |
+
history.append({"role": "assistant", "content": resp})
|
| 612 |
return history, self.context
|
| 613 |
resp = self.agent.run_autonomous_task(sanitized, self.context)
|
| 614 |
try:
|
|
|
|
| 617 |
resp = self._format_response(parsed) + note
|
| 618 |
except (json.JSONDecodeError, TypeError):
|
| 619 |
resp += note
|
| 620 |
+
history.append({"role": "user", "content": message})
|
| 621 |
+
history.append({"role": "assistant", "content": resp})
|
| 622 |
self.chat_history = history
|
| 623 |
return history, self.context
|
| 624 |
|
|
|
|
| 673 |
</div>""")
|
| 674 |
with gr.Row():
|
| 675 |
with gr.Column(scale=3):
|
| 676 |
+
chatbot = gr.Chatbot(label="Agent Zero Console", height=500, render_markdown=True, avatar_images=(None, "🛡️"))
|
| 677 |
with gr.Row():
|
| 678 |
msg_input = gr.Textbox(label="Pentesting task", placeholder="e.g., 'Scan ports on scanme.nmap.org' or '/help'", scale=8, container=False)
|
| 679 |
send_btn = gr.Button("▶ Execute", variant="primary", scale=1)
|