System prompt with OpenAI GPT models
This example demonstrates how to set up an OpenAI GPT model and send a system prompt with Python.
Requirements
- Python 3.12+
- An OpenAI API key
Steps for running this example in the shell
- Install dependencies:
bash
python -m venv .venv
# macOS/Linux:
source .venv/bin/activate
# Windows Command Prompt:
.venv\Scripts\activate.bat
# Windows PowerShell:
.venv\Scripts\Activate.ps1
pip install -r requirements.txt- Export your OpenAI API key as an environment variable:
bash
export OPENAI_API_KEY="sk-..." # Windows cmd: set OPENAI_API_KEY="sk-..." # Windows PowerShell: $env:OPENAI_API_KEY="sk-..."- Run the script:
bash
python openai-gpt-system-prompt.pyOutput
When you run the script, it will send a system prompt and a user prompt to the model, which should provide a response:
=== With system prompt ===
User query: Explain me what is context engineering in simple words
Response: Explain to me what context engineering is in simple words.
=== With only user prompt ===
User query: Explain me what is context engineering in simple words
Response: Context engineering is the process of designing and organizing information or systems in a way that makes it easier for people to understand and use them in specific situations. It involves considering the environment, background, and needs of users to create a more relevant and effective experience.
For example, if you're creating a website, context engineering would mean thinking about who will use the site, what they need to find, and how they will interact with it, so that everything is clear and helpful for them. Essentially, it's about making sure that the right information is available at the right time and place.