Overview
This guide explains how to add runtime protection to a simple chatbot. You will be running a basic chatbot, detecting toxicity in the users input, and if this is detected, ending the conversation. You will start by creating a central stage, as if you were an AI governance team. You will then use this stage in a simple chatbot. In a real-world scenario, you could use this detection to redirect a user from an AI chatbot to a human representative. In this guide you will:- Set up your project with Galileo
- Create a central stage
- Create a basic chatbot
- Add runtime protection to your basic chatbot
Before you start
To complete this how-to, you will need:- An OpenAI API key
- A Galileo project configured to use the Luna models.
- Your Galileo API key
Install dependencies
To use Galileo, you need to install some package dependencies, and configure environment variables.Install Required Dependencies
Create a .env file, and add the following values
Create a central stage
You first need to create a central stage. In a real-world scenario, these central stages would be managed by an AI governance team.Create a Python file to create the stage called `create_central_stage.py`
Add import directives
Create the rule
Create an override action
Create a ruleset
Create the central stage
Run your code
The full create_central_stage.py code
The full create_central_stage.py code
Create a basic chatbot
Now your central stage is created, you need to create a chatbot to use the stage.Create a Python file to for the chatbot called `app.py`
Add the basic chatbot code
app.py file.Run your code
Add runtime protection to your basic chatbot
Now you have a chatbot, you can add runtime protection. In this case, you will be checking the input for toxicity, and if the input is toxic, ending the conversation.Add import directives
app.py file:Create a payload
user_input has been checked to see if the conversation should end, create a Payload using this input:Send the payload to the runtime protection SDK
Check the response
while loop, ending the conversation.Run your code
The full app.py code
The full app.py code