Building AI Application: with OpenAI API

The purpose of this tutorial is mainly based on building an AI Application using the OpenAI API. This tutorial does not consume a lot of time, it usually take minutes to complete. No AI programming, models or mathematical knowledge needed to completed this tutorial.

In the old days, OpenAI had a vetting and approval process, which I never had the time to complete, so I avoided trying it. That hasn’t changed.  You can go to their website to sign up for a free trial, get your API keys, and start using their service.

Visit them here: OpenAI API

Building AI Application: with OpenAI API
Introduction to OpenAI API

What is OpenAI for Building AI Application

Elon Musk and other investors founded and funded OpenAI in 2015 as a non-profit organization that would make AI tools more accessible and open to everyone. Microsoft became the company’s partner in 2019 after the company changed to a for-profit organization.

The GPT-3 language model was announced by OpenAI in 2020 and is capable of generating text, categorizing data, summarizing information, and much more – these are the core models of the current OpenAI AI – which we will explore in this tutorial.

“OpenAI” refers to itself as a commercial Artificial Intelligence (AI) API whose primary function is to provide “text-in, text-out” tools for general use. Therefore their website allows anyone to sign up, then start benefiting from AI models that are already trained and powerful(with tons of text data from the internet). These AI models have the following capabilities:

  • Completion of texts automatically (highly used for writing blogs and producing content)
  • Translating text
  • Classifying text
  • Generating idea (creating online content)

OpenAI API use cases at the moment: Building AI Application

Creating Content

Using the OpenAI GPT-3 API, you can create websites like Ryter and Peppertype that produce marketing content.

Market insights analysis

To follow trends and market insights in real time, additionally you can build real-time tweet classification engines.

Models and Free Trial from OpenAI

OpenAI provides you with a credit of $18 and an API key, so you can get started using the API immediately. Before you begin, you should familiarize yourself with the various models offered by the API, as they have varying capabilities, response times, and costs.

Building AI Application
OpenAI models strengths and weaknesses

Among the models, the Davinci is the most capable and expensive. The models become cheaper and faster as you move down the list, but they are less capable. Each model now performs all your needs. Using Davinci, you could, for example, come up with ideas for blog posts based on some description. The cheapest Ada is good for categorizing tasks even though it cannot produce text suggestions. Davinci would be necessary, for example, if you intended to generate blog ideas based on some description.

Free Trial

You can see on the picture above on how much it will cost based on your credits, or tokens as they call them.

Generate Blog Topics

Once you’ve obtained your API keys and understood pricing, then it’s time to make your first API call. To do so, we will use Python.

You should first install the library in your virtual environment:

pip install openai

Store your API keys in an ENV file or a config file.

This is the code:

import os
import openai
import config

openai.api_key = config.OPENAI_API_KEY
response = openai.Completion.create(
engine="davinci",
prompt="Blog topics dealing with daily life living on Mars\n\n1.",
temperature=0.3,
max_tokens=64,
top_p=1,
frequency_penalty=0.5,
presence_penalty=0)
print(response)

With this method, the API is requested to return blog topics with the subject: “dealing with daily life on Mars” and to return a maximum of tokens. This call is using the Davinci engine.

Test the response by running this code.

YouTube Video on Building AI Application: with OpenAI API

Find more articles like Twitter API V2 on our platform. Thank You

Leave a Reply

Your email address will not be published.

Subscribe to our mailing list

And get this 💃💃 Free😀 eBook !

Holler Box