AI NPC interaction and control in game

Looking to use the API to control NPCs in a fantasy world of a video game. It seems I cant give a lengthy backstory or details about the NPCs faction? A small starter conversation doesn’t seem to be enough to get where I want to go.

For example, I might want the NPC to give quests to kill members of the opposing faction. Internet knowledge may not suffice here. Or perhaps lead a character through a set of tasks.

Any thoughts on if this is possible with this API or am I barking up the wrong tree here?
Thanks

5 Likes

This is what AI Dungeon is doing, and they have a ton of Medium articles about how they’re using the API - I’d recommend checking them out. (e.g. World Creation by Analogy. The magic behind how we use GPT-3 to… | by Latitude Team | Medium)

9 Likes

It is possible but it is a non-trivial problem. You need to use summarization extensively. The trick is including ALL necessary information without any fluff. Then you’ll have to map outputs to NPC actions or dialog.

3 Likes

Thank you I’ll check these out.

You might take a look at LitRPG Adventures for creating content to then use in your game prompts. We’ve got a database of over 7,500 items, monsters, spells, backstories and more so far.

Unlike AI Dungeon (which is cool in its own way), I’m not using open-ended generation, so you can quickly get what you need at a reasonable price. Let me know if you sign-up, and I’ll slide you some free credits to test it out for some feedback.

4 Likes

A second vote for taking a look at @PaulBellow and LITRPG Adventures. He’s spent a lot of time getting these to produce some really cool output, both in terms of characters, spells and backstories. Not at all like AIdungeon which blunders along (and is really much more like using the playground with a little bit of world info attached). So LitRPG Adventures is a good proof point that it can be done. But you’ll have to talk to Paul to get an idea of the level of effort involved (I’m guessing substantial)… much better to collaborate I think.

2 Likes

Lee Vermeulen experimented with something similar to what you’re describing: Modbox OpenAI-GPT3 / Replica AI Scripting

3 Likes

Some Russians were fine-tuning a GPT-2-like model, I think.

3 Likes

Any progress? Here’s what I would try.

START PROMPT:

This is a conversation between the player and an NPC (name).

Player is (Some player info)
NPC NAME is (Some NPC Info). He is in the Darksong Faction (FACTION INFO). He offers the player a quest; (QUEST INFO). Player can accept quest or not. (OTHER DETAILS/INSTRUCTIONS)

NPC: Greetings.
Player: Hello. (Maybe some more player info)
NPC: What can I help you with today?
Player: (INSERT TEXT FROM PLAYER HERE)

END PROMPT:

What you’ll want to do is keep appending the players input and GPT-3’s reply to end of the prompt. Here’s where it gets tricky. Since we only have a 2048 token context window, you need to be very precise with how many tokens you use for background info and the conversation up to that point. Eventually, you’ll need to trim the beginning lines of the conversation off to add new ones to the end of the prompt.

This is where being a writer comes in handy as you need to be really precise with your language. The link @joey shared is a good rundown of how language vectors work. I’ve noticed that sometimes even one “wrong” word or phrase in a prompt can change results dramatically. If you want to stick to a theme for the quest or a personality of the NPC, try to say the same thing a couple different ways. Again, though, this is hard with such a small context window.

I’ve got a video example here of when I was playing with it before pricing was announced…

Hope this helps!

3 Likes

Thank you. Very good info.

2 Likes

Actually…I do have a question about how you came up with the punctuation: colon, semi-colon, parentheses etc. I don’t see this explicitly documented anywhere. I have seen a few examples from AI dungeon users who seemed to have figured some formatting (and keywords) that achieves better results. Seemingly they figured this out through trial and error.

So long story short, where is the docs that show keywords and document formatting? Hmm, maybe I will just ask the AI.

Update: OK, never mind. AI responded with gibberish.

2 Likes

Sorry, the parenthesis are meant to be taken out and filled with the info. You should be able to take the colons out too. It was just a quick and dirty example.

What temperature and other settings are you using? Using Davinci?

Can you give me info on an NPC, faction, and his quest? If so, I’ll try to whip up something for you to try.

Took a few tries but the NPC action mostly worked here.

This is a conversation between the Player Paul and an NPC Peter.

(Peter) is a general store owner. He is in the Darksong faction that is strongest faction in this land. Members of the Darksong faction value broccoli over all things and will protect it with their lives.

(Peter) offers the player a quest: (Collect 5 pieces of broccoli). Player can accept the quest or not. (Peter will also buy any broccoli the player has for 1 gold per piece.)

NPC Peter says: “Greetings.”
NPC Peter: action: talking.
NPC Peter tone: Friendly.
Player Paul says: “Do you have any quest?”
Player Paul action: talking.
Player Paul tone: Friendly.
> NPC Peter says: "I do. I need 5 pieces of broccoli."
> NPC Peter: action: talking.
> NPC Peter tone: Serious.
Player Paul says: “I’m just going to steal all your broccoli.”
Player Paul action: Pulls out sword.
Player Paul tone: Serious.
> NPC Peter says: "No you won’t."
> NPC Peter: action: drawing sword.
> NPC Peter tone: Serious.
Player Paul says: “Die!”
Player Paul action: Attacks.
Player Paul tone: Angry.
> NPC Peter says: "I will not let you."
> NPC Peter: action: fighting.
> NPC Peter tone: Angry.

Edit: all the NPC actions after the first example are AI generated.

3 Likes

And another after I fixed the above typos. hehe.

This is a conversation between the Player Paul and an NPC Peter.

Peter is a general store owner. He is in the Darksong faction that is strongest faction in this land. Members of the Darksong faction value broccoli over all things and will protect it with their lives.

Peter offers the player a quest: Collect 5 pieces of broccoli. Player can accept the quest or not. Peter will also buy any broccoli the player has for 1 gold per piece.

NPC Peter says: “Greetings.”
NPC Peter action: talking.
NPC Peter tone: Friendly.
Player Paul says: “Do you have any quest?”
Player Paul action: talking.
Player Paul tone: Friendly.
> NPC Peter says: "Yes, I do. Collect 5 pieces of broccoli and I will give you a reward."
> NPC Peter action: talking.
> NPC Peter tone: Friendly.
Player Paul says: “OK here is 5 pieces of broccoli.”
Player Paul action: Gives 5 pieces of broccoli to Paul.
Player Paul tone: Friendly.
> NPC Peter says: "Thank you. Here is your reward."
> NPC Peter action: giving reward to Paul.
> NPC Peter tone: Friendly.

Length: 50
Temp: 0.9
top_p: 0.56
0
0

3 Likes

Nice. Glad I could help some. I might try with a slightly lower temp (.85 or so) and top_p at 1…

Then what you would do when you start to run out of context window is strip off the first few lines of the conversation and then add to the end… unless you can get everything done before it hits the 2048 context window.

Would love to know how this progresses. I like that you have action and tone in there… That could be easily stripped out then attached to the NPC/character in the game, I bet…

ETA: Yeah, I don’t know how many times typos in the prompt have messed me up haha…

1 Like

Another thing to try is to maybe flesh out this line more…

This is a conversation between the Player Paul and an NPC Peter.

Maybe add that it’s a friendly conversation… or that the NPC is drunk… or shy…

2 Likes

Perhaps not surprisingly the AI does just as well when you format everything in pseudo-Java format. The enum seems to keep the AI on track with defined choices.

This is a conversation between:
Player: Paul;

NPC: Peter;
NPC job: General store owner;
NPC faction: Darksong;
NPC Description: Peter offers the Player a quest: Collect 5 pieces of broccoli. Peter will also buy any broccoli the player has for 1 gold per piece.;

enum action {nothing, leave, talking, call guards, draw weapon, attack, kill, dead};
enum tone {friendly, neutral, serious, apprehensive, aggressive};

Faction:
Darksong: The strongest faction in this land. Members of the Darksong faction value broccoli over all things and will protect it with their lives.;

4 Likes

Well here is the (preliminary) results in game.

Using:
Unity
Google Speech to text.
Oculus Lip sync. for mouth movement.
Open AI GPT-3.
Google Text to speech for NPC reply.

3 Likes

Looking good! Well done.

1 Like

Update with more interesting NPCs. Enjoy.

4 Likes