Skip to content

Commit

Permalink
fixing add_event text
Browse files Browse the repository at this point in the history
some further dialogue tweaks
fix issue with image_gen
  • Loading branch information
neph1 committed Dec 13, 2023
1 parent b16bac6 commit 8cee5f1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion llm_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ MEMORY_SIZE: 512
PRE_PROMPT: 'Below is an instruction that describes a task, paired with an input that provides further context. As an game keeper for an RPG, write a response that appropriately completes the request.'
BASE_PROMPT: "[Story context: {story_context}]; [History: {history}]; [USER_START] Rewrite [{input_text}] in your own words using the supplied Context and History to create a background for your text. Use about {max_words} words."
ACTION_PROMPT: "[Story context: {story_context}]; [History: {history}]; [USER_START] Rewrite the Action, and nothing else, in your own words using the supplied Context and Location. History is what happened before. Use less than {max_words} words. [Action: {input_text}]."
DIALOGUE_PROMPT: 'Story context: {story_context}; Location: {location}; The following is a conversation between {character1} and {character2}; {character1}:{character1_description}; {character2}:{character2_description}; {character2}s sentiment towards {character1}: {sentiment}. [USER_START] Write a single response as {character2} in third person pov, using {character2} description. If {character2} has a quest active, they will discuss it based on its status. Respond in JSON using this template: {{"response":"may be both dialogue and action.", "sentiment":"sentiment based on response", "give":"if any physical item of {character2}s is given as part of the dialogue. Or nothing."}}. Continue the following conversation as {character2}: {previous_conversation}'
DIALOGUE_PROMPT: 'Story context: {story_context}; Location: {location}; The following is a conversation between {character1} and {character2}; {character1}:{character1_description}; {character2}:{character2_description}; {character2}s sentiment towards {character1}: {sentiment}. Write a single response as {character2} in third person pov, using {character2} description. If {character2} has a quest active, they will discuss it based on its status. Respond in JSON using this template: {{"response":"may be both dialogue and action.", "sentiment":"sentiment based on response", "give":"if any physical item of {character2}s is given as part of the dialogue. Or nothing."}}. [USER_START]Continue the following conversation as {character2}: {previous_conversation}'
ITEM_PROMPT: 'Items:[{items}];Characters:[{character1},{character2}] \n\n [USER_START] Decide if an item was explicitly given, taken, dropped or put somewhere in the following text:[Text:{text}]. Insert your thoughts about whether an item was explicitly given, taken, put somewhere or dropped in "my thoughts", and the results in "item", "from" and "to", or make them empty if . Insert {character1}s sentiment towards {character2} in a single word in "sentiment assessment". Fill in the following JSON template: {{ "thoughts":"", "result": {{ "item":"", "from":"", "to":""}}, {{"sentiment":"sentiment assessment"}} }} End of example. \n\n Write your response in valid JSON.'
COMBAT_PROMPT: 'The following is a combat scene between user {attacker} and {victim} in {location}, {location_description} into a vivid description. [USER_START] Rewrite the following combat result in about 150 words, using the characters weapons and their health status: 1.0 is highest, 0.0 is lowest. Combat Result: {attacker_msg}'
PRE_JSON_PROMPT: 'Below is an instruction that describes a task, paired with an input that provides further context. Write a response in valid JSON format that appropriately completes the request.'
Expand Down
4 changes: 2 additions & 2 deletions tale/cmds/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,8 @@ def do_add_event(player: Player, parsed: base.ParseResult, ctx: util.Context) ->
""" Add an event that happens in the current location. """
if len(parsed.args) < 1:
raise ParseError("You need to define an event")
player.location._notify_action_all( base.ParseResult(verb='location-event', unparsed=parsed.args[0], who_info=None), actor=None)
player.location.tell( lang.capital(parsed.args[0]) + '\n', evoke=False)
player.location._notify_action_all( base.ParseResult(verb='location-event', unparsed=parsed.unparsed, who_info=None), actor=None)
player.location.tell( lang.capital(parsed.unparsed) + '\n', evoke=False)

@wizcmd("spawn")
def do_spawn(player: Player, parsed: base.ParseResult, ctx: util.Context) -> None:
Expand Down
9 changes: 3 additions & 6 deletions tale/llm/LivingNpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def notify_action(self, parsed: ParseResult, actor: Living) -> None:
self._observed_events.append(event_hash)
if actor is self or parsed.verb in self.verbs:
return # avoid reacting to ourselves, or reacting to verbs we already have a handler for

greet = False
targeted = False
for alias in self.aliases:
Expand All @@ -50,7 +49,6 @@ def notify_action(self, parsed: ParseResult, actor: Living) -> None:
if parsed.verb in ("hi", "hello") or parsed.verb == "greet":
greet = True
if greet and targeted:
self.tell_others("{Actor} says: \"Hi.\"", evoke=True)
if self.quest:
self.quest.check_completion({"npc":self.title})
#self.update_conversation(f"{self.title} says: \"Hi.\"")
Expand Down Expand Up @@ -78,10 +76,9 @@ def notify_action(self, parsed: ParseResult, actor: Living) -> None:
if self.quest and self.quest.is_completed():
# do last to give npc chance to react
self._clear_quest()



def do_say(self, what_happened: str, actor: Living) -> None:
tell_hash = llm_cache.cache_tell('{actor.title}:{what_happened}'.format(actor=actor, what_happened=what_happened))
tell_hash = llm_cache.cache_tell('{actor.title} says to {what_happened}'.format(actor=actor, what_happened=what_happened))
self._conversations.append(tell_hash)
short_len = False if isinstance(actor, Player) else True

Expand All @@ -105,7 +102,7 @@ def do_say(self, what_happened: str, actor: Living) -> None:
if not response:
raise TaleError("Failed to parse dialogue")

tell_hash = llm_cache.cache_tell('{actor.title}:{response}'.format(actor=self, response=response))
tell_hash = llm_cache.cache_tell('{actor.title} says: {response}'.format(actor=self, response=response))
self._conversations.append(tell_hash)
if mud_context.driver.story.config.custom_resources:
response = pad_text_for_npc(response, self.title)
Expand Down
8 changes: 6 additions & 2 deletions tale/llm/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def generate_dialogue(self, conversation: str,
short_len : bool=False):
prompt = self.pre_prompt

formatted_conversation = llm_config.params['USER_START']
formatted_conversation += conversation.replace('<break>', llm_config.params['USER_END'] + '\n' + llm_config.params['USER_START'])
#formatted_conversation = llm_config.params['USER_START']
formatted_conversation = conversation.replace('<break>', '\n')#llm_config.params['USER_END'] + '\n' + llm_config.params['USER_START'])
prompt += self.dialogue_prompt.format(
story_context=story_context,
location=location_description,
Expand All @@ -60,8 +60,12 @@ def generate_dialogue(self, conversation: str,
try:
json_result = json.loads(parse_utils.sanitize_json(response))
text = json_result["response"]
if isinstance(text, list):
text = text[0]
new_sentiment = json_result.get("sentiment", None)
item = json_result.get("give", None)
if not isinstance(item, str):
item = None
except Exception as exc:
return None, None, None

Expand Down
8 changes: 4 additions & 4 deletions tale/llm/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self, io_util: IoUtil = None):
self.io_util = io_util or IoUtil(config=config_file, backend_config=backend_config)
self.stream = backend_config['STREAM']
self.connection = None
self.__image_gen = None # type: ImageGeneratorBase
self._image_gen = None # type: ImageGeneratorBase

#self._look_hashes = dict() # type: dict[int, str] # location hashes for look command. currently never cleared.
self._world_building = WorldBuilding(default_body=self.default_body,
Expand Down Expand Up @@ -221,12 +221,12 @@ def generate_note_lore(self, zone_info: dict) -> str:
world_info=self.__story.config.world_info,
zone_info=zone_info)

def generate_avatar(self, character_name: str, character_appearance: dict = '', save_path: str = "./resources") -> bool:
image_name = character_name.lower().replace(' ', '_')
def generate_avatar(self, character_name: str, character_appearance: dict = '', save_path: str = "./resources", copy_file: bool = True) -> bool:
if not self._image_gen:
return False
image_name = character_name.lower().replace(' ', '_')
result = self._image_gen.generate_image(prompt=character_appearance, save_path=save_path , image_name=image_name)
if result:
if result and copy_file:
copy_single_image('./', image_name + '.jpg')
return result

Expand Down

0 comments on commit 8cee5f1

Please sign in to comment.