You've gained a new achievement
For the past month or so I've been obsessed with a book series that's apparently been popular and I just didn't realize - Dungeon Crawler Carl. Without giving too much away, it's basically about a person, and his glorious cat, who get caught up in a real world RPG. I'm currently on book 3 (of 8) and am enjoying every page of it. It's incredibly funny and cool at the same time. If you haven't checked it out yet, I highly recommend picking up the first book and giving it a shot. I don't think you'll regret it.
As I mentioned, the book series involves a man (and his cat, the cat is crucial) experiencing a real-world RPG and like a RPG, it's got achievements as the character progress through the dungeon. For those of you aren't gamers, most games now will give you an achievement for performing some task. These achievements give you nothing but bragging rights and a slight feeling of accomplishment, but some folks get really excited about them.
In the books, the main characters will also get achievements and typically the achievement is incredibly snarky and sarcastic. As an example:
You entered the dungeon wearing no pants. Dude. Seriously?
Reward: You've received a Gold Apparel Box!
And another:
Congratulations. You know how to open doors.
Reward: That sense of fulfillment you feel? That’s reward enough.
These almost always make me LOL and I thought - what if I could make a simple web tool to generate these on the fly? I did so, using Chrome's built-in AI feature, which as of today is still behind a flag, so if you want to play with this, you'll need to follow the instructions on which flags to enable in your browser. If you've done that, and don't care about how this tool was built, you can head over to the demo now: https://dcc.raymondcamden.com/
The Code
The code behind this was a rather simple usage of the Chrome Prompt API. Here's the code that initializes the session:
session = await LanguageModel.create({
initialPrompts:[
{
role: 'system',
content:
`Generate an achievement announcement in the style of
the Dungeon Crawler Carl series. You will be given a
prompt to base the achievement on, which will be an
ordinary, mundane task. The achievement you generate
should have the snarky, over the top prose associated
with the book.
do not comment about carl at all, or have any other output
except the achievement title, text, and rewards`
}
],
monitor(m) {
m.addEventListener("downloadprogress", e => {
console.log(`Downloaded ${e.loaded * 100}%`);
if(e.loaded === 0 || e.loaded === 1) {
$status.innerHTML = '';
return;
}
$status.innerHTML = `Downloading AI model, currently at ${Math.floor(e.loaded * 100)}%`;
});
}
});
Make note of the system instruction which is what guides the model when generating content. Your input is basically a "mundane" thing you've done, like wash dishes or take out the trash. When you've entered that and hit submit, I then simply get the achievement:
let achievement = JSON.parse(await session.prompt(input, {
responseConstraint: schema,
}));
Notice the responseConstraint value? This is how I get precise results back, in my case an achievement title, the text, and a list of rewards. This is defined earlier in my code:
let schema = {
"type": "object",
"properties": {
"title": {
"type":"string"
},
"achievementText": {
"type":"string"
},
"rewards": {
"type":"array",
"items":{
"type":"string"
}
},
},
"additionalProperties": false
};
And that's pretty much it. The rest of the code is straight up DOM manipulation.
The Design
As for the look and feel of the app, I made use of Cursor and one simple prompt:
im going to be building a tool that uses Chrome AI to generate random achievements in the style of Dungeon Crawler Carl. i need your help with a design. i dont need you to do any of the javascript, just create my scaffold for me. its one web page and the title should be, "DCC Achievement Generator". There is a prompt, "What mundane thing did you get done?", a form field for the task, and then it will render out the achievment.Achievements have a title, a body of text, and a list of rewards (bulleted list). Create a nice design for the achievement as well (just make something up for now)
I'm just now noticing the typo and thankfully Cursor didn't complain. I let it output my HTML and CSS and then simply copied that over to CodePen so I could start working on the actual implementation. I think the only work I needed to do was add some IDs to the HTML in order for my JavaScript to connect to what it needed to update. The design Cursor created was just fine:
In case you can't read that, my input was: i wrote a blog post and the achievement I received was:
By the gods...you *authored* a blog post? A digital missive of words, painstakingly crafted (or, let's be honest, hastily assembled) and disseminated across the ethereal web? A feat of remarkable… mediocrity? Fear not, adventurer! While not slaying a dragon or retrieving a legendary artifact, you have demonstrated a modicum of linguistic dexterity. A tiny flicker of creativity in the vast darkness of internet noise. Consider yourself mildly commended. It's not much, but it's… something.
Rewards:
- A digital badge of… acknowledgment.
- The fleeting satisfaction of knowing you’ve added to the collective human output.
- A slightly less judgmental stare from your cat.
- Potentially, an increase in internet karma. (Results may vary.)
Results May Vary
If you've got the flags enabled and try it out, please share your results, and let me know what you think. Feel free to fork the pen and modify to your heart's content. Also... Mongo is appalled!
See the Pen DCC Generator by Raymond Camden (@cfjedimaster) on CodePen.
Photo by Giorgio Trovato on Unsplash