Unggi commited on
Commit
1bae996
·
1 Parent(s): 7ed3446

history_num 0 detailed changed

Browse files
Files changed (1) hide show
  1. bots/debate_bot.py +51 -7
bots/debate_bot.py CHANGED
@@ -4,6 +4,11 @@ from langchain.prompts import PromptTemplate
4
  from modules.gpt_modules import gpt_call
5
 
6
 
 
 
 
 
 
7
  def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0):
8
 
9
  print("prompt", prompt)
@@ -80,7 +85,9 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
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",
@@ -127,9 +134,10 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
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",
@@ -196,11 +204,13 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
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",
@@ -216,8 +226,42 @@ def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0
216
  else:
217
  pass
218
 
 
219
  if history_num == 1:
220
- pass
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
 
223
  return bot_response
 
4
  from modules.gpt_modules import gpt_call
5
 
6
 
7
+ def erase_start_word_and_after(text, start_word):
8
+ pattern = re.compile(re.escape(start_word) + '.*')
9
+ return re.sub(pattern, '', text)
10
+
11
+
12
  def debate_bot(prompt, history="", debate_subject="", bot_role="", history_num=0):
13
 
14
  print("prompt", prompt)
 
85
 
86
  # preprocess
87
  # if first_response contain the first debater for the con side's opinion, remove it.
88
+ first_response = erase_start_word_and_after(first_response, debate_role[1])
89
+
90
+ #first_response = re.sub(debate_role[1] + ":.*", "", first_response)
91
 
92
  bot_response = "\n".join([
93
  bot_preset + "\n",
 
134
 
135
  # preprocess
136
  # if first_response contain the first debater for the con side's opinion, remove it.
137
+ first_response = erase_start_word_and_after(first_response, debate_role[1])
138
  # if second_response contain the first debater for the con side's opinion, remove it.
139
+ #second_response = re.sub(debate_role[2] + ":.*", "", second_response)
140
+ second_response = erase_start_word_and_after(second_response, debate_role[2])
141
 
142
  bot_response = "\n".join([
143
  bot_preset + "\n",
 
204
 
205
  # preprocess
206
  # if first_response contain the first debater for the con side's opinion, remove it.
207
+ first_response = erase_start_word_and_after(first_response, debate_role[1])
208
  # if second_response contain the first debater for the con side's opinion, remove it.
209
+ #second_response = re.sub(debate_role[2] + ":.*", "", second_response)
210
+ second_response = erase_start_word_and_after(second_response, debate_role[2])
211
  # if third_response contain the first debater for the con side's opinion, remove it.
212
+ thir_response = erase_start_word_and_after(thir_response, debate_role[3])
213
+ #third_response = re.sub(debate_role[3] + ":.*", "", third_response)
214
 
215
  bot_response = "\n".join([
216
  bot_preset + "\n",
 
226
  else:
227
  pass
228
 
229
+ # Answer and Ask Judgement.
230
  if history_num == 1:
231
+ print("history1: ", history)
232
+
233
+ # user가 가장 첫번째로 답변했다면, 봇이 2, 3, 4 답변을 하고, 평가할지를 물어보면 됨.
234
+ if "User debate role: first debater for the pro side" in history:
235
+ ask_judgement = "Do you want to be the judge of this debate? (If you want, enter any words.)"
236
+ bot_response = ask_judgement
237
+
238
+ # user가 두번째로 답변했다면, 봇이 3, 4 번째 답변을 하고, 평가할지를 물어보면 됨.
239
+ elif "User debate role: first debater for the con side" in history:
240
+
241
+ ask_judgement = "Do you want to be the judge of this debate? (If you want, enter any words.)"
242
+ bot_response = ask_judgement
243
+
244
+ # user가 세번째로 답변했다면, 봇이 4 번째 답변을 하고, 평가할지를 물어보면 됨.
245
+ elif "User debate role: second debater for the pro side" in history:
246
+ ask_judgement = "Do you want to be the judge of this debate? (If you want, enter any words.)"
247
+ bot_response = ask_judgement
248
+
249
+ # user가 네번째로 답변했다면, 바로 평가할지를 물어보면 됨.
250
+ elif "User debate role: second debater for the con side" in history:
251
+ ask_judgement = "Do you want to be the judge of this debate? (If you want, enter any words.)"
252
+ bot_response = ask_judgement
253
+ else:
254
+ pass
255
+
256
+ # Judgement.
257
+ if history_num == 2:
258
+ judgement_word_list = "\n".join([
259
+ "!!Instruction!",
260
+ "You are now the judge of this debate. Evaluate the debate according to the rules below.",
261
+ "Rule 1. Decide between the pro and con teams.",
262
+ "Rule 2. Summarize the debate as a whole and what each debater said.",
263
+ "Rule 3. For each debater, explain what was persuasive and what made the differnce between winning and losing.",
264
+ ])
265
 
266
 
267
  return bot_response