Hey, I am on LinkedIn come and say hi 👋
Code is here
OpenAI ChatGPT APIs are out! They open a new endless possibilities. Today we’re going to see how to use them in Python
Setup
Get an API key
Log into OpenAI website and, if you are not on the free tier, add a credit card. After that go to the profile section (top right) and click on View API keys
.
Then click on Create new secret key
and store your key, you will need it later.
Install pip package
Now, install the openai
pip package
pip install --upgrade openai
We’re ready to go!
Make a simple request
The official doc is here. To make a simple request, you will need to import the openai
package and call the openai.ChatCompletion.create
method by passing the model id and a list of messages.
# main.py
import openai
chat_completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
# system…