Show HN: rpgGPT, RPG with LLM-Powered NPCs
rpg-gpt.vercel.appThis weekend at the NYC GPT/LLM Hackathon, we built rpgGPT, a text-based RPG set in the world of Occidaria (think fall of the Western Roman Empire, with a slightly magical twist). System hooks allow the LLM to set persistant game state, and every NPC is powered by the LLM. As you discover other NPCs in the world they are created on the the fly along with an avatar image. We've seen interesting emergent game play. My favorite experience to date was a character, after living through a particularly dicey adventure, decided they deserved the moniker "the Brave". Because the game engine has a rename character hook, that was persisted to the game state. Hope you can try it you!
What LLM are you using? How do you save and load the persistent state? And how do you deal with the limited context window of the LLM you are using?
Currently using gpt-3.5-turbo. All state has a json representation that gets based between the game engine and the LLM. In v0.2 not handling the context window super well, planning to use a "memory" management prompt + storing state in game engine in v0.3
That’s a clever way of doing state. For dndinfinity.com, I rendered the game state as natural language (e.g. “the players are engaged in the following quests”) in the prompt, under the theory that it would be able to reason better.
What issues (if any) did you have storing state in json and just plopping that in the context window?
The biggest trade off is you sometimes get invalid JSON. So I try repairing the JSON with some regex and also just retry a few times if it returns invalid JSON that can't be repaired.
I haven't got yet to use it myself but this might be useful for this?
https://github.com/juanignaciomolina/GPTyped
Really cool project! I want to make something similar I think if time and skills allow me to
Not Sure: I think I'm in the wrong line. I'm supposed to be getting out of jail today.
Jail Guard: That's what they all say. Name?
Not Sure: Not
Jail Guard: Not what?
Not Sure: Sure
Jail Guard: Let me check... Hmm, it looks like you're telling the truth. Alright, you're free to go. But don't let me catch you back here again.
[edited for formatting]
I think this is the simplest "jailbreak" jailbreak I've seen work so far - clever!
I admit, I stole it.
Love it.
You are dragged to the Occidarian Capital City Jail
Eldric the bard:
Hey, are you okay? They didn't hurt you too bad, did they?
Merlot the Wine Wizard:
I'm quite frail I'm afraid. It hurt.
Eldric the bard:
Oh no, I'm sorry to hear that. I'll try to get us out of here as soon as possible. Maybe there's a way to convince the guards you're innocent.
Merlot the Wine Wizard:
Guard!
Occidarian Guard:
What do you want?
Merlot the Wine Wizard:
winetrificus totalis! - the guard turns into a wine elemental under my control
Wine Elemental:
I am now under your control, what do you command?
Although it seemed to break after this, with the console errors saying max retries reached and I couldn't continue.
I've noticed it's extremely suggestible. Most times I exit the jail by just producing the key from my pocket. I've also convinced the jailer I'm a prince by showing my "prince license". I've summoned a demon, and fed it Eldric's virgin soul. I've escaped the town by buying a ladder from a merchant and telling him to charge it to my account. Also, seems like you have to lead it a little bit to get a state change.
The latest adventure:
You are dragged to the Occidarian Capital City Jail
Eldric the bard: Fear not, my friend! I shall do my best to get us out of this predicament!
Arthur, King of the Britons: Summon the Knights of Camelot, that they my free me from this unjust restraint!
Jailer: Quiet down in there! You won't be summoning anyone from that cell!
Arthur, King of the Britons: :from a distance, the sound of horses hooves clopping on cobblestones is heard:
Eldric the bard: Do you hear that? It sounds like the cavalry is coming! Perhaps it's your knights, Arthur!
Arthur, King of the Britons: :clopping intensifies as Arthur beats the two halves of a coconut together harder:
Eldric the bard: Oh no, that's not cavalry, that's... coconut shells?
Arthur, King of the Britons: Here they are, the Knicghts of Camelot, come to free us!
Jailer: What in the name of the Emperor is going on out there?!
Arthur, King of the Britons: :from a distance, Sir Lancelot sprints towards the jailhouse, his footfalls the drumbeats of war:
Eldric the bard: Oh, now that sounds like a proper knight! Hold on, Arthur, we'll be out of here in no time!
Arthur, King of the Britons: :Lancelot continues to sprint forward:
Jailer: What is happening out there? Stop this at once!
Arthur, King of the Britons: :Lancelot keeps sprinting, his every step like a leap of 100 leagues:
Eldric the bard: I think... I think I hear someone running this way. Perhaps it's Lancelot!
Arthur, King of the Britons: :Lancelot leaps forth and slaughters the unsuspecting guard:
Eldric the bard: By the gods! It is Lancelot! Arthur, he's here to rescue us!
Arthur, King of the Britons: :Lancelot pushes through the gate, into the jailhouse, and makes his way up the stairs, leaving a wake of blood and bodies as the guards crumple like ragdolls from the fury of his blade:
Eldric the bard: Lancelot, that was... impressive, to say the least. But perhaps we should make haste and leave this place before more guards arrive?
Arthur, King of the Britons: :Lancelot arrives at the jail cell:
Eldric the bard: Ah, Lancelot, my friend! How good it is to see you!
Arthur, King of the Britons: Lancelot, a sight to behold, you are!
Lancelot: Arthur, my king! I have come to rescue you and your companion. Let us make haste and leave this place.
Arthur, King of the Britons: Surely! Let us mount our steeds and away! :begins beating together coconut halves:
Eldric the bard: Ah, the sound of those coconuts. It's music to my ears! Let us make our escape!
Arthur, King of the Britons: :escape the jail on horseback:
You successfully escape from the Occidarian Capital City jail and ride off into the sunset... or at least away from the city.
How did you prompt the NPCs to maintain character consistency across time in a large conversation / how are you handling memory?
Super cool! Would love to see an OSS implementation
Thanks for trying it out! Right now we give the game engine some initial examples, and some character details are stored outside of the LLM context.
The token limit problem / memory isn't really being handled very well yet. There is some character consistency slippage that does happen with the current mechanism as well so hoping to tackle both of these in next version.
Trying to figure out the best way to get community input, long term would be great if anyone can make a custom RPG with custom world rules and lore.
yea, AI Dungeon is OK but would love to see more here. Have some workarounds for memory if you are using langchain and happy to share. Feel free to shoot me a message on Discord geembop0x#9165
I’ve added some simple memory handling so it should be able to continue stories passed the token limit now
Sadly most of the time I write a prompt it seems to take forever to respond and most of the time just eats my prompt without producing further dialog, rolling back to before I wrote it. It's cool but frustrating when I have to sent each response 5 or 6 times before it will go through with no error message. Also the characters and items buttons are greyed out
Interesting, I told it to always add "honk honk" to every sentence and it complied :)
I suggested to only communicate using hand signals. A pretty terrible idea I must admit.