GPT-4o Quickstart Guide
Introduction #
In this guide, we will show you how to quickly get set up with OpenAI's GPT-4o model. GPT-4o was released on May 13th, 2024, and it is one of their flagship models that can reason across audio, vision, and text in real-time.
Getting started #
To get started building with GPT-4o, fork this template by clicking "Use template".
Set up your OpenAI API key #
The first step is to sign up for one OpenAI account. Then proceed to directly the API key page, and create an API Key. Once you have your API Key, go back to your project on Replit.
Under "Tools", you will see a tool called "Secrets."
Open the Secrets pane and paste in your API key to the Secret labeled OPENAI_API_KEY.
Calling the OpenAI model #
Replit takes care of all of the setup for you, so at this point, you can click "Run." You will see a response in the Replit Console. Congratulations, you have officially used an OpenAI model.
Explaining the code #
Your project is already complete, but to better understand how the code works, we will give a brief walkthrough.
Importing the packages #
The project starts by importing libraries. Libraries are the building blocks of software. In this case, we are using:
- openai - A library to interact with openai models
- os - a library to help import the API key without exposing it
- sys - a library that will help us handle errors
Import the API key #
API keys are used to authenticate and bill your account. If your API key is exposed, anyone could use it, and you would be billed. The keys are highly sensitive, so we store them in Replit Secrets. Then we use the line of code above to store that key in the openai.api_key variable.
Check for the API key #
This block of code is included to handle errors. If you try to run the project without an API key, then this section of the code will alert you.
Create chat completion request #
This portion of the code sends the actual request to the OpenAI model. In this case, you can see we specify model="gpt-4o" to use GPT-4o, and we offer some initial messages with roles (e.g., user, assistant) for the model to see.
Print the response #
Based on the query and context, we then print the model response to the conversation.
What's next #
Now that you have made a call to OpenAI for the first time, you could try some of the following:
- Build a website Q&A bot with OpenAI
- Try other quickstart guides