04/14/2023
To generate an entire book using ChatGPT has been done before. However, unless you have access to GPT-4, you may run into issues and spend alot of time copy-pasting as ChatGPT tends to interrupting its response after around 400 words and loses its context even after saying "continue the above".
So, Here is my project: I made a low code Tkinter application in Python using turbo-3.5 api for creating what can be best described as a low-code programming language for AI applications. Instead of having to enter all the prompts manually over and over again, This software allows me to chain multiple prompts together to create more accurate and longer responses, and even other prompts. In the example below, I used the software to generate a 30000 word book with 7 chapters.
If the interest is high enough, I may open source it and start a youtube channel where I teach how to use it. For now, I will just share the algorithm and all the prompts to you for generating the book, so that you can build your own applications or even paste it into ChatGPT yourself. Note that the prompts may need to be modified as ChatGPT has limited context control compared to the API, so I recommend that you get the API key and write your own python script (with or without chatGPT) for this purpose:
----------------------------------------------------------------------------------
STEP 1: Outline Generation Prompt
"ChatGPT will generate a book for you with 50,000-100,000 words, consisting of chapters that are 3,000 words each. The outline should include a list of all chapters with a list of actions happening in each chapter. You would like twists included in the chapter outlines, but you want the story to be generated from scratch by ChatGPT. The book is for your personal reading only and should be a surprise to you, similar to purchasing a random book from Amazon.
Down below is an example of how the chapters shall be generated. Do not generate a title. Come up with a different story, as this example only chowcases the format:
Chapter 1: The Arrival
- The protagonist arrives in a small town to start a new job
- They meet their eccentric landlord and settle into their new apartment
- The protagonist takes a walk around town and discovers a mysterious abandoned building
Chapter 2: The Invitation
- The protagonist receives an invitation to a party from their co-worker
- They attend the party and meet a group of intriguing strangers
- One of the strangers reveals a secret about the abandoned building the protagonist discovered earlier
Chapter 3: The Investigation
- The protagonist decides to investigate the abandoned building with the help of their new friends
- They discover a hidden room filled with strange artifacts
- One of the artifacts appears to be cursed and causes the group to experience vivid nightmares"
Here you may to replace the chapter titles and action to adjust the theme of the book. I noticed that the book I generated had a different story, but still had an "artifact" as the main plot.
STEP 2: Characters prompt:
"I am going to write a book based on the outline below. Write a list of all the characters involved in the book. Each human character shall be assigned its own gender, name, age, profession and role in the book, made up by you unless otherwise stated in the outline. They shall all be of adult age. If there is an artifact, describe what it does or how the other characters discovers it.
The outline:
[)outline(]"
Replace [)outline(] with the outline you got from step 1
STEP 3: Chapter generation prompt:
"Write a long piece of text for chapter [)input(] mentioned in the progression. The chapter shall be coherent with, bot not repeat, previous chapters. The text should not contain any title. Include dialogs where there are characters talking with eachother.
Progression: "[)progression(]"
Characters:
[)characters(]"
For every X chapter, use this prompt as a template, replace [)progression(] with the first X chapters of the outline above, and [)characters(] with the response you got from step 2. The output will be a 500-700 word version of the chapter. For each paragraph that does not contain a dialog or quotes, perform STEP 4 and replace that paragraph with the output you got.
STEP 4: CHAPTER PARAGRAPH EXTENSION PROMPT:
"Extend the following paragraph based on the following rules:
- if it does not contain citations, extend the text so that it contains 3-4 times as many words. If the paragraph has 50 words, extend it to 200 words. If it contains 100 words, extend it to 300 words etc.
- Do not hallucinate details that may contradict the overall plot, as this paragraph is a part of a chapter within a book.
- If new people or revelations are introduced in the paragraph, Introduce them somewhere in the middle of the extended version.
The paragraph:
[)section(]"
replace [)section(] with the paragraph you are performing from step 3.
So there you have it, a set of prompt templates you can use to generate books for yourself, or others.
https://www.buymeacoffee.com/chatgptinsights