from chatarena.agent import Player
from chatarena.backends import OpenAIChat
# Describe the environment (which is shared by all players)
environment_description = "It is in a university classroom ..."
# A "Professor" player
player1 = Player(name="Professor", backend=OpenAIChat(),
role_desc="You are a professor in ...",
global_prompt=environment_description)
# A "Student" player
player2 = Player(name="Student", backend=OpenAIChat(),
role_desc="You are a student who is interested in ...",
global_prompt=environment_description)
# A "Teaching Assistant" player
player3 = Player(name="Teaching assistant", backend=OpenAIChat(),
role_desc="You are a teaching assistant of the module ...",
global_prompt=environment_description)
You can also create a language model-driven environment and add it to the ChatArena:
from chatarena.environments.conversation import Conversation
env = Conversation(player_names=[p.name for p in [player1, player2, player3]])
Arena
is a utility class to help you run language games:
from chatarena.arena import Arena
arena = Arena(players=[player1, player2, player3],
environment=env, global_prompt=environment_description)
# Run the game for 10 steps
arena.run(num_steps=10)
# Alternatively, you can run your own main loop
for _ in range(10):
arena.step()
# Your code goes here ...
You can easily save your gameplay history to file:
arena.save_history(path=...)
and save your game config to file:
arena.save_config(path=...)