This is the repository for the LinkedIn Learning course OpenAI API: Moderation
. The full course is available from LinkedIn Learning.
Left unchecked, AI systems can both process and output what can be considered harmful language. Sometimes this is necessary; other times it is unwanted. Using the OpenAI API, you can apply moderation tools to the communication between the user and the API to control both what goes into and what comes out of the system. In this course, you’ll get an overview of how these features work and how to implement them in your app.
See the readme file in the main branch for updated instructions and information.
This repository provides basic examples of how to use the Moderation feature of the OpenAI API in Python.
There are three examples: basic.py
, conditional.py
, and mod-assistant.py
. Each example is stand-alone and runs in terminal.
To use these exercise files you need an OpenAI API key. You get that key at platform.openai.com
- Click the "Code" button and select "Codespaces."
- Create a new Codespace or open one you've already created.
- Create a new file named
.env
in the root folder. - Add
OPENAI_API_KEY=
followed by your OpenAI API key to.env
- Note
.env
is not tracked by GitHub so the file will only exist in this Codespace. - To run the Python example in terminal, use the
python [filename].py
command.
To run mod-assistant.py
you must first create an Assistant and add its ID into the file. You can create an assistant at platform.openai.com.
For further info on OpenAI Assistants check out our dedicated course on the subject.