Experiments in semi-autonomous worldbuilding
Executive Overview
This experiment will be in generating worldbuilding related elements and using a semi-automous GPT3.5-turbo agent to iterate and create scenarios and fantasy races.
This is a personal project based on the much more important Reinforcement Learning with Heuristic Imperatives (RLHI) project by @daveshap, which you can find here: https://github.com/daveshap/RLHI
Technical Overview
This project consists of two Python scripts, 1_race_gen.py
and 2_action.py
, which use the OpenAI GPT-3 API to generate scenarios and actions for worldbuilding.
1_race_gen.py
The 1_race_gen.py
script generates a set of scenarios based on predefined lists of words for various attributes such as society, geography, economics, religion, and more. It then uses the OpenAI API to generate a response to each scenario.
The Spinner
class in this script is responsible for displaying a loading spinner while waiting for a response from the OpenAI API. This class runs on a separate thread so that it doesn't block the main thread.
The save_file
and open_file
functions are used to read and write text files.
The generate_scenario
function creates a scenario based on a random selection of attributes from the predefined lists.
2_action.py
The 2_action.py
script reads a set of scenarios generated by 1_race_gen.py
and uses the OpenAI API to generate an action for each scenario. The system message is read from a file called system_action.txt
.
The chatgpt_completion
function in this script is responsible for using the OpenAI API to generate a response to a scenario.
The save_file
and open_file
functions are used to read and write text files.
Getting Started
To use this project, you will need to have an OpenAI API key and have installed the dotenv
library for Python.
- Clone this repository to your local machine.
- Install the
dotenv
library using the following command:pip install python-dotenv
- Create a
.env
file in the root directory of the project and add the following environment variables:
OPENAI_API_KEY=<your API key here>
MODEL=gpt-3.5-turbo
TEMPERATURE=0.7
Replace <your API key here>
with your actual OpenAI API key.
- Create a file called
system_action.txt
in theactions
directory and add the system message that you want the agent to respond with. - Run the
1_generate_scenarios.py
script to generate a set of scenarios. - Run the
2_action.py
script to generate an action for each scenario.
To exit the script at any time, press ctrl + c on your keyboard. This will raise a KeyboardInterrupt and terminate the script.
Note: You may need to adjust the number of scenarios generated and the max number of retries in the chatgpt_completion
function depending on the performance of your OpenAI API account.