Skip to content

Commit

Permalink
Merge pull request #57 from neph1/update-v0.21.0
Browse files Browse the repository at this point in the history
Update v0.21.0
  • Loading branch information
neph1 authored Jan 7, 2024
2 parents 001fcd4 + 3f4a192 commit 1594142
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 114 deletions.
1 change: 0 additions & 1 deletion backend_kobold_cpp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ STREAM: False
STREAM_ENDPOINT: "/api/extra/generate/stream"
DATA_ENDPOINT: "/api/extra/generate/check"
DEFAULT_BODY: '{"stop_sequence": "\n\n\n\n", "max_length":750, "max_context_length":4096, "temperature":0.5, "top_k":120, "top_a":0.0, "top_p":0.85, "typical_p":1.0, "tfs":1.0, "rep_pen":1.2, "rep_pen_range":256, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}'
ANALYSIS_BODY: '{}'
GENERATION_BODY: '{"stop_sequence": "\n\n\n\n", "max_length":750, "max_context_length":4096, "temperature":1.0, "top_k":120, "top_a":0.0, "top_p":0.85, "typical_p":1.0, "tfs":1.0, "rep_pen":1.2, "rep_pen_range":256, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}'
18 changes: 9 additions & 9 deletions llm_config.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
WORD_LIMIT: 200
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"
ANALYSIS_BODY: '{}'
MEMORY_SIZE: 512
PRE_PROMPT: 'You are a creative game keeper. You craft detailed worlds and interesting characters with unique and deep personalities for the player to interact with.'
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}. 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.'
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, "action":action chosen, "target":character, item or exit or description, "text": if anything is said during the action}'
PRE_PROMPT: 'You are a creative game keeper for a role playing game (RPG). You craft detailed worlds and interesting characters with unique and deep personalities for the player to interact with.'
BASE_PROMPT: "<context>{context}</context>\n[USER_START] Rewrite [{input_text}] in your own words using the information found inside the <context> tags to create a background for your text. Use about {max_words} words."
DIALOGUE_PROMPT: '<context>{context}</context>\nThe following is a conversation between {character1} and {character2}; {character2}s sentiment towards {character1}: {sentiment}. Write a single response as {character2} in third person pov, using {character2} description and other information found inside the <context> tags. If {character2} has a quest active, they will discuss it based on its status. Respond in JSON using this template: """{dialogue_template}""". [USER_START]Continue the following conversation as {character2}: {previous_conversation}'
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.'
CREATE_CHARACTER_PROMPT: 'Story context: {story_context}; World info: {world_info};[USER_START] For a {story_type}, create a diverse character with rich personality that can be interacted with using the story context and keywords. {{quest_prompt}} Do not mention height. Story context: {story_context}; keywords: {keywords}. Fill in this JSON template and write nothing else: {{"name":"", "description": "50 words", "appearance": "25 words", "personality": "50 words", "money":(int), "level":"", "gender":"m/f/n", "age":(int), "race":""}}'
Expand All @@ -28,6 +28,6 @@ PLAYER_ENTER_PROMPT: 'Story context: {story_context}; World info: {world_info};
QUEST_PROMPT: '[Story context: {story_context}]; World info: {world_info}; Zone info: {zone_info}; Character: {character_card}; [USER_START] In an RPG described as {story_type}, {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: '[Story context: {story_context}]; World info: {world_info}; Zone info: {zone_info}; [USER_START]For an RPG described as {story_type}, 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: '[Story context: {story_context}]; World info: {world_info}; Zone info: {zone_info}; [USER_START]For an RPG described as {story_type}, 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: 'Story context: {story_context};<location>{location}</location> \nAct as as {character_name} in a {story_type} RPG and perform an action.<description>{character}</description> <actions>{actions}</actions>. <items>{location_items}</items>. <characters>{characters}</characters> <exits>{exits}</exits>.\nPick an action according to {character_name}s description and mood. If suitable, select something to perform the action on (target). Make sure the action is from the list and is related to {character_name}s thoughts.\n Respond using JSON in the following format: """{{"goal": reason for action, "thoughts":thoughts about performing action, "action":action chosen, "target":character, item or exit or description, "text": if anything is said during the action}}"""<history>{history}</history>'
ACTION_PROMPT: '<context>{context}</context>\nAct 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.\n Respond using JSON in the following format: """{action_template}"""'
USER_START: '### Instruction:'
USER_END: '### Response:'
USER_END: '### Response:\n'
2 changes: 1 addition & 1 deletion stories/teaparty/story_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
"type": "A whimsical and humoristic tale of tea and madness. Guests are so busy with their own problems that it's difficult to make yourself heard.",
"world_info": "",
"world_mood": 0,
"custom_resources" : "True"
"custom_resources": true
}
93 changes: 83 additions & 10 deletions stories/teaparty/world.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
"personality": "",
"occupation": "",
"age": 0,
"type": "Npc",
"type": "Mob",
"race": "",
"gender": "m",
"gender": "male",
"level": 1,
"stats": {
"ac": 0,
Expand All @@ -65,7 +65,16 @@
"strength": 3,
"dexterity": 3,
"unarmed_attack": "FISTS"
}
},
"memory": {
"known_locations": {},
"observed_events": [],
"conversations": [],
"sentiments": {},
"action_history": [],
"planned_actions": [],
"goal": null
}
},
"duchess": {
"location": "Living room",
Expand All @@ -79,9 +88,9 @@
"personality": "",
"occupation": "",
"age": 0,
"type": "Npc",
"type": "Mob",
"race": "",
"gender": "f",
"gender": "female",
"level": 1,
"stats": {
"ac": 0,
Expand All @@ -98,7 +107,16 @@
"strength": 3,
"dexterity": 3,
"unarmed_attack": "FISTS"
}
},
"memory": {
"known_locations": {},
"observed_events": [],
"conversations": [],
"sentiments": {},
"action_history": [],
"planned_actions": [],
"goal": null
}
},
"ace of spades": {
"location": "Living room",
Expand All @@ -112,9 +130,9 @@
"personality": "",
"occupation": "",
"age": 0,
"type": "Npc",
"type": "Mob",
"race": "",
"gender": "m",
"gender": "male",
"level": 1,
"stats": {
"ac": 0,
Expand All @@ -131,9 +149,64 @@
"strength": 3,
"dexterity": 3,
"unarmed_attack": "FISTS"
}
},
"memory": {
"known_locations": {},
"observed_events": [],
"conversations": [],
"sentiments": {},
"action_history": [],
"planned_actions": [],
"goal": null
}
}
},
"items": {}
},
"catalogue": {
"items": [
{
"name": "dagger",
"title": "Dagger",
"descr": "",
"short_descr": "A steel dagger",
"value": 0,
"rent": 0.0,
"weight": 0.0,
"takeable": true,
"location": "",
"wc": 0,
"base_damage": 1,
"bonus_damage": 0,
"weapon_type": "ONE_HANDED"
},
{
"name": "club",
"title": "Club",
"descr": "",
"short_descr": "A wooden club",
"value": 0,
"rent": 0.0,
"weight": 0.0,
"takeable": true,
"location": "",
"wc": 0,
"base_damage": 1,
"bonus_damage": 0,
"weapon_type": "ONE_HANDED"
},
{
"name": "note",
"title": "Note",
"descr": "",
"short_descr": "",
"value": 0,
"rent": 0.0,
"weight": 0.0,
"takeable": true,
"location": ""
}
],
"creatures": []
}
}
}
12 changes: 6 additions & 6 deletions tale/llm/LivingNpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from typing import Sequence

from tale.quest import Quest
from tale.resources_utils import pad_text_for_avatar
from tale.resources_utils import pad_text_for_avatar, unpad_text


class LivingNpc(Living):
Expand All @@ -34,7 +34,7 @@ def __init__(self, name: str, gender: str, *,

def notify_action(self, parsed: ParseResult, actor: Living) -> None:
# store even our own events.
event_hash = llm_cache.cache_event(parsed.unparsed)
event_hash = llm_cache.cache_event(unpad_text(parsed.unparsed))
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
Expand Down Expand Up @@ -80,7 +80,7 @@ def notify_action(self, parsed: ParseResult, actor: Living) -> None:
self._clear_quest()

def do_say(self, what_happened: str, actor: Living) -> None:
tell_hash = llm_cache.cache_tell('{actor.title} says {what_happened}'.format(actor=actor, what_happened=what_happened))
tell_hash = llm_cache.cache_tell('{actor.title} says {what_happened}'.format(actor=actor, what_happened=unpad_text(what_happened)))
self._conversations.append(tell_hash)
short_len = False if isinstance(actor, Player) else True
item = None
Expand Down Expand Up @@ -108,7 +108,7 @@ def do_say(self, what_happened: str, actor: Living) -> None:
if not response:
raise LlmResponseException("Failed to parse dialogue")

tell_hash = llm_cache.cache_tell('{actor.title} says: {response}'.format(actor=self, response=response))
tell_hash = llm_cache.cache_tell('{actor.title} says: {response}'.format(actor=self, response=unpad_text(response)))
self._conversations.append(tell_hash)
self._defer_result(response, verb='say')
if item:
Expand Down Expand Up @@ -213,7 +213,7 @@ def autonomous_action(self) -> str:
defered_actions = []
if action.get('text', ''):
text = action['text']
tell_hash = llm_cache.cache_tell('{actor.title} says: "{response}"'.format(actor=self, response=text))
tell_hash = llm_cache.cache_tell('{actor.title} says: "{response}"'.format(actor=self, response=unpad_text(text)))
self._conversations.append(tell_hash)
#if mud_context.config.custom_resources:
if action.get('target'):
Expand Down Expand Up @@ -260,7 +260,7 @@ def tell_action_deferred(self):
actions = '\n'.join(self.deferred_actions)
deferred_action = ParseResult(verb='idle-action', unparsed=actions, who_info=None)
self.tell_others(actions + '\n')
self.location._notify_action_all(deferred_action, actor=self)
#self.location._notify_action_all(deferred_action, actor=self)
self.deferred_actions.clear()

def _clear_quest(self):
Expand Down
Loading

0 comments on commit 1594142

Please sign in to comment.