This article is about developing an AI Blog Writer Machine using OpenAI API, GPT-3 AI and Python.
We will continue with our previous tutorial on OpenAI and develop an AI copyright machine for us. This tool will help us write blogs with the help of GPT-3 AI.

We will focus on the following topics:
- Utilizing the Online Playground tool for calling the API
- Writing the python code
- Developing a Flask App for the AI writer
Generating Blog Topic Suggestions: Developing an AI Blog Writer
We will use the online playground to make a blog in three different phases.
Our playground will be made by the following: davinci-instrct-beta-v3. This is an AI model that we will use to make content for our blogs. When it comes to developing unique material, it has proven to be the most effective blog post generator for our use case.
Other parameters:
- Temperature=0.7
- Response length=between 100 and 200 characters
The most crucial aspect of using the OpenAI API is the prompt you utilize. The prompt instructs the AI engine as to what it should return; it serves as a suggestion as to what is expected. In the prompt, specify the topic you want to generate, such as “Create blog topics for xxxxxx.”
Let me provide you with some few examples:
Phase 1 – Think of blog topics based on concepts. Using Artificial Intelligence, the GPT-3 tool can help you come up with absolutely random, human-friendly blog post ideas.

Phase 2 – Create blog section topics based on a single blog topic that break the blog topic down into pieces that can be worked on even more later.

Phase 3 – Write a short paragraph or two of blog content for each of the blog sections.

By combining these three steps above, you can create a blog entirely based on artificial intelligence.
Using the Prompt
The API receives information from the prompt. The use-case, keywords, titles, linguistic tone, and even the first paragraph of a large story can all be entered. The AI will provide you with what should be written next and instinctively put together content for you. The AI will do this until you run out of characters.
Writing the Python Code
The code from the playground can be copied and pasted directly into your Python file.
The source code can be found on our GitHub page: AI Blog Writer with OpenAI GPT-3
The blog.py file:
import os
import openai
import config
openai.api_key = config.OPENAI_API_KEY
def generateBlogTopics(prompt1):
response = openai.Completion.create(
engine="davinci-instruct-beta-v3",
prompt="Generate blog topics on: {}. \n \n 1. ".format(prompt1),
temperature=0.7,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response['choices'][0]['text']
def generateBlogSections(prompt1):
response = openai.Completion.create(
engine="davinci-instruct-beta-v3",
prompt="Expand the blog title in to high level blog sections: {} \n\n- Introduction: ".format(prompt1),
temperature=0.6,
max_tokens=100,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response['choices'][0]['text']
def blogSectionExpander(prompt1):
response = openai.Completion.create(
engine="davinci-instruct-beta-v3",
prompt="Expand the blog section in to a detailed professional , witty and clever explanation.\n\n {}".format(prompt1),
temperature=0.7,
max_tokens=200,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response['choices'][0]['text']
Developing a Flask App for the AI writer
Create a basic app boilerplate if you’re comfortable with Python flask. If you’re not sure how to do this, simply download the code from the GitHub repository linked above.
The app.py file:
from flask import Flask, render_template, request
import config
import blog
def page_not_found(e):
return render_template('404.html'), 404
app = Flask(__name__)
app.config.from_object(config.config['development'])
app.register_error_handler(404, page_not_found)
@app.route('/', methods=["GET", "POST"])
def index():
if request.method == 'POST':
if 'form1' in request.form:
prompt = request.form['blogTopic']
blogT = blog.generateBlogTopics(prompt)
blogTopicIdeas = blogT.replace('\n', '<br>')
if 'form2' in request.form:
prompt = request.form['blogSection']
blogT = blog.generateBlogSections(prompt)
blogSectionIdeas = blogT.replace('\n', '<br>')
if 'form3' in request.form:
prompt = request.form['blogExpander']
blogT = blog.blogSectionExpander(prompt)
blogExpanded = blogT.replace('\n', '<br>')
return render_template('index.html', **locals())
if __name__ == '__main__':
app.run(host='0.0.0.0', port='8888', debug=True)
The index.html file:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Skolo</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="shortcut icon" type="image/x-icon" href="{{ url_for('static', filename='images/favicon.png') }}">
</head>
<body>
<div class="container">
<h1 class="mt-5">Skolo Online Blog Writing Tool</h1>
<p>The Skolo blog writing tool will allow you to enter a blog topic and keywords --- and get in return a full blog that you can use anywhere. The tool intiially provides a list of topic ideas to choose from, once you select a topic, you can go ahead and generate a full content AI blog.</p>
<div class="row">
<div class="col-lg-6">
<form class="" action="/" method="post">
<div class="mb-3">
<label for="blogTopic" class="form-label">What topic do you want to get blog ideas on?</label>
<input type="text" class="form-control" id="blogTopic" name="blogTopic" placeholder="Enter a blog topic">
</div>
<input type="hidden" name="form1" value="form1">
<button type="submit" id="blogTopicButton" class="btn btn-primary">Generate Blog Ideas</button>
</form>
</div>
<div class="col-lg-6">
1. {{blogTopicIdeas|safe}}
</div>
</div>
<br>
<hr>
<br>
<div class="row">
<div class="col-lg-6">
<form class="" action="/" method="post">
<div class="mb-3">
<label for="blogSection" class="form-label">Enter the Blog Topic Below that you have selected to write about</label>
<input type="text" class="form-control" id="blogSection" name="blogSection" placeholder="Enter the blog title to generate blog sections on">
</div>
<input type="hidden" name="form2" value="form2">
<button type="submit" class="btn btn-primary">Generate Blog Sections</button>
</form>
</div>
<div class="col-lg-6">
{{blogSectionIdeas|safe}}
</div>
</div>
<br>
<hr>
<br>
<div class="row">
<div class="col-lg-6">
<form class="" action="/" method="post">
<div class="mb-3">
<label for="blogExpander" class="form-label">Enter the Blog section title you want to expand</label>
<input type="text" class="form-control" id="blogExpander" name="blogExpander" placeholder="Enter the blog section title">
</div>
<input type="hidden" name="form3" value="form3">
<button type="submit" class="btn btn-primary">Expand on the title</button>
</form>
</div>
<div class="col-lg-6">
{{blogExpanded|safe}}
</div>
</div>
</div>
<!-- Option 1: Bootstrap Bundle with Popper -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>
Leave a Reply