We all are waiting for CHAT GPT APIs to be publicly available but until that is not we can use GPT-3 API to connect AI and get automated API responses based on “DaVinci” engine. GPT is the actual technology behind the CHAT GPT so let’s see how to access GPT-3 API
Check out our new article for How to access New ChatGPT and Whisper APIStep 1: Log into your OpenAI account and obtain API Key
To access the GPT-3 API, you will need to create an OpenAI account and apply for access to the API.
- Sign up and Sign in to the OpenAI website.
- At the right top corner of the page click on “view API keys”.
- Click on “Create an API Key” and obtain a new open API key.
Step 2: Download the required libraries
Download openAPI python library required for the code, instead of python any other coding language also works fine with GPT-3 APIs.
pip install openai
Step 3: Create code to access GPT-3 API
Following is the example python code which can be executed from anywhere, in this case we are running it from Linux terminal.
Create a code and give executable permission,
vi heyGPT3
#!/usr/bin/env python3
#Import Modules
import openai,os,sys
prompt = sys.argv[1]
openai.api_key = os.environ['api_key']
completions = openai.Completion.create(
# davinci-003 , davinci-002 also can be used.
engine="text-davinci-003",
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
message = completions.choices[0].text
print(message)
chmod +x heyGPT3
Step 4: Talk to GPT bot from anywhere
Export API key to authenticate
export api_key=1k-XXXX
Start questioning GPT and amazed with the response
Above is an example of how to access GPT-3 API and perform some operations to get useful results but there are numerous opportunities to build applications around it. Currently, CHAT-GPT APIs are not available to the general public but can be requested from ChatGPT API request Form.
Check out our new article for How to access New ChatGPT and Whisper APIThis article is created based on experience but If you discover any corrections or enhancements, please write a comment in the comment section or email us at contribute@devopsforu.com. You can also reach out to us from Contact-Us Page.
Follow us on LinkedIn for updates!