Amazing developer use cases of openAI’s GPT-3 (Chat GPT)

Mark Aloo
CodeInfluence
Published in
8 min readDec 31, 2022
OpenAI’s Chat GPT

A few weeks ago, one of the greatest things that has ever happened to AI did happen. Chat GPT hapenned! Although the GPT language model has been around for long, it had not been that open to the public like this before. Now that we have it here, we may as well take advantage of it. Chat GPT is built on top of GPT-3 (Generative Pre-trained Transformer 3). There are a lot of things you can do with GPT-3 as a developer. Below is a list of some ideas of possibilities that you can explore on OpenAI’s language model. I have provided code snippets for each using Node.js. You can actualy build a SaaS around some of these ideas.

1. Text generation

Based on a given prompt, GPT-3 can produce creative text. This may be helpful for tasks like coming up with product descriptions, producing posts for social media, or even coming up with blog articles. However, note that Google and other search engines do not index text generated by AI.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Write a short story about a young girl who discovers a magical tree in the forest",
temperature: 0,
max_tokens: 1024,
});

console.log(response.choices[0].text);

2. ChatBot development

GPT-3 model can be used to create ChatBots that can have conversational interactions with people in an almost natural way. These ChatBots can be used as virtual assistants for both customer service and personal usage. Another way they can be used is being plugged into websites to enhance interaction.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Marv is a chatbot that reluctantly answers questions with sarcastic responses:\n\nYou: How many pounds are in a kilogram?\nMarv: This again? There are 2.2 pounds in a kilogram. Please make a note of this.\nYou: What does HTML stand for?\nMarv: Was Google too busy? Hypertext Markup Language. The T is for try to ask better questions in the future.\nYou: When did the first airplane fly?\nMarv: On December 17, 1903, Wilbur and Orville Wright made the first flights. I wish they’d come and take me away.\nYou: What is the meaning of life?\nMarv: I’m not sure. I’ll ask my friend Google.\nYou: What time is it?\nMarv:",
temperature: 0.5,
max_tokens: 60,
top_p: 0.3,
frequency_penalty: 0.5,
presence_penalty: 0.0,
});

console.log(response.choices[0].text);

3. Translation

You can translate between languages using GPT. Building translation software or developing multilingual chatbots can also benefit from this.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Translate this into 1. French, 2. Spanish and 3. Japanese:\n\nWhat rooms do you have available?\n\n1.",
temperature: 0.3,
max_tokens: 100,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

console.log(response.choices[0].text);

4. Sentiment Analysis

When given a piece of text, the model can evaluate its sentiment and identify whether it is neutral, negative or positive. This might be helpful for tasks including but not limited to assessing customer reviews, filtering social media posts and comments or keeping an eye on brand sentiment on social media.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Classify the sentiment in these tweets:\n\n1. \"I can't stand homework\"\n2. \"This sucks. I'm bored 😠\"\n3. \"I can't wait for Halloween!!!\"\n4. \"My cat is adorable ❤️❤️\"\n5. \"I hate chocolate\"\n\nTweet sentiment ratings:",
temperature: 0,
max_tokens: 60,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

console.log(response.choices[0].text);

5. Summarization

Another task that GPT-3 is good as is summarization of long paragraphs. This makes it easy to digest long pieces of articles. It can also be useed to summarize a piece of information into major points.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Summarize this for a second-grade student:\n\nJupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.",
temperature: 0.7,
max_tokens: 64,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

console.log(response.choices[0].text);

6. Content Recomendation

How cool would it be to come back to a website and get content that interest you? GPT-3 text model can be used to recomend content based on past interactions. You can build recommendation engines for your website using this.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Here is a list of products in a store:\n\nTennis racket, 2. Football, 3. Golf club, 4. Running shoes, 5. Basketball, 6. Baseball bat, 7. Skateboard, 8. Bicycle, 9. Swimming goggles, 10. Soccer cleats, 11. Volleyball, 12. Snowboard, 13. Skis, 14. Weightlifting gloves, 15. Surfing board, 16. Scuba diving gear, 17. Kayak, 18. Ice hockey stick, 19. Crossfit gloves, 20. Cricket bat, 21. Boxing gloves, 22. Archery bow, 23. American football helmet, 24. Aerobics mat, 25. Yoga mat.\n\nThe last time a user visited the website, they searched for: tennis racket, tennis shorts, water bottle\n\nRecoment some products they may use from our list:\n\n1. Running shoes\n2. Swimming goggles\n3. Weightlifting gloves\n4. Surfing board\n5. Scuba diving gear\n6. Ice hockey stick\n7. Crossfit gloves\n8. Boxing gloves\n9. Archery bow\n10. American football helmet",
temperature: 0,
max_tokens: 60,
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
});

console.log(response.choices[0].text);

7. Text classification

Tasks such as filtering spam, categorizing emails, categorizing products and categorizing social media posts are some of the uses of the GPT-3 model in text classification.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "The following is a list of companies and the categories they fall into:\n\nApple, Facebook, Fedex\n\nApple\nCategory:",
temperature: 0,
max_tokens: 64,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

console.log(response.choices[0].text);

8. Paraphrasing

You can also use this model to do paraphrasing. As a matter of fact, there are a lot of paraphrasing tools out there built using GPT.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Paraphrase this paragraph:\n\nJupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-half times that of all the other planets in the Solar System combined. Jupiter is one of the brightest objects visible to the naked eye in the night sky, and has been known to ancient civilizations since before recorded history. It is named after the Roman god Jupiter.[19] When viewed from Earth, Jupiter can be bright enough for its reflected light to cast visible shadows,[20] and is on average the third-brightest natural object in the night sky after the Moon and Venus.",
temperature: 0.7,
max_tokens: 64,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

console.log(response.choices[0].text);

9. Data extraction

I recently built an expense tracker that used Google Cloud Vision API as OCR to extract text from an image of a receipt. I see how I could use GPT-3 to extract the information from the piece of unstractured text I get after the OCR.

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "text-davinci-003",
prompt: "Extract stuctured expenses from this piece of text in the format below:\n\nlist:\nname: toothbrush, price:50\nname: soap dish, price:20\n\nHere is the piece of text: \n\n\"Adress: 1234 Loren Ipsum, Dolor\n\nTel: 123-456-7890\n\nDate: 01-01-2018 10:35\nLoren 6.50\nIpsum 7.50\nDolor Sit 48.00\nAmec 9.30\nConsectetur 11.90\nAdipiscing Elit 1.20\nSed Do 0.40\nAMOUNT 84.80\nSub-total 76 80\nSales Tax 8.00\n\nBalance 84.80\"\n\n\nlist:\nname: toothbrush, price:50\nname: soap dish, price:20\n",
temperature: 0,
max_tokens: 831,
top_p: 1,
frequency_penalty: 0.5,
presence_penalty: 0,
});

console.log(response.choices[0].text);

10. Programming

With GPT-3 you can explain code, generate code from a text, transform code from language to another, fix bugs and even calculate time complexity for a given function among other use cases you can imagine. Shoud’ve been the first on the list, right?

// convert simple JavaScript expression to Python

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "code-davinci-002",
prompt: "#JavaScript to Python:\nJavaScript: \ndogs = [\"bill\", \"joe\", \"carl\"]\ncar = []\ndogs.forEach((dog) {\n car.push(dog);\n});\n\nPython:",
temperature: 0,
max_tokens: 64,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
});

console.log(response.choices[0].text);
// explain a complicated piece of code

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

const response = await openai.createCompletion({
model: "code-davinci-002",
prompt: "class Log:\n def __init__(self, path):\n dirname = os.path.dirname(path)\n os.makedirs(dirname, exist_ok=True)\n f = open(path, \"a+\")\n\n # Check that the file is newline-terminated\n size = os.path.getsize(path)\n if size > 0:\n f.seek(size - 1)\n end = f.read(1)\n if end != \"\\n\":\n f.write(\"\\n\")\n self.f = f\n self.path = path\n\n def log(self, event):\n event[\"_event_id\"] = str(uuid.uuid4())\n json.dump(event, self.f)\n self.f.write(\"\\n\")\n\n def state(self):\n state = {\"complete\": set(), \"last\": None}\n for line in open(self.path):\n event = json.loads(line)\n if event[\"type\"] == \"submit\" and event[\"success\"]:\n state[\"complete\"].add(event[\"id\"])\n state[\"last\"] = event\n return state\n\n\"\"\"\nHere's what the above class is doing:\n1.",
temperature: 0,
max_tokens: 64,
top_p: 1.0,
frequency_penalty: 0.0,
presence_penalty: 0.0,
stop: ["\"\"\""],
});

console.log(response.choices[0].text);

Conclusion

The possibilities are vast and open to your imagination. This thing (GPT-3) scares me with its possibilities! As you have seen, the key is just to play around with the prompt. You can get better at giving the right prompts to get the desired results by visiting the OpenAPI docs and playing around with examples on the OpenAI playground. You may also be interested in DALL.E 2 from OpenAI that can create images and art from descriptions in natural language.

I am building a web app based on GPT-3 and DALL.E 2. Follow me here and on social media so you know when it comes out. I will be sharing on how I built it step by step.

Happy Hacking!

--

--

Mark Aloo
CodeInfluence

Tech pro with a broad skillset in frontend development, software engineering, RPA, technical writing, speaking about tech and passion for continuous learning