From 1355c37f5e20da94e69a2c03c0fafc013a5f5aa9 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 18 Nov 2019 17:53:05 +0000 Subject: [PATCH] update --- console_play.py | 10 +++++++--- generator/simple/simple_generator.py | 4 ++-- story/story_data.yaml | 23 +++++++++++++---------- story/story_manager.py | 4 ++++ story/utils.py | 2 +- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/console_play.py b/console_play.py index 9fe8457..8c4f8b2 100644 --- a/console_play.py +++ b/console_play.py @@ -14,8 +14,8 @@ CRED_FILE = "./AI-Adventure-2bb65e3a4e2f.json" def play_unconstrained(): generator = SimpleGenerator() - prompt = get_story_start("zombies") - context = get_context("zombies") + prompt = get_story_start("knight") + context = get_context("knight") story_manager = UnconstrainedStoryManager(generator) story_manager.start_new_story(prompt, context=context) @@ -35,7 +35,11 @@ def play_unconstrained(): #action = first_to_second_person(action) result = story_manager.act(action) - print(result) + if "you die" in result or "you are dead" in result: + print(result + "\nGAME OVER") + break + else: + print("\n" + result) if __name__ == '__main__': diff --git a/generator/simple/simple_generator.py b/generator/simple/simple_generator.py index 8828163..e225ccd 100644 --- a/generator/simple/simple_generator.py +++ b/generator/simple/simple_generator.py @@ -18,7 +18,7 @@ tf.logging.set_verbosity(tf.logging.ERROR) class SimpleGenerator: - def __init__(self, generate_num=65, temperature=0.4, top_k=40, top_p=0.8): + def __init__(self, generate_num=80, temperature=0.3, top_k=40, top_p=0.8): self.generate_num=generate_num self.temp = temperature self.top_k = top_k @@ -56,7 +56,7 @@ class SimpleGenerator: def prompt_replace(self, prompt): # print("\n\nBEFORE PROMPT_REPLACE:") # print(repr(prompt)) - if prompt[-1] == " ": + if len(prompt) > 0 and prompt[-1] == " ": prompt = prompt[:-1] #prompt = second_to_first_person(prompt) diff --git a/story/story_data.yaml b/story/story_data.yaml index 868d11c..04813b0 100644 --- a/story/story_data.yaml +++ b/story/story_data.yaml @@ -11,18 +11,13 @@ prompts: zombies: "You're on top of a building. You look over the city and see roaming undead everywhere. " -action_verbs: - classic: ["You tell", "You use", "You go", "You"] + wanderinginn: "You stumble through the grass, up the hill to the inn. The inn is dark and empty, the ruins of other structures around it. You look around and see " - anything: ["You", "You", "You"] + knight: "You wake up and continue your journey towards Larion Kingdom. You enter a dark forest that you must pass through. " -ctrl_verbs: - non_movement: ["take", "put", "give", "set", "keep", "help", "show", "pay", "read", "start", "stay", "call", - "change", "ask", "open", "look", "make", "say", "tell", "attack", "use", "fight", "scream", "yell"] - movement: ["walk", "go", "run", "move"] + necromancer: "It’s been five years since the Great Lich Lord was defeated and now it’s time to take over again.\nA messenger runs towards you and tells y that your new necromancer lord has already begun laying waste to the lands under your control. You look around at your necromancer captains and ask their advice. " -rooms: - haunted_hospital: ["lobby", "hallway", "parking", "roof", "pharmacy"] + scifi: "You have crashlanded on an some planet. You have a laser pistol and a pack of supplies. You leave your escape pod and see " contexts: zombies: "A few months ago a zombie infection broke out. You now are trying to survive on the ruins of what's left in the midst of zombie hordes. " @@ -31,4 +26,12 @@ contexts: apocalypse: "Long ago the bombs fell and the world ended. You are one of the few who is still alive. You are trying to survive by scavenging among the ruins of what is left behind. " - classic: "You are a knight in a deep dungeon. " \ No newline at end of file + classic: "You are a knight in a deep dungeon. " + + wanderinginn: "You are a young woman and an Innkeeper in a world of magic. " + + knight: "You are a knight on a quest to defeat the great dragon of Larion. You are armed with your sword and shield. " + + necromancer: "You are a necromancer in a world where undead spell casters rule and fight one another for power and control. " + + scifi: "You are a UN space marine with information crucial to the war effort that must get back to Earth. " diff --git a/story/story_manager.py b/story/story_manager.py index 78c646a..78bfc8e 100644 --- a/story/story_manager.py +++ b/story/story_manager.py @@ -45,6 +45,10 @@ class Story(): latest_result = self.context mem_ind = self.memory + if len(self.results) < 2: + latest_result += self.story_start + + while mem_ind > 0: if len(self.results) >= mem_ind: diff --git a/story/utils.py b/story/utils.py index 2c7bf52..bcba557 100644 --- a/story/utils.py +++ b/story/utils.py @@ -80,7 +80,7 @@ def cut_trailing_sentence(text): et_token = text.rfind("<|endoftext|>") if et_token != -1: - last_punc = min(last_punc, et_token+1) + last_punc = min(last_punc, et_token-1) act_token = text.find(">") if act_token != -1: