Machina Scribit Logo
 

Machina Scribit: the machine writes1


Introduction bit

My name is Lee. I'm a former Stack Overflow taught dev now Solutions Architect2 which is cool and all but in my spare time I still like to play around with different ideas. Usually I play around with AR and game dev3 or get roped into random freebie app dev projects for family/friends4 to keep my skills sharp.

Recently,5 I've been playing around with ChatGPT and MidJourney. While there may be a day when they can replace devs, creatives, writers, politicians6, doctors, hotdog vendors7, etc., I don't think we are there yet. I mean even these little 500 word stories cost me $0.028 a day to generate!9

Anyway, this whole idea started with a CostCo hotdog.10 See, their was a discussion in the work Slack channel that ended up on the topic of Costco hotdogs.10 We nerdy lock folk have been taking topics and letting ChatGPT do it's magic to create hilarity, from suggestions of how to stop eating them to scientific explanations of why they are so good.

Well,11 one thing led to another and I asked ChatGPT to write a Post-Apocalyptic story about a world where CostCo hotdogs were currency.12 The story was so good I decided to get MidJourney to generate some supporting art, 15 minutes in Photoshop later,13 a few obligatory co-worker +1's in the Slack channel14 an idea was born...a daily AI story generator.


Techy bit15

The frontend side of this is dead simple,16 plain ol' HTML and JS with the awesome Skeleton handling the CSS columnar fanciness.

Where it gets cool is in the backend. I'm a huge fan of the standard AWS Serverless stack17 and have been using it for well over a decade now so figured that'd help me move fast18 and OpenAI19 has a great API that fronts the AI hardness20 for the natural language stuff, code gen stuff, and DALL-E image stuff for you all within some handy SDKs.

The Story Gen Lambda is triggered by a daily EventBridge Schedule around 2a.m. EST.21 That Lambda first does some quick date calculations to get everything formatted for the frontend and uses the day of the year to grab the genre of the day from an array of 36622 random genre names. Then it takes that genre name and makes three calls to the OpenAI API completions endpoint to generate the prompt, title, and story23 only setting model, prompt, and max_tokens values and letting everything else default.

Prompt Completions Request Body24
{
    model: "text-davinci-003",
    prompt: `Generate a unique and interesting writing prompt for a ${genre} short story`,
    max_tokens: 200,
}
Title Completions Request Body
{
    model: "text-davinci-003",
    prompt: `Write a story title for the prompt: '${prompt}'`,
    max_tokens: 200,
}
Story Completions Request Body25
{
    model: "text-davinci-003",
    prompt: `Write a long detailed fictional story (with a minimum length of 1000 words) in the ${genre} style based on the prompt: '${prompt}'`,
    max_tokens: 4000,
}

Once those return26 and are cleaned up,27 the page templates for the site and the email are just string literals in an imported module28 so it makes quick work of doing the replacements. Those are then pushed over to S3, an invalidation is sent to Cloudfront and a few seconds later the site is ready for the day.29 Other than that it's just boring ol' serverless stuff30 to serve the static site and hit you up daily with annoying emails.31

Happy Path Story Gen Sequence Diagram32
UML Sequence Diagram
Last bit33

Anyway,34 enjoy the ride as we see what the robot overlords35 come up with over the next year. I don't plan on spending any more time on this18 unless something changes with the API or it super breaks. I'll be sure to update if any other crazy ideas come along so stay tuned, otherwise enjoy the show!36


 
Get daily AI generated stories in your inbox
 

All stories and images generated by AI and not reviewed by humans so YMMV and no copywright claimed.

Site built by Lee/AI.