yuxwu commited on
Commit
374a68b
·
1 Parent(s): 7354e37

Intial demo release.

Browse files
app.py ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import json
3
+ import gradio as gr
4
+ from glob import glob
5
+
6
+ from chatarena.arena import Arena
7
+ from chatarena.backends import BACKEND_REGISTRY
8
+ from chatarena.backends.human import HumanBackendError
9
+ from chatarena.config import ArenaConfig
10
+ from chatarena.environments import ENV_REGISTRY
11
+ from chatarena.database import log_arena, log_messages, SupabaseDB, supabase_available
12
+
13
+ css = """#col-container {max-width: 90%; margin-left: auto; margin-right: auto; display: flex; flex-direction: column;}
14
+ #header {text-align: center;}
15
+ #col-chatbox {flex: 1; max-height: min(650px, 100%); display: flex;}
16
+ #chatbox {height: min(650px, 100%); max-height: 650px; display:flex;}
17
+ #label {font-size: 2em; padding: 0.5em; margin: 0;}
18
+ .message {font-size: 1.2em;}
19
+ .wrap.svelte-18ha8kq {flex: 1}
20
+ .wrap.svelte-18ha8kq.svelte-18ha8kq {max-height: min(600px, 100vh);}
21
+ .message-wrap {max-height: min(600px, 100vh);}
22
+ """
23
+
24
+ DEBUG = False
25
+
26
+ DEFAULT_BACKEND = "openai-chat"
27
+ DEFAULT_ENV = "conversation"
28
+ MAX_NUM_PLAYERS = 6
29
+ DEFAULT_NUM_PLAYERS = 2
30
+
31
+
32
+ def load_examples():
33
+ example_configs = {}
34
+ # Load json config files from examples folder
35
+ example_files = glob("examples/*.json")
36
+ for example_file in example_files:
37
+ with open(example_file, 'r') as f:
38
+ example = json.load(f)
39
+ example_configs[example["name"]] = example
40
+ return example_configs
41
+
42
+
43
+ EXAMPLE_REGISTRY = load_examples()
44
+
45
+ DB = SupabaseDB() if supabase_available else None
46
+
47
+
48
+ def get_moderator_components(visible=True):
49
+ name = "Moderator"
50
+ with gr.Row():
51
+ with gr.Column():
52
+ role_desc = gr.Textbox(label="Moderator role", lines=1, visible=visible, interactive=True,
53
+ placeholder=f"Enter the role description for {name}")
54
+ terminal_condition = gr.Textbox(show_label=False, lines=1, visible=visible, interactive=True,
55
+ placeholder="Enter the end criteria for the conversation")
56
+ with gr.Column():
57
+ backend_type = gr.Dropdown(show_label=False, visible=visible, interactive=True,
58
+ choices=list(BACKEND_REGISTRY.keys()), value=DEFAULT_BACKEND)
59
+ with gr.Accordion(f"{name} Parameters", open=False, visible=visible) as accordion:
60
+ temperature = gr.Slider(minimum=0, maximum=2.0, step=0.1, interactive=True, visible=visible,
61
+ label=f"temperature", value=0.7)
62
+ max_tokens = gr.Slider(minimum=10, maximum=500, step=10, interactive=True, visible=visible,
63
+ label=f"max tokens", value=200)
64
+
65
+ return [role_desc, terminal_condition, backend_type, accordion, temperature, max_tokens]
66
+
67
+
68
+ def get_player_components(name, visible):
69
+ with gr.Row():
70
+ with gr.Column():
71
+ role_desc = gr.Textbox(label=name, lines=3, interactive=True, visible=visible,
72
+ placeholder=f"Enter the role description for {name}")
73
+ with gr.Column():
74
+ backend_type = gr.Dropdown(show_label=False, choices=list(BACKEND_REGISTRY.keys()),
75
+ interactive=True, visible=visible, value=DEFAULT_BACKEND)
76
+ with gr.Accordion(f"{name} Parameters", open=False, visible=visible) as accordion:
77
+ temperature = gr.Slider(minimum=0, maximum=2.0, step=0.1, interactive=True, visible=visible,
78
+ label=f"temperature", value=0.7)
79
+ max_tokens = gr.Slider(minimum=10, maximum=500, step=10, interactive=True, visible=visible,
80
+ label=f"max tokens", value=200)
81
+
82
+ return [role_desc, backend_type, accordion, temperature, max_tokens]
83
+
84
+
85
+ def get_empty_state():
86
+ return gr.State({"arena": None})
87
+
88
+
89
+ with gr.Blocks(css=css) as demo:
90
+ state = get_empty_state()
91
+ all_components = []
92
+
93
+ with gr.Column(elem_id="col-container"):
94
+ gr.Markdown("""# 🏟 Chat Arena️<br>
95
+ Prompting multiple AI agents to play games in a language-driven environment.
96
+ [Chat Arena Homepage](https://github.com/chatarena/chatarena)""", elem_id="header")
97
+
98
+ with gr.Row():
99
+ env_selector = gr.Dropdown(choices=list(ENV_REGISTRY.keys()), value=DEFAULT_ENV, interactive=True,
100
+ label="Environment Type", show_label=True)
101
+ example_selector = gr.Dropdown(choices=list(EXAMPLE_REGISTRY.keys()), interactive=True,
102
+ label="Select Example", show_label=True)
103
+
104
+ # Environment configuration
105
+ env_desc_textbox = gr.Textbox(show_label=True, lines=2, visible=True, label="Environment Description",
106
+ placeholder="Enter a description of a scenario or the game rules.")
107
+
108
+ all_components += [env_selector, example_selector, env_desc_textbox]
109
+
110
+ with gr.Row():
111
+ with gr.Column(elem_id="col-chatbox"):
112
+ with gr.Tab("All"):
113
+ chatbot = gr.Chatbot(elem_id="chatbox", visible=True, label="Chat Arena")
114
+
115
+ player_chatbots = []
116
+ for i in range(MAX_NUM_PLAYERS):
117
+ player_name = f"Player {i + 1}"
118
+ with gr.Tab(player_name, visible=(i < DEFAULT_NUM_PLAYERS)):
119
+ player_chatbot = gr.Chatbot(elem_id=f"chatbox-{i}", visible=i < DEFAULT_NUM_PLAYERS,
120
+ label=player_name)
121
+ player_chatbots.append(player_chatbot)
122
+
123
+ all_components += [chatbot, *player_chatbots]
124
+
125
+ with gr.Column(elem_id="col-config"): # Player Configuration
126
+ # gr.Markdown("Player Configuration")
127
+ parallel_checkbox = gr.Checkbox(label="Parallel Actions", value=False, visible=True)
128
+ with gr.Accordion("Moderator", open=False, visible=True):
129
+ moderator_components = get_moderator_components(True)
130
+ all_components += [parallel_checkbox, *moderator_components]
131
+
132
+ all_players_components, players_idx2comp = [], {}
133
+ with gr.Blocks():
134
+ num_player_slider = gr.Slider(2, MAX_NUM_PLAYERS, value=DEFAULT_NUM_PLAYERS, step=1,
135
+ label="Number of players:")
136
+ for i in range(MAX_NUM_PLAYERS):
137
+ player_name = f"Player {i + 1}"
138
+ with gr.Tab(player_name, visible=(i < DEFAULT_NUM_PLAYERS)) as tab:
139
+ player_comps = get_player_components(player_name, visible=(i < DEFAULT_NUM_PLAYERS))
140
+
141
+ players_idx2comp[i] = player_comps + [tab]
142
+ all_players_components += player_comps + [tab]
143
+
144
+ all_components += [num_player_slider] + all_players_components
145
+
146
+
147
+ def variable_players(k):
148
+ k = int(k)
149
+ update_dict = {}
150
+ for i in range(MAX_NUM_PLAYERS):
151
+ if i < k:
152
+ for comp in players_idx2comp[i]:
153
+ update_dict[comp] = gr.update(visible=True)
154
+ update_dict[player_chatbots[i]] = gr.update(visible=True)
155
+ else:
156
+ for comp in players_idx2comp[i]:
157
+ update_dict[comp] = gr.update(visible=False)
158
+ update_dict[player_chatbots[i]] = gr.update(visible=False)
159
+ return update_dict
160
+
161
+
162
+ num_player_slider.change(variable_players, num_player_slider, all_players_components + player_chatbots)
163
+
164
+ human_input_textbox = gr.Textbox(show_label=True, label="Human Input", lines=1, visible=True,
165
+ interactive=True, placeholder="Enter your input here")
166
+ with gr.Row():
167
+ btn_step = gr.Button("Start")
168
+ btn_restart = gr.Button("Clear")
169
+
170
+ all_components += [human_input_textbox, btn_step, btn_restart]
171
+
172
+
173
+ def _convert_to_chatbot_output(all_messages, display_recv=False):
174
+ chatbot_output = []
175
+ for i, message in enumerate(all_messages):
176
+ agent_name, msg, recv = message.agent_name, message.content, str(message.visible_to)
177
+ new_msg = re.sub(r'\n+', '<br>', msg.strip()) # Preprocess message for chatbot output
178
+ if display_recv:
179
+ new_msg = f"**{agent_name} (-> {recv})**: {new_msg}" # Add role to the message
180
+ else:
181
+ new_msg = f"**{agent_name}**: {new_msg}"
182
+
183
+ if agent_name == "Moderator":
184
+ chatbot_output.append((new_msg, None))
185
+ else:
186
+ chatbot_output.append((None, new_msg))
187
+ return chatbot_output
188
+
189
+
190
+ def _create_arena_config_from_components(all_comps: dict) -> ArenaConfig:
191
+ env_desc = all_comps[env_desc_textbox]
192
+
193
+ # Initialize the players
194
+ num_players = all_comps[num_player_slider]
195
+ player_configs = []
196
+ for i in range(num_players):
197
+ player_name = f"Player {i + 1}"
198
+ role_desc, backend_type, temperature, max_tokens = [
199
+ all_comps[c] for c in players_idx2comp[i] if not isinstance(c, (gr.Accordion, gr.Tab))]
200
+ player_config = {
201
+ "name": player_name,
202
+ "role_desc": role_desc,
203
+ "env_desc": env_desc,
204
+ "backend": {
205
+ "backend_type": backend_type,
206
+ "temperature": temperature,
207
+ "max_tokens": max_tokens
208
+ }
209
+ }
210
+ player_configs.append(player_config)
211
+
212
+ # Initialize the environment
213
+ env_type = all_comps[env_selector]
214
+ # Get moderator config
215
+ mod_role_desc, mod_terminal_condition, moderator_backend_type, mod_temp, mod_max_tokens = [
216
+ all_comps[c] for c in moderator_components if not isinstance(c, (gr.Accordion, gr.Tab))]
217
+ moderator_config = {
218
+ "role_desc": mod_role_desc,
219
+ "env_desc": env_desc,
220
+ "terminal_condition": mod_terminal_condition,
221
+ "backend": {
222
+ "backend_type": moderator_backend_type,
223
+ "temperature": mod_temp,
224
+ "max_tokens": mod_max_tokens
225
+ }
226
+ }
227
+ env_config = {
228
+ "env_type": env_type,
229
+ "env_desc": env_desc,
230
+ "parallel": all_comps[parallel_checkbox],
231
+ "moderator": moderator_config,
232
+ "moderator_visibility": "all",
233
+ "moderator_period": "turn"
234
+ }
235
+
236
+ # arena_config = {"players": player_configs, "environment": env_config}
237
+ arena_config = ArenaConfig(players=player_configs, environment=env_config)
238
+ return arena_config
239
+
240
+
241
+ def step_game(all_comps: dict):
242
+ yield {btn_step: gr.update(value="Running...", interactive=False),
243
+ btn_restart: gr.update(interactive=False)}
244
+
245
+ cur_state = all_comps[state]
246
+
247
+ # If arena is not yet created, create it
248
+ if cur_state["arena"] is None:
249
+ # Create the Arena
250
+ arena_config = _create_arena_config_from_components(all_comps)
251
+ arena = Arena.from_config(arena_config)
252
+ log_arena(arena, database=DB)
253
+ cur_state["arena"] = arena
254
+ else:
255
+ arena = cur_state["arena"]
256
+
257
+ try:
258
+ timestep = arena.step()
259
+ except HumanBackendError as e:
260
+ # Handle human input and recover with the game update
261
+ human_input = all_comps[human_input_textbox]
262
+ if human_input == "":
263
+ timestep = None # Failed to get human input
264
+ else:
265
+ timestep = arena.environment.step(e.agent_name, human_input)
266
+
267
+ if timestep is None:
268
+ yield {human_input_textbox: gr.update(value="", placeholder="Please enter a valid input"),
269
+ btn_step: gr.update(value="Next Step", interactive=True),
270
+ btn_restart: gr.update(interactive=True)}
271
+ else:
272
+ all_messages = timestep.observation # user sees what the moderator sees
273
+ log_messages(arena, all_messages, database=DB)
274
+
275
+ chatbot_output = _convert_to_chatbot_output(all_messages, display_recv=True)
276
+ update_dict = {human_input_textbox: gr.Textbox.update(value=""),
277
+ chatbot: chatbot_output,
278
+ btn_step: gr.update(value="Next Step", interactive=not timestep.terminal),
279
+ btn_restart: gr.update(interactive=True), state: cur_state}
280
+ # Get the visible messages for each player
281
+ for i, player in enumerate(arena.players):
282
+ player_messages = arena.environment.get_observation(player.name)
283
+ player_output = _convert_to_chatbot_output(player_messages)
284
+ # Update the player's chatbot output
285
+ update_dict[player_chatbots[i]] = player_output
286
+
287
+ if DEBUG:
288
+ arena.environment.print()
289
+
290
+ yield update_dict
291
+
292
+
293
+ def restart_game(all_comps: dict):
294
+ cur_state = all_comps[state]
295
+ cur_state["arena"] = None
296
+ yield {chatbot: [], btn_restart: gr.update(interactive=False),
297
+ btn_step: gr.update(interactive=False), state: cur_state}
298
+
299
+ arena_config = _create_arena_config_from_components(all_comps)
300
+ arena = Arena.from_config(arena_config)
301
+ log_arena(arena, database=DB)
302
+ cur_state["arena"] = arena
303
+
304
+ yield {btn_step: gr.update(value="Start", interactive=True),
305
+ btn_restart: gr.update(interactive=True), state: cur_state}
306
+
307
+
308
+ # Remove Accordion and Tab from the list of components
309
+ all_components = [comp for comp in all_components if not isinstance(comp, (gr.Accordion, gr.Tab))]
310
+
311
+ # If any of the Textbox, Slider, Checkbox, Dropdown, RadioButtons is changed, the Step button is disabled
312
+ for comp in all_components:
313
+ def _disable_step_button(state):
314
+ if state["arena"] is not None:
315
+ return gr.update(interactive=False)
316
+ else:
317
+ return gr.update()
318
+
319
+
320
+ if isinstance(comp,
321
+ (gr.Textbox, gr.Slider, gr.Checkbox, gr.Dropdown, gr.Radio)) and comp is not human_input_textbox:
322
+ comp.change(_disable_step_button, state, btn_step)
323
+
324
+ btn_step.click(step_game, set(all_components + [state]),
325
+ [chatbot, *player_chatbots, btn_step, btn_restart, state, human_input_textbox])
326
+ btn_restart.click(restart_game, set(all_components + [state]),
327
+ [chatbot, *player_chatbots, btn_step, btn_restart, state, human_input_textbox])
328
+
329
+
330
+ # If an example is selected, update the components
331
+ def update_components_from_example(all_comps: dict):
332
+ example_name = all_comps[example_selector]
333
+ example_config = EXAMPLE_REGISTRY[example_name]
334
+ update_dict = {}
335
+
336
+ # Update the environment components
337
+ env_config = example_config['environment']
338
+ update_dict[env_desc_textbox] = gr.update(value=example_config['global_prompt'])
339
+ update_dict[env_selector] = gr.update(value=env_config['env_type'])
340
+ update_dict[parallel_checkbox] = gr.update(value=env_config['parallel'])
341
+
342
+ # Update the moderator components
343
+ if "moderator" in env_config:
344
+ mod_role_desc, mod_terminal_condition, moderator_backend_type, mod_temp, mod_max_tokens = [
345
+ c for c in moderator_components if not isinstance(c, (gr.Accordion, gr.Tab))
346
+ ]
347
+ update_dict[mod_role_desc] = gr.update(value=env_config['moderator']['role_desc'])
348
+ update_dict[mod_terminal_condition] = gr.update(value=env_config['moderator']['terminal_condition'])
349
+ update_dict[moderator_backend_type] = gr.update(value=env_config['moderator']['backend']['backend_type'])
350
+ update_dict[mod_temp] = gr.update(value=env_config['moderator']['backend']['temperature'])
351
+ update_dict[mod_max_tokens] = gr.update(value=env_config['moderator']['backend']['max_tokens'])
352
+
353
+ # Update the player components
354
+ update_dict[num_player_slider] = gr.update(value=len(example_config['players']))
355
+ for i, player_config in enumerate(example_config['players']):
356
+ role_desc, backend_type, temperature, max_tokens = [
357
+ c for c in players_idx2comp[i] if not isinstance(c, (gr.Accordion, gr.Tab))
358
+ ]
359
+ update_dict[role_desc] = gr.update(value=player_config['role_desc'])
360
+ update_dict[backend_type] = gr.update(value=player_config['backend']['backend_type'])
361
+ update_dict[temperature] = gr.update(value=player_config['backend']['temperature'])
362
+ update_dict[max_tokens] = gr.update(value=player_config['backend']['max_tokens'])
363
+
364
+ return update_dict
365
+
366
+
367
+ example_selector.change(update_components_from_example, set(all_components + [state]), all_components + [state])
368
+
369
+ demo.queue()
370
+ demo.launch(debug=DEBUG)
examples/chameleon.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "Chameleon",
3
+ "global_prompt": "You are playing a game of the Chameleon. Here are the game rules:\n\n## Information and roles\nThere are two roles in the game, chameleon and non-chameleon.\nThe topic of the secret word will be first revealed to all the players.\nThen the secret word will be revealed to non-chameleons.\nThe chameleon does not know the secret word.\n\n## Objectives\nYour objective in the game depends on you role:\n- If you are not a chameleon, your goal is to reveal the chameleon without exposing the secret word.\n- If you are a chameleon, your aim is to blend in with other players, avoid being caught, and figure out the secret word.\n\n## Stages\nThere are three stages in the game:\n1. The giving clues stage: each player will describe the clues about the secret word.\n2. The accusation stage: In this stage, each player will vote for another player who is most likely the chameleon. The chameleon should vote for other players.\n3. The guess stage: If the accusation is correct, the chameleon should guess the secret word given the clues revealed by other players.",
4
+ "environment": {
5
+ "env_type": "chameleon",
6
+ "parallel": false
7
+ },
8
+ "players": [
9
+ {
10
+ "name": "Player 1",
11
+ "role_desc": "You are Player 1.\nThe Moderator will tell you whether you are the chameleon.\nYou're playing with two other players.\nDo not pretend you are other players or the moderator.\nYou cannot vote for yourself.\nYou don't need to prepend your player name to your response, despite others may do it.\nAlways end your response with <EOS>.",
12
+ "backend": {
13
+ "backend_type": "openai-chat",
14
+ "temperature": 0.7,
15
+ "max_tokens": 50
16
+ }
17
+ },
18
+ {
19
+ "name": "Player 2",
20
+ "role_desc": "You are Player 2.\nThe Moderator will tell you whether you are the chameleon.\nYou're playing with two other players.\nDo not pretend you are other players or the moderator.\nYou cannot vote for yourself.\nYou don't need to prepend your player name to your response, despite others may do it.\nAlways end your response with <EOS>.",
21
+ "backend": {
22
+ "backend_type": "openai-chat",
23
+ "temperature": 0.7,
24
+ "max_tokens": 50
25
+ }
26
+ },
27
+ {
28
+ "name": "Player 3",
29
+ "role_desc": "You are Player 3.\nThe Moderator will tell you whether you are the chameleon.\nYou're playing with two other players.\nDo not pretend you are other players or the moderator.\nYou cannot vote for yourself.\nYou don't need to prepend your player name to your response, despite others may do it.\nAlways end your response with <EOS>.",
30
+ "backend": {
31
+ "backend_type": "openai-chat",
32
+ "temperature": 0.7,
33
+ "max_tokens": 50
34
+ }
35
+ }
36
+ ]
37
+ }
examples/chess.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "chess",
3
+ "global_prompt": "",
4
+ "environment": {
5
+ "env_type": "pettingzoo:chess",
6
+ "parallel": false
7
+ },
8
+ "players": [
9
+ {
10
+ "name": "Player 1",
11
+ "role_desc": "You are playing chess, you are playing white. Only output the starting and ending position of the chess piece.\nThe format is \"Move (x1, y1) to (x2, y2)\". The bottom left corner piece has a position (0, 0)\n\nFor example:\n\n```\nMove (4, 1) to (4, 3) <EOS>\n\n```",
12
+ "backend": {
13
+ "backend_type": "openai-chat",
14
+ "temperature": 0.7,
15
+ "max_tokens": 50
16
+ }
17
+ },
18
+ {
19
+ "name": "Player 2",
20
+ "role_desc": "You are playing chess. You are playing black pieces. Only output the starting and ending position of the chess piece.\nThe format is \"Move (x1, y1) to (x2, y2)\". The bottom left corner piece has a position (0, 0)\n\nFor example:\n\n```\nMove (4, 6) to (4, 4) <EOS>\n```",
21
+ "backend": {
22
+ "backend_type": "openai-chat",
23
+ "temperature": 0.7,
24
+ "max_tokens": 50
25
+ }
26
+ }
27
+ ]
28
+ }
examples/nlp-classroom-3players.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "NLP Classroom 3 Players",
3
+ "global_prompt": "You are in a university classroom and it is Natural Language Processing module. You start by introducing themselves. Your answer will end with <EOS>.",
4
+ "environment": {
5
+ "env_type": "conversation",
6
+ "parallel": false
7
+ },
8
+ "players": [
9
+ {
10
+ "name": "Professor",
11
+ "role_desc": "You are Prof. Alpha, a knowledgeable professor in NLP. Your answer will concise and accurate. The answers should be less than 100 words.",
12
+ "backend": {
13
+ "backend_type": "openai-chat",
14
+ "temperature": 0.7,
15
+ "max_tokens": 250
16
+ }
17
+ },
18
+ {
19
+ "name": "Student",
20
+ "role_desc": "You are Beta, a student curious about Natural Language Processing and you want to learn some basic concepts of NLP. You know nothing about the area so you will ask lots of questions.",
21
+ "backend": {
22
+ "backend_type": "openai-chat",
23
+ "temperature": 0.7,
24
+ "max_tokens": 100
25
+ }
26
+ },
27
+ {
28
+ "name": "Teaching Assistant",
29
+ "role_desc": "You are Gamma, a teaching assistant of the Natural Language Processing module. You mostly help with logistics and marking, but occasionally handles questions. Your answer should be less than 100 words.",
30
+ "backend": {
31
+ "backend_type": "openai-chat",
32
+ "temperature": 0.7,
33
+ "max_tokens": 250
34
+ }
35
+ }
36
+ ]
37
+ }
examples/nlp-classroom.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "NLP Classroom",
3
+ "global_prompt": "You are in a university classroom and it is Natural Language Processing module. You start by introducing themselves. Your answer will end with <EOS>.",
4
+ "environment": {
5
+ "env_type": "conversation",
6
+ "parallel": false
7
+ },
8
+ "players": [
9
+ {
10
+ "name": "Professor",
11
+ "role_desc": "You are Prof. Alice, a knowledgeable professor in NLP. Your answer will concise and accurate. The answers should be less than 100 words.",
12
+ "backend": {
13
+ "backend_type": "openai-chat",
14
+ "temperature": 0.7,
15
+ "max_tokens": 250
16
+ }
17
+ },
18
+ {
19
+ "name": "Student",
20
+ "role_desc": "You are Bob, a student curious about Natural Language Processing and you want to learn some basic concepts of NLP. You know nothing about the area so you will ask lots of questions.",
21
+ "backend": {
22
+ "backend_type": "openai-chat",
23
+ "temperature": 0.7,
24
+ "max_tokens": 100
25
+ }
26
+ }
27
+ ]
28
+ }
examples/rock-paper-scissors.json ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "Rock-Paper-Scissors",
3
+ "global_prompt": "Rock Paper Scissors is a two-player hand game where players use hand signals to represent three possible outcomes: rock, paper, or scissors. \n\nThe rules of the game are simple:\n\n1. Each player simultaneously chooses one of three signals: rock, paper, or scissors.\n\n2. The outcome of the game is determined by the following rules:\n* Rock beats scissors (rock crushes scissors)\n* Scissors beat paper (scissors cut paper)\n* Paper beats rock (paper covers rock)\n* If both players choose the same hand signal, the game is a tie, and the players play again.\n\n3. The winner of each round is determined by comparing the chosen signals. The first player to win 2 rounds wins the game.",
4
+ "environment": {
5
+ "env_type": "moderated_conversation",
6
+ "parallel": true,
7
+ "moderator": {
8
+ "role_desc": "You are the system of the game.\nYou should count the number of win rounds of each paper. The player who first wins 2 rounds wins the game.\nYou should also end the game if the players say anything else besides \"rock\", \"paper\" or \"scissors\", especially if they say long sentences.\n\n## Example\nWhen you see:\n```\n[Player 1]: rock\n[Player 2]: rock\n```\nyou should output the following:\n```\nTie.\nPlayer 1 wins: 0/2\nPlayer 2 wins: 0/2\n```\n\nIn the next round, when you see:\n```\n[Player 1]: rock\n[Player 2]: paper\n```\nyou should output the following:\n```\nPlayer 2 wins this round.\nPlayer 1 wins: 0/2\nPlayer 2 wins: 1/2\n```\n\nIn the next round, when you see:\n```\n[Player 1]: paper\n[Player 2]: scissors\n```\nyou should output the following:\n```\nPlayer 2 wins this round.\nPlayer 1 wins: 0/2\nPlayer 2 wins: 2/2\n\nPlayer 2 wins the game!\n```\n\n## Other instructions\nDon't instruct the player to do anything.\nDon't pretend you are a player.\nDon't repeat the players' outputs.",
9
+ "terminal_condition": "The game is over when one player wins 2 rounds. Did someone win 2 rounds?",
10
+ "backend": {
11
+ "backend_type": "openai-chat",
12
+ "temperature": 0.0,
13
+ "max_tokens": 50
14
+ }
15
+ },
16
+ "moderator_visibility": "all",
17
+ "moderator_period": "round"
18
+ },
19
+ "players": [
20
+ {
21
+ "name": "Player 1",
22
+ "role_desc": "Randomly output one of the following texts: \"rock\", \"paper\" or \"scissors\"\nYour choice should be random, don't follow the order of the sequence I gave you.\n\n## Example\nYou should output\n```\npaper<EOS>\n```\nor \n```\nrock<EOS>\n```\nor\n```\nscissors<EOS>\n```\n\n## Other instructions\nDon't output anything besides one of the three strings.\nDon't output the results in the last turn like \"tie\".\nDon't pretend as if you are a human player.",
23
+ "backend": {
24
+ "backend_type": "openai-chat",
25
+ "temperature": 0.7,
26
+ "max_tokens": 10
27
+ }
28
+ },
29
+ {
30
+ "name": "Player 2",
31
+ "role_desc": "Randomly output one of the following texts: \"rock\", \"paper\" or \"scissors\"\nYour choice should be random, don't follow the order of the sequence I gave you.\n\n## Example\nYou should output\n```\npaper<EOS>\n```\nor \n```\nrock<EOS>\n```\nor\n```\nscissors<EOS>\n```\n\n## Other instructions\nDon't output anything besides one of the three strings.\nDon't output the results in the last turn like \"tie\".\nDon't pretend as if you are a human player.",
32
+ "backend": {
33
+ "backend_type": "openai-chat",
34
+ "temperature": 0.7,
35
+ "max_tokens": 10
36
+ }
37
+ }
38
+ ]
39
+ }
examples/tic-tac-toe.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "Tic-Tac-Toe",
3
+ "global_prompt": "",
4
+ "global_prompt_backup": "Two players are playing tic-tac-toe. \nTic-tac-toe is played on a three-by-three grid by two players, who alternately place the marks X and O in one of the nine spaces in the grid. \nThe player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner.\n\nIn the following example, the first player (X) wins the game in seven steps:\n1. [Player 1]: X: (1, 3)\n| _ |_| X |\n| _ | _ |_|\n| _ | _ |_|\n \n2. [Player 2]: O: (1, 1)\n| O | _ | X |\n| _ | _ |_|\n| _ |_| _ |\n\n3. [Player 1]: X: (3, 1)\n| O | _ | X |\n| _ |_| _ |\n| X | _ |_|\n\n4. [Player 2]: O: (2, 2)\n| O | _ | X |\n| _ | O | _ |\n| X | _ |_|\n\n5. [Player 1]: X: (3, 3)\n| O | _ | X |\n| _ | O | _ |\n| X | _ | X |\n\n6. [Player 2]: O: (2, 3)\n| O | _ | X |\n| _ | O |O|\n| X | _ | X |\n\n7. [Player 1]: X: (3, 2)\n| O | _ | X |\n| _ | O |O|\n| X |X| X |\n\n\nX plays first. Players will specify the position of the stone and the moderator will plot the board status.\nIf a position has been marked, future marks cannot be put in the same position.\nOnly the moderator can decide who wins. Players shouldn't declare they win.\nThe players interact with the game by specifying the position of the stones (x, y), where x indicates the row and y indicates the column, so (1, 1) is the top left corner and (3, 3) is the bottom right corner.",
5
+ "environment": {
6
+ "env_type": "moderated_conversation",
7
+ "parallel": false,
8
+ "moderator": {
9
+ "role_desc": "You are the system of the game.\nYou should first recall the latest move and then display the board status.\n\nFor example, when the last player says: \"X: (1, 2)\"\nIt means the X mark is put in the first row and the second column.\nYou'll output:\n```\nBoard:\n| _ | X | _ |\n| _ |_| _ |\n| _ |_| _ |\n```\n\nIn the next step, another player says: \"O: (3, 1)\"\nIt means the O mark is put in the third row and the first column.\nYou'll output:\n```\nBoard:\n| _ |_| X |\n| _ |_| _ |\n| O | _ |_|\n```\n\n## Termination condition\nIf a player succeeds in placing three of their marks in a horizontal, vertical, or diagonal line, it wins. \nThe horizontal line means there are three same marks in the same row (n, 1) (n, 2) (n, 3), where n can be from 1 to 3.\nThe vertical line means there are three same marks in the same column (1, m) (2, m) (3, m), where m can be from 1 to 3.\nThe diagonal line means three same marks occupy one of the following position combinations: (1, 1) (2, 2) (3, 3) or (1, 3) (2, 2) (3, 1)\n\nYou should declare the winner after displaying the board status if a player wins the game in the last move.\nFor example, you should output the following:\n```\nBoard\n| O | _ | X |\n| _ | X | O |\n| X |X| O |\n\nPlayer 1 (X) wins!\n```\nbecause X marks form a diagonal line on the board, so the player who plays X is the winner. The game ends.\n\n\n\n## Other instructions\nDon't write code.\nDon't instruct the player to do anything.\nDon't output \"Moderator\".",
10
+ "terminal_condition": "If a player wins, the game ends immediately. Is the game ended? Answer yes or no?",
11
+ "backend": {
12
+ "backend_type": "openai-chat",
13
+ "temperature": 0.0,
14
+ "max_tokens": 50
15
+ }
16
+ },
17
+ "moderator_visibility": "all",
18
+ "moderator_period": "turn"
19
+ },
20
+ "players": [
21
+ {
22
+ "name": "Player 1",
23
+ "role_desc": "You play X.\nYou should only output X and the position of the move, for example: \"X: (1, 3)<EOS>\"\nThe position you put the mark on must be empty.\n\nYou shouldn't act as a moderator.\nDo not output \"Moderator\" and the board status.\nDon't say anything besides mark position.",
24
+ "backend": {
25
+ "backend_type": "openai-chat",
26
+ "temperature": 0.7,
27
+ "max_tokens": 15
28
+ }
29
+ },
30
+ {
31
+ "name": "Player 2",
32
+ "role_desc": "You play O.\nYou should only output O and the position of the move, for example: \"O: (2, 3)<EOS>\"\nThe position you put the mark on must be empty.\n\nYou shouldn't act as a moderator.\nDo not output \"Moderator\" and the board status.\nDon't say anything besides mark position.",
33
+ "backend": {
34
+ "backend_type": "openai-chat",
35
+ "temperature": 0.7,
36
+ "max_tokens": 15
37
+ }
38
+ }
39
+ ]
40
+ }
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ cohere>=4.1.0
2
+ openai>=0.27.2
3
+ gradio>=3.20.0
4
+ transformers>=4.0
5
+ tenacity==8.2.2
6
+ rich>=13.3.1
7
+ prompt_toolkit>=3.0
8
+ pettingzoo==1.22.3
9
+ chess