From the course: OpenAI API: Vision

Setting up the API

- [Instructor] In order to leverage OpenAI's API for vision tasks, we need to do some setting up. We'll have to install some libraries, create an API key and we don't want to include our API key in source code. It's important to leverage an environment variable or some sort of API key management system. So let's get started by installing these libraries. I'm going to head to my terminal, which is here at the bottom of my code editor. And I'll start by installing OpenAI. So I'll type in python3-m pip install openai. Now if you're using a virtual environment or your code is containerized, it's a similar installation of OpenAI and you'll see that it's already installed. I'll clear my terminal. Now I'll type in python3-m pip install flask. And this is going to help us in a project in a later chapter. Next thing I'll want to do is head over to OpenAI and you'll need an OpenAI account to use this API. And here in the menu there is API keys and you'll want to open it and you'll create a secret key, which you're going to use later on. Now I'll head to my terminal and I'll want to export this key. So I'll type in export OPENAI_API_KEY equals, and I'll call this secret_key. Of course, you'll want to use your actual key and export it. And this is valid for one session of a terminal. So if I close this terminal and open a new one, I'll want to export again. If for some reason the session ended, it's important to export this key one more time. And if you use this specific name for the secret key, the library knows to look for the secret key there. If you have different conventions for naming environment variables, that's fine. You'll just have to specify it in the code. So here I'll clear this and what I'll do now is in my exercise files, I'll navigate to 01_01. So cd 01_01, clear my terminal and type in python3 test_vision.py. I've included an image as well as a very minimal amount of code to make the API work. So let's go ahead and run this. And the image shown is of a black mug with a graphic design printed on its surface. And if you look at 01_01, you'll see that this is correct. This is description of this image. Great. So now that we've set up, we can start looking at how this API works.

Contents