Yiqiao Jin commited on
Commit
c291457
1 Parent(s): cb54601

Update Demo

Browse files
agentreview/environments/paper_review.py CHANGED
@@ -211,3 +211,7 @@ class PaperReview(Conversation):
211
  player_name, phase_index=self.phase_index, next_player_idx=self._next_player_index,
212
  player_names=self.player_names
213
  )
 
 
 
 
 
211
  player_name, phase_index=self.phase_index, next_player_idx=self._next_player_index,
212
  player_names=self.player_names
213
  )
214
+
215
+ def get_messages_from_player(self, player_name: str) -> List[str]:
216
+ """Get the list of actions that the player can take."""
217
+ return self.message_pool.get_messages_from_player(player_name)
agentreview/message.py CHANGED
@@ -84,6 +84,7 @@ class MessagePool:
84
  """
85
  self._messages.append(message)
86
 
 
87
  def print(self):
88
  """Print all the messages in the pool."""
89
  for message in self._messages:
@@ -148,3 +149,16 @@ class MessagePool:
148
  ):
149
  visible_messages.append(message)
150
  return visible_messages
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  """
85
  self._messages.append(message)
86
 
87
+
88
  def print(self):
89
  """Print all the messages in the pool."""
90
  for message in self._messages:
 
149
  ):
150
  visible_messages.append(message)
151
  return visible_messages
152
+
153
+ def get_messages_from_player(self, player_name: str) -> List[Message]:
154
+ """
155
+ Get all the messages from a given player.
156
+
157
+ Parameters:
158
+ player_name (str): The name of the player.
159
+
160
+ Returns:
161
+ List[Message]: A list of messages from the player.
162
+ """
163
+ return [message for message in self._messages if message.agent_name == player_name]
164
+
app.py CHANGED
@@ -14,7 +14,8 @@ from agentreview.environments import PaperReview
14
  from agentreview.paper_review_arena import PaperReviewArena
15
  from agentreview.utility.experiment_utils import initialize_players
16
  from agentreview.paper_review_player import PaperExtractorPlayer, AreaChair, Reviewer
17
- from agentreview.role_descriptions import get_reviewer_description, get_ac_description, get_author_config, get_paper_extractor_config
 
18
 
19
  # 该文件的使命是前端交互:构建前端页面,从页面中获取用户的配置,传入后端运行,将结果实时展示到相应模块
20
 
@@ -37,8 +38,8 @@ css = """#col-container {max-width: 90%; margin-left: auto; margin-right: auto;
37
  DEBUG = False
38
 
39
  DEFAULT_BACKEND = "openai-chat"
40
- MAX_NUM_PLAYERS = 4
41
- DEFAULT_NUM_PLAYERS = 4
42
  CURRENT_STEP_INDEX = 0
43
 
44
  def load_examples():
@@ -78,7 +79,7 @@ def get_player_components(name, visible):
78
  # )
79
 
80
  with gr.Row():
81
- # 将三个属性做成dropdown
82
  Intention_config = gr.Dropdown(
83
  choices=["Benign", "Malicious", "Neutral"],
84
  interactive=True,
@@ -96,7 +97,7 @@ def get_player_components(name, visible):
96
  )
97
 
98
  Responsibility_config = gr.Dropdown(
99
- choices=["Responsible", "Lazy", "Normal"],
100
  interactive=True,
101
  label = "Responsibility",
102
  show_label=True,
@@ -113,10 +114,7 @@ def get_player_components(name, visible):
113
  autoscroll=False,
114
  value=get_reviewer_description()
115
  )
116
-
117
- # role_desc = gr.Markdown(value=get_reviewer_description(),
118
- # visible=visible)
119
-
120
  def update_role_desc(Intention_config, Knowledge_config, Responsibility_config):
121
 
122
  is_benign = True if Intention_config == "Benign" else (False if Intention_config == "Malicious" else None)
@@ -142,7 +140,7 @@ def get_player_components(name, visible):
142
  f"{name} Parameters", open=False, visible=visible
143
  ) as accordion:
144
  temperature = gr.Slider(
145
- minimum=0,
146
  maximum=2.0,
147
  step=0.1,
148
  interactive=True,
@@ -162,6 +160,51 @@ def get_player_components(name, visible):
162
 
163
  return [role_name, Intention_config, Knowledge_config, Responsibility_config, backend_type, accordion, temperature, max_tokens]
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  def get_area_chair_components(name, visible):
166
  with gr.Row():
167
  with gr.Column():
@@ -191,13 +234,13 @@ def get_area_chair_components(name, visible):
191
  visible=visible,
192
  value=get_ac_description("BASELINE", "ac_write_metareviews", 'None', 1),
193
  )
194
-
195
  def update_role_desc(AC_type):
196
  ac_type = 'BASELINE' if AC_type == "Normal" else AC_type.lower()
197
  return get_ac_description(ac_type, "ac_write_metareviews", "None", 1) # FIXME:依据阶段变化
198
-
199
  AC_type.select(fn=update_role_desc, inputs=[AC_type], outputs=[role_desc])
200
-
201
  with gr.Column():
202
  backend_type = gr.Dropdown(
203
  show_label=False,
@@ -235,14 +278,14 @@ def get_empty_state():
235
  return gr.State({"arena": None})
236
 
237
 
238
- with gr.Blocks(css=css) as demo:
239
  state = get_empty_state()
240
  all_components = []
241
 
242
  with gr.Column(elem_id="col-container"):
243
  gr.Markdown(
244
- """# 🤖 AgentReview<br>
245
- Using Multi-Agent to review your paper!.
246
  **[Project Homepage](https://github.com/Ahren09/AgentReview)**""",
247
  elem_id="header",
248
  )
@@ -269,14 +312,22 @@ Using Multi-Agent to review your paper!.
269
 
270
  player_chatbots = []
271
  for i in range(MAX_NUM_PLAYERS):
272
- player_name = f"Reviewer {i + 1}" if i < MAX_NUM_PLAYERS-1 else "AC"
 
 
 
 
 
 
 
 
273
  with gr.Tab(player_name, visible=(i < DEFAULT_NUM_PLAYERS)):
274
  player_chatbot = gr.Chatbot(
275
  elem_id=f"chatbox-{i}",
276
  visible=i < DEFAULT_NUM_PLAYERS,
277
  label=player_name,
278
  show_label=False,
279
- height=600, # FIXME: 无效设置
280
  )
281
  player_chatbots.append(player_chatbot)
282
 
@@ -292,19 +343,32 @@ Using Multi-Agent to review your paper!.
292
  all_players_components, players_idx2comp = [], {}
293
  with gr.Blocks():
294
  for i in range(MAX_NUM_PLAYERS):
295
-
296
- player_name = f"Reviewer {i + 1}" if i < MAX_NUM_PLAYERS-1 else "AC"
 
 
 
 
 
 
 
 
 
297
  with gr.Tab(
298
  player_name, visible=(i < DEFAULT_NUM_PLAYERS)
299
  ) as tab:
300
- if player_name != "AC":
301
  player_comps = get_player_components(
302
  player_name, visible=(i < DEFAULT_NUM_PLAYERS)
303
  )
304
- else:
305
  player_comps = get_area_chair_components(
306
  player_name, visible=(i < DEFAULT_NUM_PLAYERS)
307
  )
 
 
 
 
308
 
309
  players_idx2comp[i] = player_comps + [tab]
310
  all_players_components += player_comps + [tab]
@@ -362,13 +426,12 @@ Using Multi-Agent to review your paper!.
362
  # Step 1: Initialize the players
363
  num_players = MAX_NUM_PLAYERS
364
 
365
- # 为了适应之前的接口填充无意义数据
366
- conference = "EMNLP 2024"
367
  paper_decision = "Accept"
368
  data_dir = ''
369
  paper_id = "12345"
370
-
371
- # Notion: 此处设置参数,experiment_name为无效填充参数
372
  args = Namespace(openai_client_type="azure_openai",
373
  experiment_name="test",
374
  max_num_words=16384)
@@ -402,7 +465,10 @@ Using Multi-Agent to review your paper!.
402
 
403
 
404
  for i in range(num_players):
405
- if i < num_players-1: # reviewer
 
 
 
406
  role_name, intention_config, knowledge_config, responsibility_config, backend_type, temperature, max_tokens = (
407
  all_comps[c]
408
  for c in players_idx2comp[i]
@@ -420,7 +486,7 @@ Using Multi-Agent to review your paper!.
420
 
421
  role_desc = get_reviewer_description(is_benign, is_knowledgeable, is_responsible)
422
 
423
- if i == num_players-1: # AC
424
  role_name, ac_type, backend_type, temperature, max_tokens = (
425
  all_comps[c]
426
  for c in players_idx2comp[i]
@@ -432,7 +498,21 @@ Using Multi-Agent to review your paper!.
432
  experiment_setting["players"]['AC'].append({"area_chair_type": ac_type})
433
 
434
  role_desc = get_ac_description(ac_type, "ac_write_metareviews", "None", 1)
435
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
436
  # common config for all players
437
  player_config = {
438
  "name": role_name,
@@ -461,10 +541,10 @@ Using Multi-Agent to review your paper!.
461
  # 人为加入paper extractor
462
  paper_extractor_config = get_paper_extractor_config(max_tokens=2048)
463
 
464
- paper_extractor = PaperExtractorPlayer( paper_pdf_path=paper_pdf_path,
465
- data_dir=data_dir, paper_id=paper_id,
466
- paper_decision=paper_decision, args=args,
467
- conference=conference, **paper_extractor_config)
468
  players.append(paper_extractor)
469
 
470
  # 人为加入author
@@ -515,6 +595,8 @@ Using Multi-Agent to review your paper!.
515
  all_messages = timestep.observation
516
  all_messages[0].content = 'Paper content has been extracted.'
517
  chatbot_output = _convert_to_chatbot_output(all_messages, display_recv=True)
 
 
518
  update_dict = {
519
  chatbot: chatbot_output,
520
  btn_step: gr.update(
@@ -523,10 +605,37 @@ Using Multi-Agent to review your paper!.
523
  btn_restart: gr.update(interactive=True),
524
  state: cur_state,
525
  }
526
-
527
- # Reviewer 1, 2, 3 Area Chair, Paper Extractor, Author
528
-
529
- for i, player in enumerate(arena.players):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  if 'Reviewer' in player.name and arena.environment.phase_index < 4: # FIXME: 临时逻辑
531
  player_messages = arena.environment.get_observation(player.name)
532
  # 不要显示第一条长段的信息,只显示 文章内容已被抽取
@@ -540,7 +649,11 @@ Using Multi-Agent to review your paper!.
540
  player_output = _convert_to_chatbot_output(player_messages)
541
  # Update the player's chatbot output
542
  update_dict[player_chatbots[3]] = player_output
543
-
 
 
 
 
544
  yield update_dict
545
 
546
 
@@ -594,7 +707,7 @@ Using Multi-Agent to review your paper!.
594
  ):
595
  comp.change(_disable_step_button, state, btn_step)
596
 
597
- # print(set(all_components + [state]))
598
  btn_step.click(
599
  step_game,
600
  set(all_components + [state]),
 
14
  from agentreview.paper_review_arena import PaperReviewArena
15
  from agentreview.utility.experiment_utils import initialize_players
16
  from agentreview.paper_review_player import PaperExtractorPlayer, AreaChair, Reviewer
17
+ from agentreview.role_descriptions import (get_reviewer_description, get_ac_description, get_author_config,
18
+ get_paper_extractor_config, get_author_description)
19
 
20
  # 该文件的使命是前端交互:构建前端页面,从页面中获取用户的配置,传入后端运行,将结果实时展示到相应模块
21
 
 
38
  DEBUG = False
39
 
40
  DEFAULT_BACKEND = "openai-chat"
41
+ MAX_NUM_PLAYERS = 5
42
+ DEFAULT_NUM_PLAYERS = 5
43
  CURRENT_STEP_INDEX = 0
44
 
45
  def load_examples():
 
79
  # )
80
 
81
  with gr.Row():
82
+ # Converting the three attributes into dropdowns
83
  Intention_config = gr.Dropdown(
84
  choices=["Benign", "Malicious", "Neutral"],
85
  interactive=True,
 
97
  )
98
 
99
  Responsibility_config = gr.Dropdown(
100
+ choices=["Responsible", "Irresponsible", "Normal"],
101
  interactive=True,
102
  label = "Responsibility",
103
  show_label=True,
 
114
  autoscroll=False,
115
  value=get_reviewer_description()
116
  )
117
+
 
 
 
118
  def update_role_desc(Intention_config, Knowledge_config, Responsibility_config):
119
 
120
  is_benign = True if Intention_config == "Benign" else (False if Intention_config == "Malicious" else None)
 
140
  f"{name} Parameters", open=False, visible=visible
141
  ) as accordion:
142
  temperature = gr.Slider(
143
+ minimum=0.,
144
  maximum=2.0,
145
  step=0.1,
146
  interactive=True,
 
160
 
161
  return [role_name, Intention_config, Knowledge_config, Responsibility_config, backend_type, accordion, temperature, max_tokens]
162
 
163
+
164
+ def get_author_components(name, visible):
165
+ with gr.Row():
166
+ with gr.Column():
167
+ role_desc = gr.Textbox(
168
+ lines=8,
169
+ max_lines=8,
170
+ show_label=False,
171
+ interactive=True,
172
+ visible=visible,
173
+ value=get_author_description(),
174
+ )
175
+ with gr.Column():
176
+ backend_type = gr.Dropdown(
177
+ show_label=False,
178
+ choices=list(BACKEND_REGISTRY.keys()),
179
+ interactive=True,
180
+ visible=visible,
181
+ value=DEFAULT_BACKEND,
182
+ )
183
+ with gr.Accordion(
184
+ f"{name} Parameters", open=False, visible=visible
185
+ ) as accordion:
186
+ temperature = gr.Slider(
187
+ minimum=0.,
188
+ maximum=2.0,
189
+ step=0.1,
190
+ interactive=True,
191
+ visible=visible,
192
+ label="temperature",
193
+ value=0.7,
194
+ )
195
+ max_tokens = gr.Slider(
196
+ minimum=10,
197
+ maximum=500,
198
+ step=10,
199
+ interactive=True,
200
+ visible=visible,
201
+ label="max tokens",
202
+ value=200,
203
+ )
204
+
205
+ return [role_desc, backend_type, accordion, temperature, max_tokens]
206
+
207
+
208
  def get_area_chair_components(name, visible):
209
  with gr.Row():
210
  with gr.Column():
 
234
  visible=visible,
235
  value=get_ac_description("BASELINE", "ac_write_metareviews", 'None', 1),
236
  )
237
+
238
  def update_role_desc(AC_type):
239
  ac_type = 'BASELINE' if AC_type == "Normal" else AC_type.lower()
240
  return get_ac_description(ac_type, "ac_write_metareviews", "None", 1) # FIXME:依据阶段变化
241
+
242
  AC_type.select(fn=update_role_desc, inputs=[AC_type], outputs=[role_desc])
243
+
244
  with gr.Column():
245
  backend_type = gr.Dropdown(
246
  show_label=False,
 
278
  return gr.State({"arena": None})
279
 
280
 
281
+ with (gr.Blocks(css=css) as demo):
282
  state = get_empty_state()
283
  all_components = []
284
 
285
  with gr.Column(elem_id="col-container"):
286
  gr.Markdown(
287
+ """# 🤖[AgentReview](https://arxiv.org/abs/2406.12708)<br>
288
+ S Multi-Agent to Simulate conference reviews on your own papers.
289
  **[Project Homepage](https://github.com/Ahren09/AgentReview)**""",
290
  elem_id="header",
291
  )
 
312
 
313
  player_chatbots = []
314
  for i in range(MAX_NUM_PLAYERS):
315
+ if i in [0, 1, 2]:
316
+ player_name = f"Reviewer {i + 1}"
317
+
318
+ elif i == 3:
319
+ player_name = "AC"
320
+
321
+ elif i == 4:
322
+ player_name = "Author"
323
+
324
  with gr.Tab(player_name, visible=(i < DEFAULT_NUM_PLAYERS)):
325
  player_chatbot = gr.Chatbot(
326
  elem_id=f"chatbox-{i}",
327
  visible=i < DEFAULT_NUM_PLAYERS,
328
  label=player_name,
329
  show_label=False,
330
+ height=600, # FIXME: this parameter is not working
331
  )
332
  player_chatbots.append(player_chatbot)
333
 
 
343
  all_players_components, players_idx2comp = [], {}
344
  with gr.Blocks():
345
  for i in range(MAX_NUM_PLAYERS):
346
+ if i in [0, 1, 2]:
347
+ player_name = f"Reviewer {i + 1}"
348
+
349
+ elif i == 3:
350
+ player_name = "AC"
351
+
352
+ elif i == 4:
353
+ player_name = "Author"
354
+
355
+ else:
356
+ raise ValueError(f"Invalid player index: {i}")
357
  with gr.Tab(
358
  player_name, visible=(i < DEFAULT_NUM_PLAYERS)
359
  ) as tab:
360
+ if "Reviewer" in player_name:
361
  player_comps = get_player_components(
362
  player_name, visible=(i < DEFAULT_NUM_PLAYERS)
363
  )
364
+ elif player_name == "AC":
365
  player_comps = get_area_chair_components(
366
  player_name, visible=(i < DEFAULT_NUM_PLAYERS)
367
  )
368
+ elif player_name == "Author":
369
+ player_comps = get_author_components(
370
+ player_name, visible=(i < DEFAULT_NUM_PLAYERS)
371
+ )
372
 
373
  players_idx2comp[i] = player_comps + [tab]
374
  all_players_components += player_comps + [tab]
 
426
  # Step 1: Initialize the players
427
  num_players = MAX_NUM_PLAYERS
428
 
429
+ # You can ignore these fields for the demo
430
+ conference = "EMNLP2024"
431
  paper_decision = "Accept"
432
  data_dir = ''
433
  paper_id = "12345"
434
+
 
435
  args = Namespace(openai_client_type="azure_openai",
436
  experiment_name="test",
437
  max_num_words=16384)
 
465
 
466
 
467
  for i in range(num_players):
468
+
469
+ role_name = role_desc = backend_type = temperature = max_tokens = None
470
+
471
+ if i in [0, 1, 2]: # reviewer
472
  role_name, intention_config, knowledge_config, responsibility_config, backend_type, temperature, max_tokens = (
473
  all_comps[c]
474
  for c in players_idx2comp[i]
 
486
 
487
  role_desc = get_reviewer_description(is_benign, is_knowledgeable, is_responsible)
488
 
489
+ elif i == 3: # AC
490
  role_name, ac_type, backend_type, temperature, max_tokens = (
491
  all_comps[c]
492
  for c in players_idx2comp[i]
 
498
  experiment_setting["players"]['AC'].append({"area_chair_type": ac_type})
499
 
500
  role_desc = get_ac_description(ac_type, "ac_write_metareviews", "None", 1)
501
+
502
+ elif i == 4: # Author
503
+ role_name, backend_type, temperature, max_tokens = (
504
+ all_comps[c]
505
+ for c in players_idx2comp[i]
506
+ if not isinstance(c, (gr.Accordion, gr.Tab))
507
+ )
508
+
509
+ role_desc = get_author_description()
510
+
511
+ else:
512
+ raise ValueError(f"Invalid player index: {i}")
513
+
514
+
515
+
516
  # common config for all players
517
  player_config = {
518
  "name": role_name,
 
541
  # 人为加入paper extractor
542
  paper_extractor_config = get_paper_extractor_config(max_tokens=2048)
543
 
544
+ paper_extractor = PaperExtractorPlayer(paper_pdf_path=paper_pdf_path,
545
+ data_dir=data_dir, paper_id=paper_id,
546
+ paper_decision=paper_decision, args=args,
547
+ conference=conference, **paper_extractor_config)
548
  players.append(paper_extractor)
549
 
550
  # 人为加入author
 
595
  all_messages = timestep.observation
596
  all_messages[0].content = 'Paper content has been extracted.'
597
  chatbot_output = _convert_to_chatbot_output(all_messages, display_recv=True)
598
+
599
+ # Initialize update dictionary
600
  update_dict = {
601
  chatbot: chatbot_output,
602
  btn_step: gr.update(
 
605
  btn_restart: gr.update(interactive=True),
606
  state: cur_state,
607
  }
608
+
609
+ # Define a mapping of player names to their respective chatbots
610
+ player_name_to_chatbot = {
611
+ "Reviewer 1": player_chatbots[0],
612
+ "Reviewer 2": player_chatbots[1],
613
+ "Reviewer 3": player_chatbots[2],
614
+ "AC": player_chatbots[3],
615
+ "Author": player_chatbots[4],
616
+ }
617
+
618
+ # Update each player's chatbot output
619
+ for player in arena.players:
620
+ player_name = player.name
621
+ if player_name in player_name_to_chatbot:
622
+ player_messages = arena.environment.get_messages_from_player(player_name)
623
+ # player_messages[0].content = 'Paper content has been extracted.'
624
+ player_output = _convert_to_chatbot_output(player_messages)
625
+ update_dict[player_name_to_chatbot[player_name]] = player_output
626
+
627
+ # # Reviewer 1, 2, 3 Area Chair, Paper Extractor, Author
628
+ # for i, player in enumerate(arena.players):
629
+ # player_name = player.name
630
+ # # Get the messages for the current player
631
+ # player_messages = arena.environment.get_observation(player_name)
632
+ # player_messages[0].content = 'Paper content has been extracted.'
633
+ #
634
+ # # Convert messages to chatbot output
635
+ # player_output = _convert_to_chatbot_output(player_messages)
636
+
637
+
638
+ """
639
  if 'Reviewer' in player.name and arena.environment.phase_index < 4: # FIXME: 临时逻辑
640
  player_messages = arena.environment.get_observation(player.name)
641
  # 不要显示第一条长段的信息,只显示 文章内容已被抽取
 
649
  player_output = _convert_to_chatbot_output(player_messages)
650
  # Update the player's chatbot output
651
  update_dict[player_chatbots[3]] = player_output
652
+ """
653
+ # Ahren: Auto run
654
+ # if not timestep.terminal:
655
+ # yield from step_game(all_comps)
656
+
657
  yield update_dict
658
 
659
 
 
707
  ):
708
  comp.change(_disable_step_button, state, btn_step)
709
 
710
+ # Ahren: Auto run
711
  btn_step.click(
712
  step_game,
713
  set(all_components + [state]),