From the course: Hands-On Introduction: Python

Unlock the full course today

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

OpenAI API

OpenAI API

- [Narrator] So, this is a hands-on course and it's time we look at some code. So for this example, I'm going to install the package OpenAI. So, I'll type in python3 -m pip install openai and I can also run pip install - - upgrade pip since I've been prompted to do that. I'll clear my terminal, and now let's have a look at this code. So, first I bring in OS, and this is going to allow me to access environment variables such as my GitHub token without revealing it or placing it in source code, which is not secure. Next, I'll import OpenAI from openai so that I can instantiate an OpenAI client. I'll grab the GITHUB_TOKEN, which is going to allow me to use GitHub Models in order to access my model. I'll have an endpoint here, which is this inference.ai.azure endpoint, and I'll name my model, which is gpt-4o. gpt-4o is an extremely capable model from OpenAI. It's great for many tasks, not as good for reasoning tasks as the o1 model. Extremely capable though. Next, I instantiate that…

Contents