This is a continuation of nraw’s project to automatically create
AI-generated newspapers based on HTML-templating and the utilization
of OpenAI’s API. It has been used by me in a number of games and I
have made iterative improvements based on the input of the other
players. These include, but are not limited to;
- A title based on the headlines of the articles.
- Improvements to the phrasing of the AI.
- The removal of the tedious summaries.
- News based on real life events that occur outside of Europe on the
given season.
- These can sometimes run into issues, such as spring 1914 often times resulting in reports on the beginnings of WW1, after players have already been fighting for 14 years.
- More realistic news articles, with comments made by people involved.
- The ability for players to login and issue comments on the situation that then turns into in-universe articles (plausible deniability on phrasing!).
The project was originally intended just to be used for students of class TE21D at the Stockholm Science & Innovation School (SSIS), but work is slowly being done to improve portability and deployability. For now this is what you can do:
- Set the
OPENAI_API_KEYenvironment variable. - Set the url of your backstabbr game in
get_backstabbr.py.
The program is run by executing the main.py file which then generates
the appropriate pictures in ./assets and the index.hmtl. These as well
as the style.css file should be pushed to a server where they can then
be viewed.
To allow players to issue declarations or comment on geopolitical
affairs through the newspaper, change the passwords in users.json,
distribute the credentials to your players and run run the app.py
script using a WSGI server like gunicorn. The data.json file is
intended to be purged between each turn so that only powers that
actually want to say something are included in the next issue.
The major dependency is on selenium and through it Mozilla Firefox or a geckodriver compatible browser. Other dependencies are:
tqdmjinja2flaskandflask-login(for the commentaries)
There is a timer between each call to the OpenAI API. This is because
the number of units performing orders of interest later on in the game
triggers OpenAI’s rate-limiter. Personally I find this unnecessary on
OpenAI’s part since they have an underlying rate-limiter in the price
of the API service. If you want to improve the speed at which it is
run (To test things out perhaps?) simply remove the time.sleep(1) code
on line 31 in ping_gpt.py.
Have fun!