DEV Community

Cover image for How I created a kids’ story creator using GPT3 ?

Posted on

How I created a kids’ story creator using GPT3 ?

Being an active twitter user, I came across a plethora of AI tools and side projects people made primarily using stable diffusion and GPT3. I realized the huge potential of all these algorithms, and found the side projects to be really fun experiments. I decided to deep dive into GPT3, and use it to create an app which creates stories based on genres and characters.

Try it out here

OpenAI provides two types of AI models, GPT3 — which is a text generation model and DALL-E which is an image generation model. I read the GPT3 docs which are pretty succinct and easy to understand. OpenAI also provides 18$ worth of credits for the GPT3 models, which makes it easy to experiment and build projects. The key to getting the desired results from either of these models depends on how well you write the prompts.

Prompt is basically a statement explaining what you want the algorithm to create.

For e.g

A prompt given to DALL-E could be “Create a Van Gogh style painting of a Coca-Cola can”.

A prompt given to GPT-3 could be “Explain the history of Greece to a 5 year old”.

OpenAI provides a playground where you can type prompts, see the results and tweak accordingly.

I wanted to get stories from different genres having different characters, and to abstract away the requirement of typing a prompt which is still pretty esoteric for people not from a tech background had to design a UI which should appear self explanatory.

I started designing in Figma, and choose to use simple and familiar radio buttons and checkboxes for the user to select a genre and a maximum of 2 characters.

I choose to code the app in NextJS, it’s a full stack React framework and I could write an API which uses the openAI SDK to create results without the need to create a seperate expressJS project and host it.

I have also used framer motion to create subtle animations. Further the background image that I have used is generated by DALL-E

It’s incredibly easy to use the openAI nodejs SDK.

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

const configuration = new Configuration({
  apiKey: process.env.API_KEY,

const openai = new OpenAIApi(configuration);

export default async function handler(req, res) {
  const body = req.body;
  const prompt = `Write a long form ${body.genre} story which has a ${body.characters[0]} and a ${body.characters[1]}`;
  const response = await openai.createCompletion({
    model: "text-davinci-002",
    prompt: prompt,
    temperature: 0.7,
    max_tokens: 3000,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
  return res.status(200).json({ data:[0].text });
Enter fullscreen mode Exit fullscreen mode

That’s pretty much how you pass a dynamic prompt using string interpolation and return the response.

Would love to collaborate on more such projects, you can find me on twitter

Try it out here**

Top comments (2)

iimrx profile image
Abdulrazak A. Othman

Nice one!
OpenAI have been opened there chatGPT api if you use it to make more good ideas for kids story

ahmednadar profile image
Ahmed Nadar

Nice idea and cool project.
Is your repo open for public?