-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
97 lines (77 loc) · 2.75 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#%% packages
from autogen import ConversableAgent
import os
import streamlit as st
def main():
# LLM config
llm_config = {"config_list": [
{"model": "gpt-4o-mini",
"temperature": 0.9,
"api_key": os.environ.get("OPENAI_API_KEY")}]}
st.title("Controversial Debate")
prompt = st.chat_input("Enter a topic to debate about:")
if prompt:
st.header(f"Topic: {prompt}")
with st.expander("Conversation Settings"):
number_of_turns = st.slider("Number of turns", min_value=1, max_value=10, value=1)
col1, col2 = st.columns(2)
with col1:
st.subheader("Style of Person A")
style_a = st.radio(
"Choose style for first speaker:",
["Friendly", "Neutral", "Unfriendly"],
key="style_a"
)
with col2:
st.subheader("Style of Person B")
style_b = st.radio(
"Choose style for second speaker:",
["Friendly", "Neutral", "Unfriendly"],
key="style_b"
)
if prompt:
#%% set up the agent: Jack, the flat earther
person_a = ConversableAgent(
name="user",
system_message=f"""
You are a person who believes that {prompt}.
You try to convince others of this.
You answer in a {style_a} way.
Answer very short and concise.
""",
llm_config=llm_config,
human_input_mode="NEVER",
)
#%% set up the agent: Alice, the scientist
person_b = ConversableAgent(
name="ai",
system_message="""
You are a person who believes the opposite of {prompt}.
You answer in a {style_b} way.
Answer very short and concise.
""",
llm_config=llm_config,
human_input_mode="NEVER",
)
# %% start the conversation
result = person_a.initiate_chat(
recipient=person_b,
message=prompt,
max_turns=number_of_turns)
messages = result.chat_history
for message in messages:
name = message["name"]
if name == "user":
with st.container():
col1, col2 = st.columns([3, 7])
with col2:
with st.chat_message(name=name):
st.write(message["content"])
else:
with st.container():
col1, col2 = st.columns([7, 3])
with col1:
with st.chat_message(name=name):
st.write(message["content"])
if __name__ == "__main__":
main()