TL;DR
To summarize, I want to automate my blog posts using ChatGPT and a database (Firestore). I was inspired by a YouTube video by a guy named Jean-Philippe who did the same thing using NoCode tools (Zapier and Airtable), but I did it with code, chose Firestore as my database, and plan to use ChatGPT to support the automation process.
👆 The above summary was done with ChatGPT.
ChatGPT blog automation?
If you search for "chatgpt blog automation" on YouTube, there are tons of videos. I referenced Ilzaler Jang Piem's "How to automatically generate dozens of blog posts in 2 minutes with chatGPT".
In the YouTube video, he automated his blog using only NoCode tools. From now on, I'll refer to him as Jang Hyung-nim.
He was using Zapier as an automation tool and Airtable as a database. When I checked Airtable's pricing, I found that it was free to use. However, it's only free for up to 1,200 records. Zapier is also free. However, the free version only allows single-step zaps, so I couldn't create complex workflows.
I could have used the NoCode tool like my brother-in-law, but since I can code, I decided to develop it myself. I decided to use Firestore on Google Cloud for the database. Firestore is free up to 1 GiB and allows 50,000 reads and 20,000 writes per day. We decided to develop the automation part ourselves with the help of ChatGPT.
Setting up the project environment
I asked ChatGPT how to configure the project. They're kind enough to answer in great detail.
Configure the project in Typescript as ChatGPT told me.
mkdir autoblog
yarn init
yarn add typescript ts-node tsc
yarn tsc --init
Create a blog post using the OpenAI API
Next, let's create a function to create a blog post using the OpenAI API.
First, install the openai SDK.
yarn add openai
Next, write a generateTextWithOpenAi function to generate text from openai. For this part, ChatGPT didn't give me an accurate answer, so I looked at the openai documentation and wrote the code.
import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const writeBlogPost = async (prompt: string) => {
const completion = await openai.createCompletion({
model: "text-davinci-003",
temperature: 0.7,
max_tokens: 3900,
prompt,
});
return completion.data?.choices?.[0].text;
};
Now, let's test the code we just wrote
const response = await writeBlogPost('I'm blogging an essay about the daily life of a developer. The title of the post is "The Daily Life of a Developer." Please write a long blog post of about 2000 words in Markdown format. And don't include the main title.');
console.log(response)
For a guide to prompting OpenAI to generate text, see documentation here.
As a result, OpenAI wrote the following.
Now all we need to do is save it to the database and auto-upload it to our blog. And for prompts to find images in the Unsplash API, see Reddit here.
Storing data in Firestore
It's faster and easier to code this by asking ChatGPT than by reading the Firestore API documentation. I asked ChatGPT how to store data in Firestore and got the following answer.
Then, using ChatGPT's code as a guide, write a createDocument function.
import firebase from "firebase-admin";
firebase.initializeApp({
credential: firebase.credential.cert(require("./serviceAccountKey.json")),
});
async function createDocument(title: string, body: string, tags: string, mainImage: string) {
try {
const firestore = firebase.firestore();
const newDocRef = firestore.collection("documents").doc();
await newDocRef.set({
title: title,
body: body,
tags: tags,
mainImage: mainImage,
});
console.log("Document written with ID: ", newDocRef.id);
return newDocRef.id;
} catch (error) {
console.error("Error adding document: ", error);
return error;
}
}
If you check the Cloud Firestore console, you can see that the data you just registered has been saved.
Admin: Jetadmin
It's not easy to manage data in the Cloud Firestore console environment, so we built an admin using Jetadmin. You can easily register and modify data by integrating Firestore like below.
That's it for today, I'll save the uploading to the blog for another time. I will use a blogging platform that allows me to integrate Google Analytics and Edsense.
Review
Coding with ChatGPT saved me a lot of time (naming functions, reading API documentation, etc.).
The cost of calling the OpenAI API is much lower than I expected. For the da Vinci engine, the best performing language model, it's $0.02 per 1000 tokens. 1,000 tokens is about 750 words.
While it's difficult to learn deep learning and build your own AI, it's very easy to develop AI using the OpenAI API.
In addition to automatic blogging, it would be interesting to create a consultation chatbot or Q&A service.
References
- "How to auto-generate dozens of blog posts in 2 minutes with chatGPT", Ilsaler Jangpiem, YouTube, 2022
'ChatGPT' 카테고리의 다른 글
(ChatGPT) Automating your blog with OpenAI 2 (0) | 2023.02.17 |
---|---|
(ChatGPT) Summarize and translate overseas YouTube into Korean with AI (0) | 2023.02.17 |
Tistory not showing up well in Google search - SEO, sitemap, duplicate content (0) | 2023.02.17 |
6 useful Chrome extensions for ChatGPT (0) | 2023.02.17 |
Ask ChatGPT How to Develop an Automated Blog Bot (0) | 2023.02.17 |