Boilerplate for working with the OpenAI API.
OpenAI-boilerplate/
├── prompts/ # Folder containing prompt text files
│ ├── init_terminal.txt # Welcome print content
│ ├── system_prompt.txt # System prompt content
├── utility/ # Utility scripts
│ ├── build_messages.py # Builds messages for the OpenAI API
│ ├── call_GPT.py # Handles API calls to OpenAI
│ ├── check_key.py # Validates the API key
│ ├── debug_print.py # Prints debug information
│ ├── display_init_terminal.py # Initialize the welcome message inside the terminal
│ ├── load_key.py # Loads the API key from .env
│ ├── print_response.py # Print the GPT reponse with a typewriter effect
│ ├── read_prompt.py # Reads content from the prompt text file
├── .env # Environment file (API key)
├── .gitignore # Git ignore file
├── main.py # Main script to run the project
├── README.md # Project documentation
├── requirements.txt # List of dependencies
- Python 3.8+
- Install dependencies:
pip install -r requirements.txt
The .env
file is used to store your OpenAI API key. You can create it inside the project folder via the command line:
echo "OPENAI_API_KEY=sk-your-api-key-here" > .env
Replace sk-your-api-key-here
with your actual OpenAI API key.
Ensure that the prompts/
folder contains the following file:
system_prompt.txt
: A text file with the system prompt.
You can store differen system prompt files in this folder and suit them to your use case.
Run the main.py
script with custom file paths and model names as parameters:
python3 main.py
--system_prompt ./prompts/system_prompt.txt
--model gpt-4o-mini
or
python3 main.py
--sp ./prompts/system_prompt.txt
--m gpt-4o-mini
- No API Key Found: Ensure your
.env
file is correctly set up with theOPENAI_API_KEY
variable. - File Not Found Errors: Verify that the paths to a system prompt (e.g.,
system_prompt.txt
) is correct. - Dependency Issues: Run
pip install -r requirements.txt
to install all required dependencies.
Your problem is not mentioned? Feel free to ask about it to me or by submitting an issue.
This project is open-source and available under the MIT License.