Code completion/Image
generation using OpenAI
APIs
Faiz ul haque Zeya
CEO Transys
 This presentation is about how to write code for OpenAI Codex model for code
completion and image generation.
Steps before writing code
 1. Signup openAi.com https://openai.com/api/login/
 2.Go to code completion.
Play ground
 You can try the code generation in play ground.
OpenAI API
 YOU CAN USE THE OPENAI API TO USE THE MODELS IN YOUR CODE FOR
EXAMPLE COMPLETE CODE OR GENERATE IMAGES ETC.
 https://beta.openai.com/docs/api-reference/introduction
 Here you will find a link to API key page where you can download the key
(copy to clipboard) and later used in code.
 Here you will find APIS for code completion, correction ,image generation
etc.
 Different URLS are to be passed for different purposes. HTTP response post
method is used to post the request in python with json data and headers and
shown in next slide.
 Further before doing any thing you have to install openai using pip.
The code for image generation
 !pip install openai
#Image generation using OpenAI api
#Singup and get the api key from https://beta.openai.com/account/api-keys
# Todo for you.
 # response.content is the image save it and display it.
import os
import openai
import requests
import requests
headers = {
 'Content-Type': 'application/json',
 'Authorization': 'Bearer YOUR_API_KEY',
 }
 json_data = {
 'prompt': 'A mountain with clouds',
 'n': 2,
 'size': '1024x1024',
 }
 response = requests.post('https://api.openai.com/v1/images/generations', he
aders=headers, json=json_data)
#save the content into binary and display it
 print(response.content)
Link to my github code
 https://github.com/faizulhz/datascience1/blob/master/Codex_image_gener
ations_ex2.ipynb
 For code generation use the URL
 https://api.openai.com/v1/completions
 Use the parameters and URLs from API page
 https://beta.openai.com/docs/api-reference/introduction
 Also you can use the command line CURL tool to run it as a .bat file progam.

Code completion using OpenAI APIs.pptx

  • 1.
    Code completion/Image generation usingOpenAI APIs Faiz ul haque Zeya CEO Transys
  • 2.
     This presentationis about how to write code for OpenAI Codex model for code completion and image generation.
  • 3.
    Steps before writingcode  1. Signup openAi.com https://openai.com/api/login/  2.Go to code completion.
  • 4.
    Play ground  Youcan try the code generation in play ground.
  • 5.
    OpenAI API  YOUCAN USE THE OPENAI API TO USE THE MODELS IN YOUR CODE FOR EXAMPLE COMPLETE CODE OR GENERATE IMAGES ETC.  https://beta.openai.com/docs/api-reference/introduction  Here you will find a link to API key page where you can download the key (copy to clipboard) and later used in code.
  • 6.
     Here youwill find APIS for code completion, correction ,image generation etc.  Different URLS are to be passed for different purposes. HTTP response post method is used to post the request in python with json data and headers and shown in next slide.  Further before doing any thing you have to install openai using pip.
  • 7.
    The code forimage generation  !pip install openai #Image generation using OpenAI api #Singup and get the api key from https://beta.openai.com/account/api-keys # Todo for you.  # response.content is the image save it and display it. import os import openai import requests import requests headers = {  'Content-Type': 'application/json',  'Authorization': 'Bearer YOUR_API_KEY',  }
  • 8.
     json_data ={  'prompt': 'A mountain with clouds',  'n': 2,  'size': '1024x1024',  }  response = requests.post('https://api.openai.com/v1/images/generations', he aders=headers, json=json_data) #save the content into binary and display it  print(response.content)
  • 9.
    Link to mygithub code  https://github.com/faizulhz/datascience1/blob/master/Codex_image_gener ations_ex2.ipynb  For code generation use the URL  https://api.openai.com/v1/completions  Use the parameters and URLs from API page  https://beta.openai.com/docs/api-reference/introduction  Also you can use the command line CURL tool to run it as a .bat file progam.