forked from latitudegames/AIDungeon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
play_dm.py
executable file
·51 lines (38 loc) · 1.33 KB
/
play_dm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
import os
import sys
import time
from generator.gpt2.gpt2_generator import *
from generator.human_dm import *
from play import *
from story.story_manager import *
from story.utils import *
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
class AIPlayer:
def __init__(self, generator):
self.generator = generator
def get_action(self, prompt):
return self.generator.generate_raw(prompt)
def play_dm():
console_print("Initializing AI Dungeon DM Mode")
generator = GPT2Generator(temperature=0.9)
story_manager = UnconstrainedStoryManager(HumanDM())
context, prompt = select_game()
console_print(context + prompt)
story_manager.start_new_story(prompt, context=context, upload_story=False)
player = AIPlayer(generator)
while True:
action_prompt = story_manager.story_context() + "What do you do next? \n> You"
action = player.get_action(action_prompt)
print("\n******DEBUG FULL ACTION*******")
print(action)
print("******END DEBUG******\n")
action = action.split("\n")[0]
punc = action.rfind(".")
if punc > 0:
action = action[: punc + 1]
shown_action = "> You" + action
console_print(second_to_first_person(shown_action))
story_manager.act(action)
if __name__ == "__main__":
play_dm()