$git clone https://github.com/HumanCompatibleAI/tensor-trustThis is the source code for the Tensor Trust web game and data cleaning pipeline. See the paper website for more details on the project. You can also use the data, or [go play the game!](htt
| 1 | # Tensor Trust |
| 2 | |
| 3 | ## A prompt injection attack game to collect data for adversarial ML research |
| 4 | |
| 5 | This is the source code for the Tensor Trust web game and data cleaning pipeline. See the [paper website](https://tensortrust.ai/paper) for more details on the project. You can also [use the data](https://github.com/HumanCompatibleAI/tensor-trust-data), or [go play the game!](https://tensortrust.ai/) |
| 6 | |
| 7 | If you build on our code or data in an academic publication, please cite us with the following BibTeX: |
| 8 | |
| 9 | ```bibtex |
| 10 | @misc{toyer2023tensor, |
| 11 | title={{Tensor Trust}: Interpretable Prompt Injection Attacks from an Online Game}, |
| 12 | author={Toyer, Sam and Watkins, Olivia and Mendes, Ethan Adrian and Svegliato, Justin and Bailey, Luke and Wang, Tiffany and Ong, Isaac and Elmaaroufi, Karim and Abbeel, Pieter and Darrell, Trevor and Ritter, Alan and Russell, Stuart}, |
| 13 | year={2023}, |
| 14 | journal={arXiv preprint arXiv:2311.01011}, |
| 15 | url={https://arxiv.org/pdf/2311.01011.pdf} |
| 16 | } |
| 17 | ``` |
| 18 | |
| 19 | ### Installation |
| 20 | |
| 21 | To install and run, first set up OpenAI API key if you have not already: |
| 22 | |
| 23 | 1. Login to OpenAI account and go to `https://platform.openai.com/account/api-keys`. |
| 24 | 2. Create an API key. |
| 25 | 3. Now open a shell: on Windows run `set OPENAI_API_KEY=<your-key>`, and on Unix run `export OPENAI_API_KEY=<your-key>`. |
| 26 | |
| 27 | Now run the following: |
| 28 | |
| 29 | ```bash |
| 30 | # Install Redis on Ubuntu. For other OSes see: |
| 31 | # https://redis.io/docs/getting-started/installation/ |
| 32 | sudo apt install redis |
| 33 | # If this command fails, try running `redis-server` directly |
| 34 | sudo systemctl enable redis-server \ |
| 35 | && sudo systemctl restart redis-server |
| 36 | # Install node.js on Ubuntu. For other OSes see: |
| 37 | # https://nodejs.org/en/download |
| 38 | # If this command doesn't work, try installing using nvm. See |
| 39 | # https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04#option-3-installing-node-using-the-node-version-manager |
| 40 | sudo snap install node --classic |
| 41 | |
| 42 | # setup: |
| 43 | conda create -n promptgame python=3.10 |
| 44 | conda activate promptgame |
| 45 | pip install -e '.[dev]' |
| 46 | |
| 47 | ./manage.py tailwind install # install JS modules for Tailwind |
| 48 | ./manage.py migrate # set up database |
| 49 | |
| 50 | # For testing, we need two commands. |
| 51 | # Run this first command in one terminal to update the stylesheet in response to Tailwind changes: |
| 52 | ./manage.py tailwind start |
| 53 | |
| 54 | # Now run this second command in another terminal to a Django server |
| 55 | ./manage.py runserver # run demo server (will auto-restart when you edit files) |
| 56 | ``` |
| 57 | |
| 58 | Now you can visit a development copy of the website at |
| 59 | [http://localhost:8000/](http://localhost:8000/). |
| 60 | |
| 61 | ### Database Management |
| 62 | |
| 63 | Django handles database management with `Models`, which we define in `src/promptgame/gameui/models.py`. Whenever |
| 64 | you edit a `Model`, you need the change to be reflected in the underlying database that |
| 65 | Django is managing. To do this, run: |
| 66 | |
| 67 | ```bash |
| 68 | ./manage.py makemigrations |
| 69 | |
| 70 | ./manage.py migrate |
| 71 | ``` |
| 72 | |
| 73 | In git terms, `makemigrations` is like creating a commit recording your change to the database. This migration |
| 74 | is actually tracked within a file in the `src/promptgame/migrations` directory. Running `migrate` is like |
| 75 | pushing this commit, and thus actually updates the database. To find out more about this process (including |
| 76 | how to do more complex behavior such as revert your database back to a previous migration state), click |
| 77 | [here](https://docs.djangoproject.com/en/4.2/topics/migrations/). |
| 78 | |
| 79 | Note that if you are pulling from `main` after someone has made a change to a model, you will also have to run `./manage.py migrate` to apply the new migrations generated by the other person. |
| 80 | |
| 81 | ### Creating an admin account |
| 82 | |
| 83 | To create an admin account, run: |
| 84 | |
| 85 | ```bash |
| 86 | ./manage.py createsuperuser |
| 87 | ``` |
| 88 | |
| 89 | Follow the prompts to create a username and password. |
| 90 | |
| 91 | |
| 92 | ### Viewing the admin interface |
| 93 | |
| 94 | Log in to the admin page at [localhost:8000/private/dj-login/](http://localhost:8000/private/dj-login/). |
| 95 | On the prod site, this will be at [tensortrust.ai/private/dj-login/](https://tensortrust.ai/private/dj-login/). |
| 96 | |
| 97 | Enter the use |