Spaces:
Runtime error
Runtime error
preprocess the output of gpt
Browse files- bots/debate_bot.py +28 -63
bots/debate_bot.py
CHANGED
@@ -7,6 +7,7 @@ from modules.gpt_modules import gpt_call
|
|
7 |
def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0):
|
8 |
|
9 |
print("prompt", prompt)
|
|
|
10 |
|
11 |
##################################################
|
12 |
# Bot Role에 따라서 Bot Persona 변경
|
@@ -38,8 +39,8 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
38 |
debate_preset = "\n".join([
|
39 |
"Debate Rules: ",
|
40 |
"1) This debate will be divided into two teams, pro and con, with two debates on each team.",
|
41 |
-
"2) The order of speaking is: first debater for the pro side, first debater for the con side, second debater for the pro side, second debater for the con side
|
42 |
-
"3) Answer logically with an introduction, body, and conclusion
|
43 |
"User debate role: " + user_debate_role,
|
44 |
"Bot debate roles: " + ", ".join(bot_debate_role_list) + "\n",
|
45 |
"Debate subject: " + debate_subject
|
@@ -68,7 +69,7 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
68 |
template="\n".join([
|
69 |
bot_preset, #persona
|
70 |
"{prompt}",
|
71 |
-
"Only say " + debate_role[0] + "\'s opinion after
|
72 |
debate_role[0] + ": "
|
73 |
])
|
74 |
)
|
@@ -77,6 +78,10 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
77 |
)
|
78 |
first_response = gpt_call(first_bot_prompt)
|
79 |
|
|
|
|
|
|
|
|
|
80 |
bot_response = "\n".join([
|
81 |
bot_preset + "\n",
|
82 |
"-----------------------------------------------------------------",
|
@@ -110,7 +115,7 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
110 |
input_variables=["first_prompt"],
|
111 |
template="\n".join([
|
112 |
bot_preset, #persona
|
113 |
-
"Only say " + debate_role[1] + "\'s opinion after
|
114 |
debate_role[0] + ": " + "{first_prompt}",
|
115 |
debate_role[1] + ": "
|
116 |
])
|
@@ -120,6 +125,12 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
120 |
)
|
121 |
second_response = gpt_call(second_bot_prompt)
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
bot_response = "\n".join([
|
124 |
bot_preset + "\n",
|
125 |
"-----------------------------------------------------------------",
|
@@ -156,7 +167,7 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
156 |
input_variables=["first_prompt"],
|
157 |
template="\n".join([
|
158 |
bot_preset, #persona
|
159 |
-
"Only say " + debate_role[1] + "'s opinion after
|
160 |
debate_role[0] + ": " + "{first_prompt}",
|
161 |
debate_role[1] + ": "
|
162 |
])
|
@@ -171,7 +182,7 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
171 |
input_variables=["first_prompt", "second_prompt"],
|
172 |
template="\n".join([
|
173 |
bot_preset, #persona
|
174 |
-
"Only say " + debate_role[2] + "\'s opinion after
|
175 |
debate_role[0] + ": " + "{first_prompt}",
|
176 |
debate_role[1] + ": " + "{second_prompt}",
|
177 |
debate_role[2] + ": "
|
@@ -183,6 +194,14 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
183 |
)
|
184 |
third_response = gpt_call(third_bot_prompt)
|
185 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
bot_response = "\n".join([
|
187 |
bot_preset + "\n",
|
188 |
"-----------------------------------------------------------------",
|
@@ -194,65 +213,11 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
|
|
194 |
"-----------------------------------------------------------------",
|
195 |
"It's your turn! Write your opinion!"
|
196 |
])
|
197 |
-
|
198 |
else:
|
199 |
pass
|
200 |
|
201 |
-
|
202 |
-
|
203 |
-
# dialog_prompt_template = PromptTemplate(
|
204 |
-
# input_variables=["prompt"],
|
205 |
-
# template="\n".join([
|
206 |
-
# bot_persona, #persona
|
207 |
-
# few_shot_prompt,
|
208 |
-
# "Debate Subject: " + debate_subject,
|
209 |
-
# history,
|
210 |
-
# "User: {prompt}",
|
211 |
-
# "Bot: "
|
212 |
-
# ])
|
213 |
-
# )
|
214 |
-
|
215 |
-
# bot_prompt = dialog_prompt_template.format(
|
216 |
-
# prompt=prompt
|
217 |
-
# )
|
218 |
-
# bot_response = gpt_call(bot_prompt)
|
219 |
-
|
220 |
-
# return bot_response
|
221 |
-
# # Assign user one of the following roles
|
222 |
-
# elif history_num == 1:
|
223 |
-
# pass
|
224 |
-
|
225 |
-
# bot_persona = "\n".join([
|
226 |
-
# 'Debate Rules:',
|
227 |
-
# "1) This debate will be divided into two teams, pro and con, with two debates on each team.",
|
228 |
-
# "2) The order of speaking is: first debater for the pro side, first debater for the con side, second debater for the pro side, second debater for the con side.",
|
229 |
-
|
230 |
-
# "Assign user one of the following roles: first debater for the pro side, first debater for the con side, second debater fo the pro side, seconde debater for the con side.",
|
231 |
-
# "Debate the remaining roles you didn't give user. With given Debate Subject.",
|
232 |
-
|
233 |
-
# ])
|
234 |
-
# few_shot_prompt = "\n".join([
|
235 |
-
# ""
|
236 |
-
# ])
|
237 |
-
# else:
|
238 |
-
# print("bot_role is needed")
|
239 |
-
|
240 |
-
|
241 |
-
# dialog_prompt_template = PromptTemplate(
|
242 |
-
# input_variables=["prompt"],
|
243 |
-
# template="\n".join([
|
244 |
-
# bot_persona, #persona
|
245 |
-
# few_shot_prompt,
|
246 |
-
# "Debate Subject: " + debate_subject,
|
247 |
-
# history,
|
248 |
-
# "User: {prompt}",
|
249 |
-
# "Bot: "
|
250 |
-
# ])
|
251 |
-
# )
|
252 |
|
253 |
-
# bot_prompt = dialog_prompt_template.format(
|
254 |
-
# prompt=prompt
|
255 |
-
# )
|
256 |
-
# bot_response = gpt_call(bot_prompt)
|
257 |
|
258 |
-
|
|
|
7 |
def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0):
|
8 |
|
9 |
print("prompt", prompt)
|
10 |
+
print("history", history)
|
11 |
|
12 |
##################################################
|
13 |
# Bot Role에 따라서 Bot Persona 변경
|
|
|
39 |
debate_preset = "\n".join([
|
40 |
"Debate Rules: ",
|
41 |
"1) This debate will be divided into two teams, pro and con, with two debates on each team.",
|
42 |
+
"2) The order of speaking is: first debater for the pro side, first debater for the con side, second debater for the pro side, second debater for the con side.",
|
43 |
+
"3) Answer logically with an introduction, body, and conclusion.\n", #add this one.
|
44 |
"User debate role: " + user_debate_role,
|
45 |
"Bot debate roles: " + ", ".join(bot_debate_role_list) + "\n",
|
46 |
"Debate subject: " + debate_subject
|
|
|
69 |
template="\n".join([
|
70 |
bot_preset, #persona
|
71 |
"{prompt}",
|
72 |
+
"Only say " + debate_role[0] + "\'s opinion after \':\'. Do not write " + debate_role[1] + "\'s " + "opinions, " + debate_role[2] + "\'s " + "opinions and " + debate_role[3] + "\'s " + "opinions.",
|
73 |
debate_role[0] + ": "
|
74 |
])
|
75 |
)
|
|
|
78 |
)
|
79 |
first_response = gpt_call(first_bot_prompt)
|
80 |
|
81 |
+
# preprocess
|
82 |
+
# if first_response contain the first debater for the con side's opinion, remove it.
|
83 |
+
first_response = re.sub(debate_role[1] + ":.*", "", first_response)
|
84 |
+
|
85 |
bot_response = "\n".join([
|
86 |
bot_preset + "\n",
|
87 |
"-----------------------------------------------------------------",
|
|
|
115 |
input_variables=["first_prompt"],
|
116 |
template="\n".join([
|
117 |
bot_preset, #persona
|
118 |
+
"Only say " + debate_role[1] + "\'s opinion after \':\'. Do not write " + debate_role[0] + "\'s " + "opinions, " + debate_role[2] + "\'s " + "opinions and " + debate_role[3] + "\'s " + "opinions.",
|
119 |
debate_role[0] + ": " + "{first_prompt}",
|
120 |
debate_role[1] + ": "
|
121 |
])
|
|
|
125 |
)
|
126 |
second_response = gpt_call(second_bot_prompt)
|
127 |
|
128 |
+
# preprocess
|
129 |
+
# if first_response contain the first debater for the con side's opinion, remove it.
|
130 |
+
first_response = re.sub(debate_role[1] + ":.*", "", first_response)
|
131 |
+
# if second_response contain the first debater for the con side's opinion, remove it.
|
132 |
+
second_response = re.sub(debate_role[2] + ":.*", "", second_response)
|
133 |
+
|
134 |
bot_response = "\n".join([
|
135 |
bot_preset + "\n",
|
136 |
"-----------------------------------------------------------------",
|
|
|
167 |
input_variables=["first_prompt"],
|
168 |
template="\n".join([
|
169 |
bot_preset, #persona
|
170 |
+
"Only say " + debate_role[1] + "'s opinion after \':\'. Do not write " + debate_role[0] + "\'s " + "opinions, " + debate_role[2] + "\'s " + "opinions and " + debate_role[3] + "\'s " + "opinions.",
|
171 |
debate_role[0] + ": " + "{first_prompt}",
|
172 |
debate_role[1] + ": "
|
173 |
])
|
|
|
182 |
input_variables=["first_prompt", "second_prompt"],
|
183 |
template="\n".join([
|
184 |
bot_preset, #persona
|
185 |
+
"Only say " + debate_role[2] + "\'s opinion after \':\'. Do not write " + debate_role[0] + "\'s " + "opinions, " + debate_role[1] + "\'s " + "opinions and " + debate_role[3] + "\'s " + "opinions.",
|
186 |
debate_role[0] + ": " + "{first_prompt}",
|
187 |
debate_role[1] + ": " + "{second_prompt}",
|
188 |
debate_role[2] + ": "
|
|
|
194 |
)
|
195 |
third_response = gpt_call(third_bot_prompt)
|
196 |
|
197 |
+
# preprocess
|
198 |
+
# if first_response contain the first debater for the con side's opinion, remove it.
|
199 |
+
first_response = re.sub(debate_role[1] + ":.*", "", first_response)
|
200 |
+
# if second_response contain the first debater for the con side's opinion, remove it.
|
201 |
+
second_response = re.sub(debate_role[2] + ":.*", "", second_response)
|
202 |
+
# if third_response contain the first debater for the con side's opinion, remove it.
|
203 |
+
third_response = re.sub(debate_role[3] + ":.*", "", third_response)
|
204 |
+
|
205 |
bot_response = "\n".join([
|
206 |
bot_preset + "\n",
|
207 |
"-----------------------------------------------------------------",
|
|
|
213 |
"-----------------------------------------------------------------",
|
214 |
"It's your turn! Write your opinion!"
|
215 |
])
|
|
|
216 |
else:
|
217 |
pass
|
218 |
|
219 |
+
if history_num == 1:
|
220 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
|
|
|
|
|
|
|
|
|
222 |
|
223 |
+
return bot_response
|