Writing a Novel with GPT-4
I recently spent a weekend writing, from scratch, a 110,000-word novel. This included the time it took me to publish it to Amazon.
I cheated, of course, by using GTP-4. Here’s the final result:
Star-Crossed: Echoes of the Horizon: A Dance of Stars and Shadows
If you’d like to read the whole thing (which even I haven’t done), please contact me and I’ll be happy to send you the PDF version.
Seeding the Script
I wrote the novel by creating a Ruby script, using the ruby-openai gem, which gradually fleshed out the novel by prompting GPT-4 over and over again to write one section of one part of one chapter until it was all done.
The whole thing cost me $50 in OpenAI API credits.
But before fleshing out the novel I needed to determine its basic structure, and I did that by chatting to GPT-4, as shown below.
Selecting a Genre
Determine Amazon Search Keywords
Major Characters and their Backgrounds
Main Story Locations
Chapter Titles and Summaries
Title and Subtitle
Cover Image
Blurb for Amazon Listing
Author Name
Writing the Novel
With the basic structure determined, my script could take over. I created a JSON file that contained only information from these chat sessions. My script used this information to send prompts to the GPT-4 API. This process was fully automated, and I just needed to wait until the epilogue had been written before re-formatting the JSON and running Kindle Create to format the results for uploading to Amazon.
Each time the script sent a prompt to the OpenAI API, it would build the prompt using a summary of what had happened in the story, chapter, scene or beat so far, and ask GPT-4 to do one of the following:
- If starting a new chapter, list the scenes that should occur in the chapter, in order, together with a brief description of what happens.
- If starting a new scene, list the story beats in that scene.
- If starting a new story beat, flesh it out into multiple paragraphs.
The script also prompted GPT-4 to write a brief summary of what it had just written, and this was used to provide context for the next API call.
In this way the character and location names were preserved for the full length of the novel, as was the flow of chapters, scenes and story beats.
As GPT-4 is pretty good at writing a couple of paragraphs, it was an exercise in determining the best prompt to give it to ensure that those paragraphs naturally flowed on from what it had written previously, and served their purpose in making the story flow based on what was to follow.
It was a fractal-like process: list the chapters, then list the sections in each chapter, then list the story beats in each section, then write a few paragraphs for each beat, prompting only with text that GTP-4 itself had written previously. It all seemed to work rather well.
Well as in preserving long-distance story constraints, that is!