Skip to content

Commit

Permalink
Merge pull request #69 from neph1/update-v0.24.3
Browse files Browse the repository at this point in the history
Update v0.24.3
  • Loading branch information
neph1 authored Feb 16, 2024
2 parents 47811d0 + 85f8b8e commit d157128
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
9 changes: 5 additions & 4 deletions llm_config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
WORD_LIMIT: 200 # max number of words the model is encoraged to generate. not a hard limit
SHORT_WORD_LIMIT: 25 # max number of words when asked to write something short. not a hard limit
BACKEND: "kobold_cpp" # valid options: "openai", "llama_cpp", "kobold_cpp"
BACKEND: "kobold_cpp" # valid options: "openai", "llama_cpp", "kobold_cpp". if using ooba, use and modify openai template
MEMORY_SIZE: 512
DIALOGUE_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."}}'
ACTION_TEMPLATE: '{{"goal": reason for action, "thoughts":thoughts about performing action, 25 words "action":chosen action, "target":character, item or exit or description, "text": if anything is said during the action}}'
UNLIMITED_REACTS: False
DIALOGUE_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."}}]'
ACTION_TEMPLATE: '[{{"goal": reason for action, "thoughts":thoughts about performing action, 25 words "action":chosen action, "target":character, item or exit or description, "text": if anything is said during the action}}'
ITEM_TEMPLATE: '{{"name":"", "type":"", "short_descr":"", "level":int, "value":int}}'
CREATURE_TEMPLATE: '{{"name":"", "body":"", "mass":int(kg), "hp":int, "type":"Npc or Mob", "level":int, "unarmed_attack":One of [FISTS, CLAWS, BITE, TAIL, HOOVES, HORN, TUSKS, BEAK, TALON], "short_descr":""}}'
EXIT_TEMPLATE: '{{"direction":"", "name":"name of new location", "short_descr":"exit description"}}'
Expand Down Expand Up @@ -35,6 +36,6 @@ PLAYER_ENTER_PROMPT: '<context>{context}</context> Zone info: {zone_info}; Npc e
QUEST_PROMPT: '<context>{context}</context> Zone info: {zone_info}; Character: {character_card};\n[USER_START] Using the information supplied inside the <context> tags, {character_name} needs someone to perform a task. Based on the following input, come up with a suitable reason for it, using {character_name}s personality and history. Task info: {base_quest}. Fill in this JSON template and do not write anything else: {{"reason":""}} \n\n '
NOTE_QUEST_PROMPT: '<context>{context}</context> Zone info: {zone_info};\n[USER_START]Using the information supplied inside the <context> tags, generate a quest that starts from reading a note. The reader must find and talk to a person. Fill in the following JSON template and write nothing else.: {{"reason": "only what the note says. 50 words.", "type":"talk", "target":"who to talk to", "location":"", "name":"name of quest"}}'
NOTE_LORE_PROMPT: '<context>{context}</context> Zone info: {zone_info};\n[USER_START]FUsing the information supplied inside the <context> tags, decide what is written on a note that has been found. Use the provided story and world information to generate a piece of lore. Use about 50 words.'
ACTION_PROMPT: '<context>{context}</context>\n[USER_START]Act as as {character_name}.\nUsing the information supplied inside the <context> tag, pick an action according to {character_name}s description and mood. If suitable, select something to perform the action on (target). The action should be in the supplied list and should be related to {character_name}s thoughts. Build on events in "History" without repeating them. Respond using JSON in the following format: """{action_template}""". Continue the sequence of events: {previous_events}'
ACTION_PROMPT: '<context>{context}</context>\n[USER_START]Act as as {character_name}.\nUsing the information supplied inside the <context> tag, pick an action according to {character_name}s description and mood. If suitable, select something to perform the action on (target). The action should be in the supplied list and should be related to {character_name}s goal and thoughts. Build on events in "History" without repeating them. Respond using JSON in the following format with up to 3 actions: """{action_template}""". Continue the sequence of events: {previous_events}'
USER_START: '### Instruction:'
USER_END: '### Response:'
11 changes: 4 additions & 7 deletions tale/llm/LivingNpc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tale.llm.item_handling_result import ItemHandlingResult
from tale.llm import llm_config
import tale.llm.llm_cache as llm_cache
from tale import lang, mud_context, story
from tale.base import ContainingType, Living, ParseResult
Expand Down Expand Up @@ -60,7 +61,8 @@ def notify_action(self, parsed: ParseResult, actor: Living) -> None:
elif (targeted and parsed.verb == "idle-action") or parsed.verb == "location-event":
event_hash = llm_cache.cache_event(unpad_text(parsed.unparsed))
self._observed_events.append(event_hash)
self._do_react(parsed, actor)
if not self.deferred_actions or llm_config.params['UNLIMITED_REACTS']:
self._do_react(parsed, actor)
elif targeted and parsed.verb == "give":
parsed_split = parsed.unparsed.split(" to ")

Expand Down Expand Up @@ -137,7 +139,7 @@ def _do_react(self, parsed: ParseResult, actor: Living) -> None:
sentiment=self.sentiments.get(actor.name, '') if actor else '')
if action:
self.action_history.append(action)
self._defer_result(action, verb='reaction')
self._defer_result(action, verb='idle-action')

def handle_item_result(self, result: ItemHandlingResult, actor: Living) -> bool:
if result.to == self.title:
Expand Down Expand Up @@ -238,12 +240,7 @@ def _parse_action(self, action):
if action.target:
target = self.location.search_living(action.target)
if target:
target.tell('\n' + text, evoke=False)
target.notify_action(ParseResult(verb='say', unparsed=text, who_list=[target]), actor=self)
else:
self.tell_others('\n' + text, evoke=False)
else:
self.tell_others('\n' + text, evoke=False)
defered_actions.append(f'"{text}"')
if not action.action:
return defered_actions
Expand Down
3 changes: 3 additions & 0 deletions tale/llm/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def generate_dialogue(self,
if not isinstance(item, str):
item = None
except Exception as exc:
print(f'Failed to parse dialogue {exc}')
print(response)
return None, None, None

return text, item, new_sentiment
Expand Down Expand Up @@ -165,5 +167,6 @@ def free_form_action(self, action_context: ActionContext) -> list:
return actions
except Exception as exc:
print('Failed to parse action ' + str(exc))
print(text)
return None

16 changes: 14 additions & 2 deletions tests/test_llm_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,26 @@ def test_idle_action(self):

@responses.activate
def test_do_react(self):
action = ParseResult(verb='idle-action', unparsed='something happened', who_info=None)
mud_context.config.server_tick_method = 'TIMER'
npc = LivingNpc(name='test', gender='m', age=44, personality='')
npc2 = LivingNpc(name="actor", gender='f', age=32, personality='')
action = ParseResult(verb='idle-action', unparsed='something happened', who_list=[npc])
responses.add(responses.POST, self.dummy_backend_config['URL'] + self.dummy_backend_config['ENDPOINT'],
json={'results':[{'text':'"test happens back!"'}]}, status=200)
npc._do_react(action, npc2)
npc.notify_action(action, npc2)
assert(npc.deferred_actions == {'test : test happens back\n'})

@responses.activate
def test_do_react_deferred_exists(self):
action = ParseResult(verb='idle-action', unparsed='something happened', who_info=None)
npc = LivingNpc(name='test', gender='m', age=44, personality='')
npc.deferred_actions = {'test : existing action\n'}
npc2 = LivingNpc(name="actor", gender='f', age=32, personality='')
responses.add(responses.POST, self.dummy_backend_config['URL'] + self.dummy_backend_config['ENDPOINT'],
json={'results':[{'text':'"test happens back!"'}]}, status=200)
npc.notify_action(action, npc2)
assert(npc.deferred_actions == {'test : existing action\n'})

@responses.activate
def test_take_action(self):
location = Location("test_room")
Expand Down

0 comments on commit d157128

Please sign in to comment.