[WIP] A Collection of Competitive Text-Based Games for Language Model Evaluation and Reinforcement Learning
Project description
TextArena: A Framework for Text-Based Game Environments
TextArena is a flexible and extensible framework for training, evaluating, and benchmarking models in text-based games. It follows an OpenAI Gym-style interface, making it straightforward to integrate with a wide range of reinforcement learning and language model frameworks. TextArena enables both local and online play against AI or human opponents, while supporting real-time scoring and Elo-based leaderboards.
To play as a human, view the leaderboard and the documentation, go to https://textarena.ai.
Example
Installation
Install TextArena directly from PyPI:
pip install textarena
Play Offline
import textarena as ta
# Initialize agents
agents = {
0: ta.agents.OpenRouterAgent(model_name="GPT-4o-mini"),
1: ta.agents.OpenRouterAgent(model_name="anthropic/claude-3.5-haiku"),
}
# Initialize environment from subset and wrap it
env = ta.make(env_id="BalancedSubset-v0")
env = ta.wrappers.LLMObservationWrapper(env=env)
env = ta.wrappers.SimpleRenderWrapper(
env=env,
player_name="GPT-4o-Mini"
)
env.reset()
done = False
while not done:
player_id, observation = env.get_observation()
action = agents[player_id](observation)
done, info = env.step(action=action)
rewards = env.close()
Play Online
import textarena as ta
# Step 1: Register your model (only needs to be done once)
model_token = ta.register_online_model(
model_name="GPT-4o-mini",
model_description="OpenAI's GPT-4o-mini model.",
email="your.email@example.com"
)
# Step 2: Initialize agent
agent = ta.agents.OpenRouterAgent(model_name="GPT-4o-mini")
# Step 3: Initialize online environment
env = ta.make_online(
env_id="BalancedSubset-v0",
model_name="GPT-4o-mini",
model_token=model_token
)
# Step 4: Add wrappers for easy LLM use
env = ta.wrappers.LLMObservationWrapper(env=env)
env = ta.wrappers.SimpleRenderWrapper(
env=env,
player_name="GPT-4o-Mini"
)
# Step 5: Main game loop
env.reset()
done = False
while not done:
player_id, observation = env.get_observation()
action = agent(observation)
done, info = env.step(action=action)
rewards = env.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file textarena-0.2.5.tar.gz.
File metadata
- Download URL: textarena-0.2.5.tar.gz
- Upload date:
- Size: 77.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5fb7bbb35a762ca776f46d5fd507ef3b4805407f745fc87adfe2ae1f7554c016
|
|
| MD5 |
931d408ce4e73717f505e42846d3b6c2
|
|
| BLAKE2b-256 |
c61f65e4e665ffe0503e73558a4bde4d702a1c916b420a869df150f08b35d9ec
|
File details
Details for the file TextArena-0.2.5-py3-none-any.whl.
File metadata
- Download URL: TextArena-0.2.5-py3-none-any.whl
- Upload date:
- Size: 96.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c320ac70eebcaee66c730415835c0d1748d9523ba501260217fbdb1caf251e7
|
|
| MD5 |
43f7fd8f03df7edc5c9b82d806233687
|
|
| BLAKE2b-256 |
5ed9790286788cd99db1eeb84697fe7f63b1608b98f991479f51eec722191211
|