Update app.py
Browse files
app.py
CHANGED
@@ -4,75 +4,47 @@ import gradio as gr
|
|
4 |
from agents.programmer import ProgrammerAgent
|
5 |
from agents.debugger import DebuggerAgent
|
6 |
from agents.base_agent import ACPMessage
|
7 |
-
|
8 |
|
9 |
-
#
|
10 |
codebot = ProgrammerAgent()
|
11 |
bugbot = DebuggerAgent()
|
12 |
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
performative="request",
|
24 |
-
content="Can you write a Python function to reverse a list?"
|
25 |
-
)
|
26 |
-
conversation.append(str(msg))
|
27 |
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
|
|
|
|
|
|
33 |
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
reply2 = codebot.receive_message(reply)
|
46 |
-
conversation.append(str(reply2))
|
47 |
|
48 |
-
|
49 |
|
50 |
-
def parse_acp_string(message_str: str) -> ACPMessage:
|
51 |
-
"""
|
52 |
-
Convert "[PERFORMATIVE] sender β receiver: content"
|
53 |
-
back to an ACPMessage object
|
54 |
-
"""
|
55 |
-
try:
|
56 |
-
parts = message_str.split("] ", 1)
|
57 |
-
performative = parts[0][1:].lower()
|
58 |
-
meta, content = parts[1].split(": ", 1)
|
59 |
-
sender, receiver = [s.strip() for s in meta.split("β")]
|
60 |
-
return ACPMessage(sender, receiver, performative, content.strip())
|
61 |
-
except Exception:
|
62 |
-
return ACPMessage("Unknown", "Unknown", "inform", "Failed to parse message.")
|
63 |
-
|
64 |
-
# Gradio interface
|
65 |
-
with gr.Blocks(title="BotTalks") as demo:
|
66 |
-
gr.Markdown("# π€ BotTalks: Programmer vs Debugger\nAgent Communication Protocol Chat")
|
67 |
-
|
68 |
-
chatbox = gr.Textbox(label="Conversation", lines=20)
|
69 |
-
|
70 |
-
with gr.Row():
|
71 |
-
start_btn = gr.Button("Start Conversation π")
|
72 |
-
next_btn = gr.Button("Next Turn π")
|
73 |
-
|
74 |
-
start_btn.click(start_conversation, outputs=chatbox)
|
75 |
-
next_btn.click(continue_conversation, outputs=chatbox)
|
76 |
-
|
77 |
-
# Run app
|
78 |
demo.launch()
|
|
|
4 |
from agents.programmer import ProgrammerAgent
|
5 |
from agents.debugger import DebuggerAgent
|
6 |
from agents.base_agent import ACPMessage
|
7 |
+
from firebase.firebase_config import log_message_to_firestore
|
8 |
|
9 |
+
# Init agents
|
10 |
codebot = ProgrammerAgent()
|
11 |
bugbot = DebuggerAgent()
|
12 |
|
13 |
+
def chat_with_bots(user_input):
|
14 |
+
# Send same input to both agents
|
15 |
+
msg_to_codebot = ACPMessage(sender="User", receiver="CodeBot", performative="request", content=user_input)
|
16 |
+
msg_to_bugbot = ACPMessage(sender="User", receiver="BugBot", performative="request", content=user_input)
|
17 |
|
18 |
+
# Log inputs
|
19 |
+
log_message_to_firestore(msg_to_codebot.to_dict())
|
20 |
+
log_message_to_firestore(msg_to_bugbot.to_dict())
|
21 |
|
22 |
+
# Get both responses
|
23 |
+
reply_codebot = codebot.receive_message(msg_to_codebot)
|
24 |
+
reply_bugbot = bugbot.receive_message(msg_to_bugbot)
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
# Log responses
|
27 |
+
log_message_to_firestore(reply_codebot.to_dict())
|
28 |
+
log_message_to_firestore(reply_bugbot.to_dict())
|
29 |
|
30 |
+
# Format reply for chat
|
31 |
+
full_reply = f"""
|
32 |
+
π§ **CodeBot** (Programmer):
|
33 |
+
{reply_codebot.content}
|
34 |
|
35 |
+
π **BugBot** (Debugger):
|
36 |
+
{reply_bugbot.content}
|
37 |
+
"""
|
38 |
+
return full_reply.strip()
|
39 |
|
40 |
+
# Gradio UI
|
41 |
+
with gr.Blocks(title="BotTalks: Chat with 2 AI Agents") as demo:
|
42 |
+
gr.Markdown("# π€ BotTalks: Chat with 2 AI Friends!\nAsk anything and see how both agents respond.")
|
43 |
+
input_box = gr.Textbox(label="You", placeholder="Ask something like: How do I reverse a list?", lines=2)
|
44 |
+
output_box = gr.Textbox(label="Responses", lines=10)
|
45 |
|
46 |
+
send_btn = gr.Button("Send")
|
|
|
|
|
47 |
|
48 |
+
send_btn.click(chat_with_bots, inputs=input_box, outputs=output_box)
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
demo.launch()
|