Inspiration
I personally love playing choose your own adventure games! Rather than feeling like inevitable, predetermined sequences, they feel like you have control over the fate of your character, and that each decision you make really matters instead of feeling like just another objective you have to slog through to get to the end. However, traditionally, choose-your-own-adventure games have all still been "scripted" - eventually, you will have exhausted all the possibilities and there is nothing new to discover. There are only so many possible directions a human can make a story go! That's why I wanted to create a more immersive and personalized storytelling experience using the power of AI language models, where each story is completely unique and you might never repeat the same experience twice. AdventureGPT generates the story as you choose what happens, harnessing the enormous creative potential of ChatGPT-3.5-turbo to create the most interesting narrative experience for the player.
Additionally, choose-your-own adventure games have always confined you to what can happen in their game - however, with AdventureGPT, you can play out totally original scenarios and stories form your own imagination! AdventureGPT can take your own ideas and create a fun, thrilling, comedic, or romantic story out of them, regardless of whether you have any experience with writing or not! The ultimate goal of AdventureGPT is to have fun, and creative expression is critical in making the player's experience fresh and new every single time they open the app.
What it does
The idea of a choose-your-own adventure game is tried and true. You are presented with a setting and characters (potentially of your own creation), and you decide what happens next! You could be on a space station on Mars or on a boat in the Pacific Ocean - either way, you get the reins to the game. However, unlike most of these games where your choices are predetermined, with AdventureGPT, you don't know what's happening next. AdventureGPT progressively generates the story as you decide what happens, forming an exciting narrative that is a blast to play through! You are able to choose from 4 options each turn, for a maximum of 20 turns. Wherever you end up is up to you to decide!
How we built it
To build AdventureGPT, I used the OpenAI API to receive the story prompt and generate events and choices. When the user sends a story prompt, behind the scenes, I send a query to the API that not only includes the prompt but also a short context line that essentially asks ChatGPT to create a set of 4 options that will follow the story prompt, being A. B. C. and D. I then parse this response, splitting where A. B. C. and D. appear to create the set of 4 options the user can then select. Once the user selects an option, it sends this to the API and generates a new set of options! It repeats this process for however many turns the user has specified. This is the core gameplay loop, and while simple, it is intended to keep the user engaged with the events of their story!
For the tech itself, I used the OpenAI API with the gpt-3.5-turbo model. I built the web app using the Next/React frameworks and Tailwind.css. User authentication is performed with next-auth along with Google/Discord providers. I used React heavily for game states such as the game log and choice selections.
Challenges we ran into
AdventureGPT was took quite a bit of designing to pull off, and their were some bumps along the way:
First, I had to figure out how to actually get AdventureGPT to consistently return a response that I could iterate through to extract the choice selections for the user to progress the story. I had to specifically word the prompt to not include the story idea but also a short blurb reading
Create a small summary of what happened titled 'EVENTS:' and then create options for what to do with A. B. C. D.I tried this out on the ChatGPT app until I got the results I wanted!And now for the code itself. Oh boy. There were a couple issues to start - first of all, the API doesn't have a memory, so there is no way for the stock API to remember the story. Second, I had to figure out how to seamlessly render each event and choice selection. For the first issue, I essentially built my own memory system that takes the story prompt and then the previous actions as context, and sends that ALONG with the newest event the user takes to generate the next event. To solve the second issue, I decided to store the story as an array of objects, allowing me to display all of the events in the order they appear in. I even added a neat typewriter effect to make it appear like the actual ChatGPT!
Accomplishments that we're proud of
I think the game really surpassed my expectations in how imaginative it could be. Not only were the events able to match the narrative's detail and theme, but they were occasionally able to improve it by adding in creative events, characters, places, and ideas out of the blue! For example, while testing the game with an idea about a moon landing, I pushed it in a cosmic horror-y direction, but to my surprise, it came up with the twist that digging up the soil revealed that the moon was all cheese! I thought that this idea, while not exactly original, was exactly the kind of sarcastic ingenuity that I wanted the game to be able to imbue in its storytelling. In a choose-your-own-adventure game, the player decides the tone of the story, and AdventureGPT was easily able to not only understand but fire back with its own interpretation of the theme. The flexibility and adaptability of AdventureGPT in coming up with complex literary features like subverting expectations and introducing suspense are really just remarkable. While not perfect, I think this game is a great little idea "sandbox," where you can not only bring any of your dreams to life but also play them out!
What we learned
AI is fickle! When you prompt it, you have to be precise down to each word to explain exactly what you want the AI to generate. What's more, its response is really difficult to dig out as it is in layers of objects that you have to manually parse through to get the response. However, by looking deeper into the actual technical complexities of the ChatGPT API, I was also able to play around with its parameters, like frequency penalty and temperature, to test how I could get the best responses for stories. I eventually realized that a higher temperature was ideal for the app, as with a lower temperature, you tend to see more similar responses to similar prompts. Finally, I also had to research how a memory system could be implemented for the ChatGPT API by storing previous messages as contexts. All of this came together to build the actual game component of AdventureGPT!
What's next for AdventureGPT
One of the more ambitious ideas I had in mind for AdventureGPT would be to incorporate MidJourney into making AI-generated images of the actual events going on in the story. That way, the user could visually see what is going on in their story and the whole experience would be drastically more involved. However, I do not have access to their API, so this could definitely be a great way to improve the app in the future. Additionally, I could expand the scope of the game by adding the ability to have more options or turns. The opportunities are endless for creating a story-driven experience, where the only real limitation is how many words (or maybe even images) you can cram into a paragraph!
Built With
- next
- next-auth
- openai
- t3app
- tailwind
- typescript
Log in or sign up for Devpost to join the conversation.