From the course: OpenAI API for Python Developers

Project setup and overview

From the course: OpenAI API for Python Developers

Project setup and overview

- [Instructor] For this example, we create a chat bot that can generate conversational replies and simulate human-like conversations thanks to the power of the GPT large language models, and this will serve as a basic starting example for future projects, and also, if you ever want to build your own customized chat bot using OpenAI. So first things first, you want to download the starter projects, and we're going to go through the instructions in the read-me file. So first you want to create a virtual environment, then to activate the virtual environment, you're going to run this script. Next we're going to install the packages, and also, we must remember to set up an API key, and finally we're going to run this script to start the projects. For this project, we connect to the chat completion API. The chat models are large deep learning models that are trained on a large amount of data, giving the applications like ChatGPT the ability to understand and process natural language and making the chat bot capable of responding in the most natural way. So it's going to feel like a real human-like dialogue. So here we use the GPT 3.5 turbo model, and the main parameter here will be an array of messages that comprises the chat dialogue, right here, and notice how the message object is structured with the key value pair dictionary with the key's role and contents, and so the roles can be system, assistant and user, and a system message is set and required to set the behavior of the assistant bot, and this is to give a persona. Basically we tell the assistant how to behave, and here we have a basic example, like, you are a helpful assistant, but it can also be a professional writer or a math tutor, or even an experienced standup comedian, and I'm not saying that randomly. We're going to use that skill for an upcoming demonstration next, and below we have an example of a chat completion response object. We're going to navigate through this response object to access choices, which is an array with one object, and inside we're going to find a message object with the role assistant, and this corresponds to the response from the assistant bot. So let's go back to our project. We're going to set up our project, and first we want to create a virtual environment. So if it's not done for you, it's already done for me. You're just going to run this script to create a new virtual environment, then to activate this one, we're going to run this one, and you see that this is activated when you see this env here in parenthesis. Next we're going to install the packages, and I'm going to use this one because I work on a Mac with pipe, three. Here we go, and the next step. So we're going to go back to this afterwards, but the next step will be to then run this script to then start the project. Here we go. So it looks like here we are missing. So the most important, which is the API key, and this is what we're going to do next. Obviously we're going to need to set up an API key to be authorized to make API calls. So up next we go straight to work. We build a chat bot assistant. We also configure the project with an API key to be authorized to make API calls, and we're going to be finally ready to send API requests.

Contents