Project URL: https://roadmap.sh/projects/openai-api-python
This project demonstrates how to set up and use the OpenAI Python API, including configuring the client, managing environment variables, exploring parameters, and building a simple interactive chatbot.
-
Install dependencies:
pip install -r requirements.txt
-
Configure Environment Variables:
- Copy
.env.exampleto a new file named.env. - Add your OpenAI API key to the
.envfile.
OPENAI_API_KEY=your_openai_api_key_here - Copy
01_basic_call.py: Demonstrates initializing the client and making a single API call while experimenting withtemperature,max_tokens, andsystem messageparameters.python 01_basic_call.py
02_interactive_script.py: A small console-based chatbot that takes continuous user input and returns responses from the model.python 02_interactive_script.py
03_temperature_comparison.py: Sends the same prompt to the model multiple times using different temperature values to compare the deterministic versus creative nature of the outputs.python 03_temperature_comparison.py