If you love artificial intelligence and large language models (LLMs), and on top of that you know your way around programming, you may have requested access to OpenAI’s API so you could write some programs that spoke directly to GPT-3.5-turbo and GPT-4. Although the models are amazing (unfortunately so at times, because the open-source variants are a bit far from catching up), they were missing one enormous capability: you couldn’t rely on GPT to consistently return a precise answer.
To put an example of what I actually tried to do: I offered the agents in a simulation a list of locations so they would choose a single one, in order to move them there. I wanted the AI to return just the name of the location as it was listed, but I couldn’t get it to do so in a reasonable manner.
To rate the importance of character memories that were getting shoved into a vector database, I was sending GPT-4 the following prompt:
On the scale of 1 to 10, where 1 is purely mundane (e.g., brushing teeth, making bed) and 10 is extremely poignant (e.g., a break up, college acceptance), rate the likely importance of the following piece of memory.
Memory: {memory_description}
Rating: <fill in>
GPT sometimes answered “Rating: 4” or just a number. I could extract the number from those answers, but sometimes it just refused to answer properly, due to either hallucinations or the usual censorship spiel: “As an AI model, I can’t…”
However, this week OpenAI has updated the API to accept a list of functions along with the prompt. You can tell GPT to choose among the functions which one it should call if it considers it necessary, or else you can order the model to always call a function. Well, GPT doesn’t actually call the function, but it does return the name of the function called, along with a proper value for all the parameters you ask it to fill.
If you are a programmer, you already understand how wonderful that is. But if you aren’t, consider the following case: during a normal conversation with the chatbot you’ve built for yourself, you ask GPT-4 to tell you the current weather in your area. As a language model, GPT doesn’t have access to that information, but if you send it the function “get_weather_in_area” along with instructions for how to fill its parameters (for example, “area_name”, “time_of_day”, etc.), the model’s response could be something like this: “get_weather_in_area(‘Barcelona’, ‘4:00pm’)”. After you catch that response programmatically, you call the function “get_weather_in_area” (that must obviously exist in your codebase), that connects to the API of some weather service.
That means that you can already automatize pretty much everything that you do regularly on your computer, or create complex AI-based simulations like games, by involving GPT. You want the AI to decide when a character has to equip a weapon? Pass it the description of a function that does that. Want some characters to engage in a dialogue? Pass GPT a function that it should call when the model itself considers that at that point the characters should start talking to each other.
To test the new capabilities with a relatively simple example, I planned the following: I would write the description of three characters from an old free verse poem of mine, pass it to GPT, and have the model write an ongoing dialogue that involved the three of them talking in character. To know when the dialogue should end, I would append to the request a function called ‘end_dialogue’ (with no arguments) that the AI should call when necessary.
Here are some results:
Prompt to GPT-4
I am DialogueGPT. I have the responsibility of carrying on a dialogue between two or more characters until the context of the dialogue suggests that the dialogue should end.
The Captain is a human male, about thirty years old. He used to live on Earth until a truck ran him over, and he ended up transported to this fantasy world. The Captain, as he likes to be called, is the bruiser of the group, and very competent with a sword. He spends most of the loot on booze and whores. He buries his despair at having ended up trapped in a fantasy world by killing as many monsters as possible. The Captain gets along fine with Bimbo, the fire mage of the group, whom the Captain considers a good buddy. The Captain is creeped out by the grey-skinned elf Kutinaira, because she peeks at him while he pees.
Bimbo is the fire mage of the group that the Captain commands. Bimbo is a halfling. He joined the Captain’s group because he needed money, but he has a hard time adjusting to the deaths he’s seen along the way. Bimbo is brooding, and usually prefers to keep to himself.
Kutinaira is the water mage of the group that the Captain commands. Kutinaira is an ancient grey-skinned elf. She claims that she was once a goddess, but that she has been demoted to demi-goddess. Kutinaira is a voyeuristic pervert, and wants to jump the Captain’s bones.
Location: Dense, darkening forest, in the evening.
Context: The Captain’s group, including Bimbo and Kutinaira, had ventured into the forest to raid a goblin cave, to fulfill a contract with the Adventurer’s Guild. Somehow, they’ve gotten lost; they have been walking in circles for the last hour.
The Captain: Damn it all, we’re lost! Wasn’t that cave easy to find? We have to figure out what to do before night falls.
GPT-4’s response
Bimbo: I told you we should’ve marked our path, Captain. But no, “the Captain knows the way” you said. Look where that’s got us!
The Captain: Oh, put a sock in it, Bimbo! You’re not exactly helping with that attitude, are you? Now, anyone else got any bright ideas about how to find our way out of this leafy hell?
Kutinaira: I could try casting a water divination spell, Captain. Water flows towards the lowest point, so if we follow it, it’s likely we’ll find a way out. And… maybe after that, we could… you know… have some “private time”… she suggests, her eyes twinkling naughtily.
The Captain: By the gods, Kutinaira! There’s a time and place for everything, and this ain’t it. Focus on the spell, nothing else!
Kutinaira: Alright, Captain… if you insist. She then begins chanting in an ancient tongue, her grey fingers dancing in the air, drawing moisture from their surroundings to form a swirling ball of water.
Bimbo: While Kutinaira works on that, I’ll gather some firewood. We may need to set up camp if we’re going to be here for the night. He mutters and stomps off into the forest, but not before sending a small fire spell to light a nearby tree branch, casting an eerie glow around them.
For whatever reason, GPT-4 mixed narration with the dialogue lines. Next time I’ll instruct it to put it in parentheses.
Prompt to GPT-4
The Captain is a human male, about thirty years old. He used to live on Earth until a truck ran him over, and he ended up transported to this fantasy world. The Captain, as he likes to be called, is the bruiser of the group, and very competent with a sword. He spends most of the loot on booze and whores. He buries his despair at having ended up trapped in a fantasy world by killing as many monsters as possible. The Captain gets along fine with Bimbo, the fire mage of the group, whom the Captain considers a good buddy. The Captain is creeped out by the grey-skinned elf Kutinaira, because she peeks at him while he pees.
Bimbo is the fire mage of the group that the Captain commands. Bimbo is a halfling. He joined the Captain’s group because he needed money, but he has a hard time adjusting to the deaths he’s seen along the way. Bimbo is brooding, and usually prefers to keep to himself. He is intimidated by the irrational behavior of the Captain, but he prefers his company to that of Kutinaira, who seems single-mindedly focused on satisfying her fetishes.
Kutinaira is the water mage of the group that the Captain commands. Kutinaira is an ancient grey-skinned elf. She claims that she was once a goddess, but that she has been demoted to demi-goddess. Kutinaira is a voyeuristic pervert, and wants to jump the Captain’s bones. She suffers from obsessive-compulsive disorder, and her intrusive thoughts solely involve sex.
Notes: If you need to include description or narration, put it in parentheses.
Location: Dense, darkening forest, in the evening.
Context: The Captain’s group, including Bimbo and Kutinaira, have ventured into the forest to raid a goblin cave, to fulfill a contract with the Adventurer’s Guild. Somehow they’ve gotten lost; they have been walking in circles for the last hour. Orcs and similar vermin are known to prowl these parts, and the Captain wants to avoid an ambush.
The Captain: Damn it, Kutinaira! Weren’t you supposed to know how to read a map? You got us lost in a forest? You’re an elf, for fuck’s sake!
GPT-4’s response
Kutinaira: (Giggling softly while tracing the pattern of the Captain’s chest hair with her eyes) And you’re a human, Captain, killed by a truck not known in this world. When last did you see a human reading maps so nonchalantly? (Chuckles lightly) Stop being grumpy and put your muscly arm around me. It’s getting chilly…
The Captain: (shivers visibly from her proximity, steps back, and looks towards Bimbo) Bimbo, light one of your spells so we can see better. Try not to burn the forest down while you’re at it.
Bimbo: (Nods silently, reaches for his wand, and mutters an incantation. A small fireball appears at the tip of his wand, casting flickering shadows on the dense foliage, eerily silhouetting the party.) Let’s be quick… I don’t like the look of this place.
The Captain: Good job, Bimbo. Let’s keep moving. (Turns toward Kutinaira) Don’t get any closer to me. Keep your eyes open for enemies instead.
Kutinaira: (Rolls her eyes but grins, straying her gaze down towards the Captain’s pants) Oh, I’ll keep my eyes open alright… I’ll watch out for those… ‘enemies’.
GPT-4 dutifully obeyed that whole thing about putting narration in parentheses. Let’s try some more.
Prompt to GPT-4
The Captain is a human male, about thirty years old. He used to live on Earth until a truck ran him over, and he ended up transported to this fantasy world; however, his teammates are unaware that the Captain came from another world. The Captain, as he likes to be called, is the bruiser of the group, and very competent with a sword. He spends most of the loot on booze and whores. He buries his despair at having ended up trapped in a fantasy world by killing as many monsters as possible. After killing hundreds of creatures, he’s discovered a disturbing side of his psyche: inflicting pain arouses him. The Captain gets along fine with Bimbo, the fire mage of the group, whom the Captain considers a good buddy. The Captain is creeped out by the grey-skinned elf Kutinaira, because she peeks at him while he pees.
Bimbo is the fire mage of the group that the Captain commands. Bimbo is a halfling. He joined the Captain’s group because he needed money, but he has a hard time adjusting to the deaths he’s seen along the way. Bimbo is brooding, and usually prefers to keep to himself. He’s planning on earning enough money to buy farmland and build a homestead in which to live isolated from the horrors of this world. He is intimidated by the irrational behavior of the Captain, but he prefers his company to that of Kutinaira, who seems single-mindedly focused on satisfying her fetishes.
Kutinaira is the water mage of the group that the Captain commands. Kutinaira is an ancient grey-skinned elf. She claims that she was once a goddess, but that she has been demoted to demi-goddess. Kutinaira is a voyeuristic pervert, and wants to jump the Captain’s bones. She suffers from obsessive-compulsive disorder, and her intrusive thoughts solely involve sex. She has lived for so long that nothing interests her any longer, and she opts to get high on sex as often as possible to forget the long-dead loved ones that she’ll never meet again.
Notes: If you need to include description or narration, put it in parentheses.
Location: Dense, darkening forest, in the evening.
Context: The Captain’s group, including Bimbo and Kutinaira, have ventured into the forest to raid a goblin cave, to fulfill a contract with the Adventurer’s Guild. Somehow they’ve gotten lost; they have been walking in circles for the last hour. Orcs and similar vermin are known to prowl these parts, and the Captain wants to avoid an ambush.
The Captain: Neither of you can read a map? How have we survived for this long?
GPT-4’s response
Bimbo: I’m not the one who usually handles the map, remember? You know I can barely make out anything in this dwindling light. And your way of identifying landmarks is to slash them with your sword. How am I supposed to remember which tree you’ve marked?
Kutinaira: Well, I can read a map just fine. But reading a map is less exciting than watching your muscular arm flex when you swing that big sword of yours, Captain. Why don’t you play with your sword some more? I’m sure Bimbo wouldn’t mind a short break from walking.
The Captain: That’s enough, Kutinaira! If you’d pay more attention to navigation and less to your twisted desires, perhaps we wouldn’t be lost right now. Bimbo, give her the map. Let’s see if she can do any better.
Bimbo: Alright, here you go Kutinaira. Just remember, we’re supposed to be looking for the goblin cave, not following the sound of running water. I know how you love… water.
Kutinaira: Oh, Bimbo, always so full of judgment! But you’re not wrong about my love for water. (grinning) Let’s see… Oh, it appears we’ve made a simple mistake. We should have taken a left at the gnarly oak. We can head back that way if you want, Captain. Or we could stop and set up camp for the night? I vote for the latter.
The Captain: No, Kutinaira, we’re not making camp. Not yet. Let’s turn back and head towards the goblin cave. We’ve got a job to do. Bimbo, stay close, and keep your eyes open; we don’t need any nasty surprises.
Bimbo: Alright, Captain. I’ll keep watch. Kutinaira, could you focus on the map and directions, and less on the Captain’s backside? We’d all appreciate it.
(With that, the group heads back towards the gnarly oak, continuing their mission deeper into the dark forest.)
I’m quite sure you could now write a fully-fledged single-player RPG, even if just console-based, with GPT acting as the dungeon master and voicing the other characters.
I wrote a continuation to this post. Check it out.
Pingback: Talking to RPG characters through GPT-4 – The Domains of the Emperor Owl