From the course: Hands-On OpenAI API: Building a Real-World Solution

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Calling the assistant from the Web API

Calling the assistant from the Web API

- [Instructor] We have this basic implementation of a web API using FastAPI. Now we need to invoke the assistant that we've created. First, let's import the required modules. Then let's create the constant that we're going to use for the second user message. And now let's read the environment variables and create the OpenAI client object. So here's what's happening now. As you can see, we are reading the environment variables for both the API key and the assistant ID. This strategy will help us configure the target assistant without requiring the service to be updated. To expedite this process, I already set the environment variable in my machine for development purposes. So let's open up the terminal and let's execute ls env and then forward slash and the name of this environment variable. So we can see that we have that environment variable in place. Okay, let's close the terminal. And now let's implement the rest of the code. So I'm going to paste it right here and you can see that…

Contents