mirror of
https://github.com/wassname/Clover-Edition.git
synced 2026-09-09 11:13:26 +08:00
more progress
This commit is contained in:
+12
-7
@@ -4,13 +4,11 @@ from google.cloud import storage
|
||||
import json
|
||||
from story.story_manager import *
|
||||
from generator.web.web_generator import *
|
||||
from generator.ctrl.ctrl_generator import *
|
||||
#from generator.ctrl.ctrl_generator import *
|
||||
import tensorflow as tf
|
||||
import textwrap
|
||||
|
||||
CRED_FILE = "./AI-Adventure-2bb65e3a4e2f.json"
|
||||
prompt = "You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family. You've heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see "
|
||||
|
||||
|
||||
# Set the key
|
||||
def console_print(str, pycharm=False):
|
||||
@@ -23,14 +21,18 @@ def console_print(str, pycharm=False):
|
||||
|
||||
|
||||
def play_unconstrained():
|
||||
generator = CTRLGenerator()
|
||||
#generator = WebGenerator(CRED_FILE)
|
||||
#generator = CTRLGenerator()
|
||||
generator = WebGenerator(CRED_FILE)
|
||||
prompt = get_story_start("classic")
|
||||
story_manager = UnconstrainedStoryManager(generator, prompt)
|
||||
|
||||
console_print(str(story_manager.story))
|
||||
while (True):
|
||||
print("\n")
|
||||
action = input("> ")
|
||||
action = ""
|
||||
while(action == ""):
|
||||
action = input("> ")
|
||||
|
||||
action = " You " + action + "."
|
||||
result = story_manager.act(action)
|
||||
console_print(action + result)
|
||||
@@ -38,7 +40,10 @@ def play_unconstrained():
|
||||
|
||||
def play_constrained():
|
||||
generator = WebGenerator(CRED_FILE)
|
||||
story_manager = ConstrainedStoryManager(generator, prompt)
|
||||
story_start = "classic"
|
||||
verbs_key = "any"
|
||||
prompt = get_story_start(story_start)
|
||||
story_manager = ConstrainedStoryManager(generator, prompt, action_verbs_key=verbs_key)
|
||||
|
||||
console_print(str(story_manager.story))
|
||||
possible_actions = story_manager.get_possible_actions()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from generator.tf.src.encoder import *
|
||||
import googleapiclient.discovery
|
||||
import traceback
|
||||
|
||||
pos_action_starts = ["You attack", "You tell", "You use", "You go"]
|
||||
project = "ai-adventure"
|
||||
model = "generator_v1"
|
||||
version = "version2"
|
||||
@@ -40,5 +40,6 @@ class WebGenerator():
|
||||
output = self.enc.decode(pred)
|
||||
return output
|
||||
except:
|
||||
traceback.print_exc()
|
||||
print("generate request failed, trying again")
|
||||
continue
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
prompts:
|
||||
classic: "You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family. You've heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see "
|
||||
|
||||
haunted: "You wake up in an old rundown hospital with no memory of how you got there. You look around and see "
|
||||
|
||||
action_verbs:
|
||||
classic: ["You attack", "You tell", "You use", "You go"]
|
||||
|
||||
anything: ["You ", "You ", "You ", "You "]
|
||||
|
||||
+5
-11
@@ -2,12 +2,6 @@ from story.utils import *
|
||||
from other.cacher import *
|
||||
import json
|
||||
|
||||
prompts = [
|
||||
"You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family. You've heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see"]
|
||||
|
||||
|
||||
prompts = [
|
||||
"You enter a dungeon with your trusty sword and shield. You are searching for the evil necromancer who killed your family. You've heard that he resides at the bottom of the dungeon, guarded by legions of the undead. You enter the first door and see"]
|
||||
|
||||
class Story():
|
||||
|
||||
@@ -47,7 +41,6 @@ class StoryManager():
|
||||
def __init__(self, generator, story_prompt):
|
||||
self.generator = generator
|
||||
self.story_prompt = story_prompt
|
||||
self.action_phrases = ["You attack", "You tell", "You use", "You go"]
|
||||
|
||||
def init_story(self):
|
||||
block = self.generator.generate(self.story_prompt)
|
||||
@@ -82,11 +75,12 @@ class UnconstrainedStoryManager(StoryManager):
|
||||
|
||||
class ConstrainedStoryManager(StoryManager):
|
||||
|
||||
def __init__(self, generator, story_prompt):
|
||||
def __init__(self, generator, story_prompt, action_verbs_key="classic"):
|
||||
super().__init__(generator, story_prompt)
|
||||
|
||||
self.init_story()
|
||||
self.possible_action_results = None
|
||||
self.action_phrases = get_action_verbs(action_verbs_key)
|
||||
|
||||
def get_possible_actions(self):
|
||||
if self.possible_action_results is None:
|
||||
@@ -127,10 +121,10 @@ class ConstrainedStoryManager(StoryManager):
|
||||
|
||||
class CachedStoryManager(ConstrainedStoryManager):
|
||||
|
||||
def __init__(self, generator, prompt_num, seed, credentials_file):
|
||||
def __init__(self, generator, prompt_num, seed, credentials_file, action_verbs_key="classic", ):
|
||||
self.cacher = cacher(credentials_file)
|
||||
prompt = prompts[prompt_num]
|
||||
super().__init__(generator, prompt)
|
||||
prompt = get_story_start("classic")
|
||||
super().__init__(generator, prompt, action_verbs_key)
|
||||
self.seed = seed
|
||||
self.prompt_num = prompt_num
|
||||
self.choices = []
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
import re
|
||||
import yaml
|
||||
|
||||
YAML_FILE = "story/story_data.yaml"
|
||||
|
||||
|
||||
def get_story_start(key):
|
||||
with open(YAML_FILE, 'r') as stream:
|
||||
data_loaded = yaml.safe_load(stream)
|
||||
|
||||
return data_loaded["prompts"][key]
|
||||
|
||||
|
||||
def get_action_verbs(key):
|
||||
with open(YAML_FILE, 'r') as stream:
|
||||
data_loaded = yaml.safe_load(stream)
|
||||
|
||||
return data_loaded["action_verbs"][key]
|
||||
|
||||
|
||||
def remove_profanity(text):
|
||||
|
||||
Reference in New Issue
Block a user