This project is a simple demo showing how you can change the personality of the chatbot by changing the system prompt. Its meant to be shared with people with zero AI coding experience, so they can get a feel for how the APIs work, and what the role of a system prompt is. There are three example personas already in the script, including a genetics researcher persona! Try chatting with each persona, or make your own.
You'll quickly see that despite the jokes made about it "prompt engineering" is a real thing, the way you build your prompt can wildly affect your output. You can use prompts to give example outputs, demand a specific format, define personas, or special rules you don't want exposed to the user.
Note: This is a great example of why collaboration between subject-matter experts and AI specialists is so powerful. When building complex systems to solve real-world problems, you often need to design prompts that guide the model in how to reason through a task. Experts bring tremendous value here—they can help shape these prompts based on the thought processes they've developed through years of experience.
Also, these bots wont be as powerful as the chatgpt that you see online, with long term memory and web search abilities. Those things have to be built.
To run this project, just run the following from the project root after doing the setup below:
python persona_chat.pyThen take a look at the code, and play around with it!
A virtual environment is an isolated Python environment that allows you to manage project-specific dependencies. You dont strictly need it, but this will help keep your python libraries organized.
-
Open a terminal and navigate to your project directory:
cd path/to/your/project -
Create a virtual environment:
python3 -m venv venv
-
Activate the virtual environment:
source venv/bin/activateWhen activated, your terminal prompt will change to show the name of the virtual environment.
-
Open Command Prompt and navigate to your project directory:
cd path\to\your\project -
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
venv\Scripts\activate
When activated, your command prompt will be prefixed with
(venv).
Once your virtual environment is activated, install the requirements:
pip install -r requirements.txtThis will install the following packages:
- openai: The OpenAI Python client
- requests: For making HTTP requests
- python-dotenv: For loading environment variables from a .env file
First, you'll need to get an OpenAI API Key. This means you'll need to make a dev account, fund it ($10 will last you a while), and get the key.
- You need a file called
.envwith is your API key saved in this format:OPENAI_API_KEY=your_api_key_here
To help, I included a file called .env_example that already has this template. Just run this to make a renamed copy of the template file:
cp env_example .envThen fill it in with your API key.
When you're done working on the project, you can deactivate the virtual environment:
deactivate