ChatGPT API – Introduction

This class introduces you to the ChatGPT API. By using the API you can create apps with Python code to solve your specific problems.
  • 00:00 Introduction
  • 07:17 Demonstration of ChatGPT and DALL E API
  • 12:20 What is ChatGPT 25:33 Pricing and Requirements for OpenAI API
  • 37:11 Explaining ChatGPT Python Code
  • 50:31 Why ChatGPT API Matter for Coders
  • 56:25 Final Thoughts

chatgpt-demo.py

import openai

openai.api_key = 'APIKEY'

query = "Why Boxing Day is Important"

response = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "you are a teacher"},
    {"role": "assistant", "content": "write a 500 word blog post"},
    {"role": "user", "content": query}
  ]
)

#print(response)
print(response["choices"][0]["message"]["content"])

dalle-demo.py

import openai

openai.api_key = 'APIKEY'

query = "a goat with a trench coat"

response = openai.Image.create(
  prompt=query,
  n=1,
  size="1024x1024"
)
image_url = response['data'][0]['url']
print(image_url)

Be the first to comment

Leave a Reply