Skip to main content

[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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

textarena-0.2.7.tar.gz (76.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

TextArena-0.2.7-py3-none-any.whl (96.4 kB view details)

Uploaded Python 3

File details

Details for the file textarena-0.2.7.tar.gz.

File metadata

  • Download URL: textarena-0.2.7.tar.gz
  • Upload date:
  • Size: 76.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for textarena-0.2.7.tar.gz
Algorithm Hash digest
SHA256 ee5c0a7665dcbe33926beb57c2a7a6df4d6e88c86ed2a1e223afa29cf0190ff1
MD5 9577152e12e61e6d915a50fb1ddd5c3c
BLAKE2b-256 b8385d57a8a5d21f67b2b940cd6f4047cace1a1bc65089350817c0b85d85d0c6

See more details on using hashes here.

File details

Details for the file TextArena-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: TextArena-0.2.7-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

Hashes for TextArena-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 17a1d2cd0711b402e136aaadfa7898213f1a4816205ddfc4e933ea22cf4e0e75
MD5 329716d750865b6ac77134da9e499128
BLAKE2b-256 5e684b7be85538780479312194bb1ce5e5125648a34763a5a14e72e27af99310

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page