Inspiration

I enjoy trying to take things to the next level, gaming, and murder mysteries, so the idea of infinite murder mysteries that could be generated for Twitch chat felt like an intuitive and exciting prospect for me. Even in the nascence of AI, I dabbled in the idea of making this project happen, as it is the perfect addition to my stream to further engage with viewers. After seeing this contest, and witnessing the drastic improvements of AI, it felt absolutely clear that it was time to actually make this project happen. With young kids in the house, it's rare that I find time to stream, so having some standout features is also appealing.

What it does

When someone types !mystery in the streamer's chat, a murder mystery is automatically created by AI. To help the mystery be digestible for readers, where we don't just spam the chat with the different sections of the mystery, the different sections of the mystery are shared in chat over time. Once the entire mystery is shared, including suspects and clues, the viewers will have a chance to guess who did it via a poll.

How we built it

The Twitch bot was built using a python script that connects to Twitch's IRC chat server. When !mystery is typed in chat, the program uses the OpenAI api to automatically generate a mystery. In the prompt, there are very specific instructions on what to create as well as formatting, so that the information can all be parsed correctly. This information is processed into different sections that are slowly revealed to the viewers. Once all information is revealed, a poll occurs where participants can guess who they think did it. To successfully process the suspects and the murderer, that information is explicitly requested from the AI.

Partly for the requirements of this contest and partly to enhance the bot's functionality, I developed a second version that integrated additional Twitch features. I implemented OAuth authentication to securely access Twitch's APIs, allowing the bot to fetch user information and personalize interactions. I set up a Flask application to handle Twitch's EventSub webhooks, enabling the bot to respond to real-time events like subscriptions and bits donations. I also introduced a system where there is a certain amount of time that has to pass between mysteries that viewers could reduce by subbing or donating. That way there's a system for avoiding too many mysteries flooding the chat as well as a way to further viewer engagement.

Challenges we ran into

There was a bit of a learning curve in getting the Twitch bot setup, but this was overall relatively painless. The biggest issues came with processing the response from OpenAI properly. There were many small but irksome issues that resulted in things like the guesses not registering correctly, even if the user guessed the correct person, as well as many issues with segments of the mystery never being shared with the chat. After some iterating, these issues, as well as the smaller ones like better formatting, were resolved.

Accomplishments that we're proud of

It works in full and is a ton of fun. Even if I'm the only one who ever uses it, I'm still proud to have it and enjoyed making it. I'm also pretty proud of how the video representation of one of the mysteries turned out (this can be seen at the end of the video I included in this). It uses chatgpt for images, Runway for some animations from those images, and Suno ai for the dialogue/song - so it's an AI driven video for an AI generated mystery, which I felt also turned out really nicely.

What we learned

One of the biggest learnings was that, even with clear instruction, AI is still much more inconsistent in formatting, style, ideas, etc than one would expect. This meant handling more use cases than I expected and generally just handling more possible responses. I also gained a deeper understanding of Twitch's API and EventSub system.

What's next for Infinite Murder (Mysteries) on Twitch

Much further down the line, when generative video is more reliable and affordable, I would be highly interested in having the option to generate a viewable murder mystery experience.

Built With

Share this project:

Updates