Choose Your Own AIdventure - A CloudFlare Challenge

Paulo Henrique - Apr 9 - - Dev Community

This is a submission for the Cloudflare AI Challenge.

What I Built

(Honestly, I don't know how this isn't the priority when we talk about AIs, I mean, the storytelling potential is infinite...)

Being a kid from the '80s, I loved the series of "Choose Your Own Adventure" books - even in Brazil, they had some niche fans and translated editions. And text games from the past were also cool. Obviously, videogames and group RPGs took their place, but it is still something nice to waste time have fun.

I had this idea when AI started blooming, but most of the services had a prohibitive cost for a "fun only" project. The CloudFlare Challenge and the free tier gave me the chance to remove this code from my "brain cabinet labeled STUPID IDEAS" and put it into action. And for that, I'm truly grateful.

And how does it work? Select the type of adventure you want, then enter the name of your character and his class. The AI will start creating a story and give you three different actions so you can proceed. Then he will create a new part of the adventure based on your choice.

Oh! Fans of Easter Eggs: there's a nice one when you start playing 🥷🏽

Demo

You can test and play it here

Site Example

My Code

Choose your own AIdventure

This repository is a submission for the Cloudflare AI Challenge.

Demo

Demo can be seen and played here

Old School style RPG

Deployment

To deploy this project, clone it and upload the file from WK folder to a new CloudFlare Worker.

Then, create a .env file with:

NEXT_PUBLIC_CF_WORKER=

then run

  npm install
Enter fullscreen mode Exit fullscreen mode

to test :

  npm run dev 
Enter fullscreen mode Exit fullscreen mode

to build locally :

  npx @cloudflare/next-on-pages@1
Enter fullscreen mode Exit fullscreen mode

If everything is OK, then create a new CloudFlare Pages and upload the folder OR connect your github repository to it. Create the variable NEXT_PUBLIC_CF_WORKER before the first build




Journey

By the sweet JC in the sky, what a ride! First I got confused by how Workers, well, "worked", and I tried to scramble everything into a single file. When I finally noticed that Workers can act as an API and I can host the layout in CloudFlare pages, everything was a breeze - mostly. NextJS building in CloudFlare is a nuisance, but nothing that some questions to my beloved LLM couldn't solve.

I love how CloudFlare lets me create different endpoints with a single Worker. It's the best practice? Probably not, but for starters and proof of concepts it's wonderful.

There is a lot that I want to do with the idea behind the "Choose your own AIdventure", but I had less time this week to finish the project. The layout is bad, and I would love to make the system prompt better. Maybe after the challenge CloudFlare can sponsor the idea 👀

Multiple Models and/or Triple Task Types

Models Used:

llama-2-7b-chat-fp16 - for interaction with the user while playing

dreamshaper-8-lcm - each interaction brings an image so the user can "feel" the story.

. . . . . . . . .