Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added docker support #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,28 @@ You may have noticed that all character sprites in the replay look identical. We
To start the demo, go to the following address on your browser: `http://localhost:8000/demo/<simulation-name>/<starting-time-step>/<simulation-speed>`. Note that `<simulation-name>` and `<starting-time-step>` denote the same things as mentioned above. `<simulation-speed>` can be set to control the demo speed, where 1 is the slowest, and 5 is the fastest. For instance, visiting the following link will start a pre-simulated example, beginning at time-step 1, with a medium demo speed:
[http://localhost:8000/demo/July1_the_ville_isabella_maria_klaus-step-3-20/1/3/](http://localhost:8000/demo/July1_the_ville_isabella_maria_klaus-step-3-20/1/3/)

### Docker
Alternatively, it is possible to run the environment server and the simulation server using Docker. To do this, first make sure that you have Docker installed on your machine. Then, run the following command to build the Docker image:

docker build -f docker/Dockerfile -t generative_agents .

Then, run the following command to start the Docker container. You will be presented with the same prompt as in Step 3 after running `python reverie.py`:

docker run -it -p 8000:8000 -e OPENAI_API_KEY=<OPENAI_API_KEY> -e OPENAI_API_NAME=<OPENAI_API_NAME> -v $(pwd)/environment:/app/environment generative_agents

Note that you will need to replace `<OPENAI_API_KEY>` and `<OPENAI_API_NAME>` with your OpenAI API key and API key name, respectively.

You can then access the environment server at [http://localhost:8000]. You can customise host and port for the simulation server through `DJANGO_HOST` and `DJANGO_PORT` environment variables:

# the server will be located at localhost:9000
# note that we need to set the host to 0.0.0.0 inside the container so that it will be correctly visible from the outside
docker run -it -p 9000:9000 \
-e OPENAI_API_KEY=<OPENAI_API_KEY> \
-e OPENAI_API_NAME=<OPENAI_API_NAME> \
-e DJANGO_HOST=0.0.0.0 \
-e DJANGO_PORT=9000 \
-v $(pwd)/environment:/app/environment generative_agents

### Tips
We've noticed that OpenAI's API can hang when it reaches the hourly rate limit. When this happens, you may need to restart your simulation. For now, we recommend saving your simulation often as you progress to ensure that you lose as little of the simulation as possible when you do need to stop and rerun it. Running these simulations, at least as of early 2023, could be somewhat costly, especially when there are many agents in the environment.

Expand Down
12 changes: 12 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.10


WORKDIR /app

COPY docker/entrypoint.sh /entrypoint.sh
COPY requirements.txt requirements.txt
COPY reverie reverie

RUN pip install -r requirements.txt

ENTRYPOINT ["/entrypoint.sh"]
29 changes: 29 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -e

HOST="${DJANGO_HOST:-"0.0.0.0"}"
PORT="${DJANGO_PORT:-"8000"}"

cat > /app/reverie/backend_server/utils.py << EOF
# Copy and paste your OpenAI API Key
openai_api_key = "$OPENAI_API_KEY"
# Put your name
key_owner = "$OPENAI_API_NAME"

maze_assets_loc = "../../environment/frontend_server/static_dirs/assets"
env_matrix = f"{maze_assets_loc}/the_ville/matrix"
env_visuals = f"{maze_assets_loc}/the_ville/visuals"

fs_storage = "../../environment/frontend_server/storage"
fs_temp_storage = "../../environment/frontend_server/temp_storage"

collision_block_id = "32125"

# Verbose
debug = True
EOF

cd /app/environment/frontend_server && python manage.py runserver $HOST:$PORT > /app/server_logs.txt 2>&1 &
sleep 5

cd /app/reverie/backend_server && python reverie.py