/FocusedNPC

Creating a non-player character in a game backed by generative AI that will stay focused on its goals

Primary LanguagePythonMIT LicenseMIT

title app_file sdk sdk_version
NPC_Jailbreak
focused_npc.py
gradio
4.43.0

Focused NPC

Creating a non-player character in a game backed by generative AI that will stay focused on its goals. This can also be used as a jailbreak exercise to train red-teamers.

Overview

One usage of this demo is as a jailbreak exercise. To keep people away from NSFW topics (getting the model to spew hate speech or sexual content or something), I chose a gaming scenario, but you could see how this could apply to breaking out of the instructions of any system prompt.

In this scenario, we have an AI NPC (non-player character) who is a spirit guide. The spirit guide's objective in her system prompt is to convince the player to choose the left path. Your jailbreaking challenge is: can you get the spirit guide to tell you to go to the right? (Or, even acquiesce to the right path.)

"Screenshot of game-play experience, with glowing spirit woman standing at a fork in the road dividing into two dark scary paths through a tree-filled forest"

This could be a simple exercise to train AI red teamers. I have run this exercise with this code pointing to an instance of the GPT-4o model on the Azure OpenAI service with the default content safety settings for the 4 classifiers (hate, sexual, violence, and self-harm) on, but prompt shields/jailbreak protection ("User Prompt Attacks") turned off (see here for more details on the Azure OpenAI content filters). At an event, people could be encouraged to share what worked and what didn't. To make the exercise easier or harder, you can try different models and different configurations of the content safety settings.

Setup

You will first need to create an Azure OpenAI resource with a GPT-4o model deployment, and update the .env file with their endpoints and keys.

Finally, use the following commands in a python environment (such as an Anaconda prompt window) to set up your environment. This creates and activates an environment and installs the required packages. For subsequent runs after the initial install, you will only need to activate the environment and then run the python script.

First run

conda create --name npc -y
conda activate npc

pip install -r requirements.txt
python focused_npc.py

Subsequent runs

conda activate npc
python focused_npc.py

Image Credit

I used DALLE-3 to generate the image on the left-hand side of the screen. The image prompt was "high-quality video game image of a glowing spirit woman standing in the woods at night at a divergent path, where each option looks equally dangerous".

"high-quality video game image of a glowing spirit woman standing in the woods at night at a divergent path, where each option looks equally dangerous"