Skip to content

Commit 8b83643

Browse files
committed
some parameter tweaking
1 parent 472bc7c commit 8b83643

File tree

7 files changed

+32
-24
lines changed

7 files changed

+32
-24
lines changed

stories/prancingllama/npcs/npcs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from tale.base import Item, Living, ParseResult
55
from tale.errors import ParseError, ActionRefused
6+
from tale.lang import capital
67
from tale.llm_ext import LivingNpc
78
from tale.player import Player
89
from tale.util import call_periodically, Context
@@ -48,6 +49,10 @@ def do_random_move(self, ctx: Context) -> None:
4849
if direction:
4950
self.move(direction.target, self, direction_names=direction.names)
5051

52+
@call_periodically(30, 60)
53+
def do_pick_up_dishes(self, ctx: Context) -> None:
54+
self.location.tell("%s wipes a table and picks up dishes." % capital(self.title), evoke=False)
55+
5156
class Patron(LivingNpc):
5257

5358
def __init__(self, name: str, gender: str, *,
@@ -118,4 +123,7 @@ def do_idle_action(self, ctx: Context) -> None:
118123
urta = InnKeeper("Urta", "f", age=44, descr="A gruff, curvy woman with a long brown coat and bushy hair that reaches her waist. When not serving, she keeps polishing jugs with a dirty rag.", personality="She's the owner of The Prancing Llama, and of few words. But the words she speak are kind. She knows a little about all the patrons in her establishment.", short_descr="A curvy woman with long brown coat standing behind the bar.")
119124
urta.aliases = {"bartender", "inn keeper", "curvy woman"}
120125

126+
brim = Maid("Brim", "f", age=22, descr="A timid girl with long dark blonde hair in a braid down her back. She carries trays and dishes back and forth.", personality="She's shy and rarely looks anyone in the eye. When she speaks, it is merely a whisper. She traveled up the mountain looking for work, and ended up serving at the Inn. She dreams of big adventures.", short_descr="A timid maid with a braid wearing a tunic and dirty apron.")
127+
brim.aliases = {"maid", "timid girl", "serving girl"}
128+
121129

stories/prancingllama/zones/prancingllama.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def spawn_rat(self, ctx: Context) -> None:
4545

4646
bar.init_inventory([urta, norhardt])
4747

48-
hearth.init_inventory([count_karta])
48+
hearth.init_inventory([count_karta, brim])
4949

5050
drink = Item("ale", "jug of ale", descr="Looks and smells like strong ale.")
5151

tale/base.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,8 @@ def tell(self, room_msg: str, exclude_living: 'Living'=None, specific_targets: S
642642
that based on this message string. That will make it quite hard because you need to
643643
parse the string again to figure out what happened... Use handle_verb / notify_action instead.
644644
"""
645+
#alt_prompt ="### Instruction: Location: [" + str(self.look(short=True)) + "]. Rewrite the following text in your own words using vivid language, use 'location' for context. Text:\n\n [{input_text}] \n\nEnd of text.\n\n### Response:\n"
646+
645647
targets = specific_targets or set()
646648
assert isinstance(targets, (frozenset, set, list, tuple))
647649
assert exclude_living is None or isinstance(exclude_living, Living)
@@ -669,7 +671,7 @@ def message_nearby_locations(self, message: str) -> None:
669671
if exit.target in yelled_locations:
670672
continue # skip double locations (possible because there can be multiple exits to the same location)
671673
if exit.target is not self:
672-
exit.target.tell(message, evoke=True, max_length=True)
674+
exit.target.tell(message, evoke=False, max_length=True)
673675
yelled_locations.add(exit.target)
674676
for direction, return_exit in exit.target.exits.items():
675677
if return_exit.target is self:
@@ -684,7 +686,7 @@ def message_nearby_locations(self, message: str) -> None:
684686
direction = "below"
685687
else:
686688
continue # no direction description possible for this exit
687-
exit.target.tell("The sound is coming from %s." % direction, evoke=True, max_length=True)
689+
exit.target.tell("The sound is coming from %s." % direction, evoke=False, max_length=True)
688690
break
689691

690692
def nearby(self, no_traps: bool=True) -> Iterable['Location']:
@@ -1034,7 +1036,7 @@ def wiz_clone(self, actor: 'Living', make_clone: bool=True) -> 'Living':
10341036
actor.tell("Cloned into: " + repr(duplicate) + " (spawned in current location)")
10351037
actor.tell_others("{Actor} summons %s..." % lang.a(duplicate.title))
10361038
actor.location.insert(duplicate, actor)
1037-
actor.location.tell("%s appears." % lang.capital(duplicate.title), evoke=True, max_length=True)
1039+
actor.location.tell("%s appears." % lang.capital(duplicate.title), evoke=False, max_length=True)
10381040
return duplicate
10391041

10401042
@util.authorized("wizard")
@@ -1274,7 +1276,7 @@ def display_direction(directions: Sequence[str]) -> str:
12741276
message = "%s leaves %s." % (lang.capital(self.title), direction_txt)
12751277
else:
12761278
message = "%s leaves." % lang.capital(self.title)
1277-
original_location.tell(message, exclude_living=self, evoke=True, max_length=True)
1279+
original_location.tell(message, exclude_living=self, evoke=False, max_length=True)
12781280
# queue event
12791281
if is_player:
12801282
pending_actions.send(lambda who=self, where=target: original_location.notify_player_left(who, where))
@@ -1283,7 +1285,7 @@ def display_direction(directions: Sequence[str]) -> str:
12831285
else:
12841286
target.insert(self, actor)
12851287
if not silent:
1286-
target.tell(f"{lang.capital(self.title)} arrives from {original_location}." , exclude_living=self, evoke=True, max_length=True)
1288+
target.tell(f"{lang.capital(self.title)} arrives from {original_location}." , exclude_living=self, evoke=False, max_length=True)
12871289
# queue event
12881290
if is_player:
12891291
pending_actions.send(lambda who=self, where=original_location: target.notify_player_arrived(who, where))
@@ -1683,7 +1685,7 @@ def open(self, actor: Living, item: Item=None) -> None:
16831685
actor.tell_others("{Actor} opens the %s." % self.name, evoke=True, max_length=True)
16841686
if self.linked_door:
16851687
self.linked_door.opened = True
1686-
self.target.tell("The %s is opened from the other side." % self.linked_door.name, evoke=True, max_length=True)
1688+
self.target.tell("The %s is opened from the other side." % self.linked_door.name, evoke=False, max_length=True)
16871689

16881690
def close(self, actor: Living, item: Item=None) -> None:
16891691
"""Close the door with optional item. Notifies actor and room of this event."""
@@ -1694,7 +1696,7 @@ def close(self, actor: Living, item: Item=None) -> None:
16941696
actor.tell_others("{Actor} closes the %s." % self.name, evoke=True, max_length=True)
16951697
if self.linked_door:
16961698
self.linked_door.opened = False
1697-
self.target.tell("The %s is closed from the other side." % self.linked_door.name, evoke=True, max_length=True)
1699+
self.target.tell("The %s is closed from the other side." % self.linked_door.name, evoke=False, max_length=True)
16981700

16991701
def lock(self, actor: Living, item: Item=None) -> None:
17001702
"""Lock the door with the proper key (optional)."""
@@ -1714,11 +1716,11 @@ def lock(self, actor: Living, item: Item=None) -> None:
17141716
if not key:
17151717
raise ActionRefused("You don't seem to have the means to lock it.")
17161718
self.locked = True
1717-
actor.tell("Your %s fits, the %s is now locked." % (key.title, self.name), evoke=True, max_length=True)
1718-
actor.tell_others("{Actor} locks the %s with %s." % (self.name, lang.a(key.title)), evoke=True, max_length=True)
1719+
actor.tell("Your %s fits, the %s is now locked." % (key.title, self.name), evoke=False, max_length=True)
1720+
actor.tell_others("{Actor} locks the %s with %s." % (self.name, lang.a(key.title)), evoke=False, max_length=True)
17191721
if self.linked_door:
17201722
self.linked_door.locked = True
1721-
self.target.tell("The %s is locked from the other side." % self.linked_door.name, evoke=True, max_length=True)
1723+
self.target.tell("The %s is locked from the other side." % self.linked_door.name, evoke=False, max_length=True)
17221724

17231725
def unlock(self, actor: Living, item: Item=None) -> None:
17241726
"""Unlock the door with the proper key (optional)."""

tale/driver.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ def load_character(self, player: player.Player, path: str):
792792
age = character.age,
793793
personality = character.personality,
794794
occupation = character.occupation)
795+
npc.following = player
795796
player.location.insert(npc, None)
796797

797798

tale/llm_config.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
URL: "http://localhost:5001"
22
ENDPOINT: "/api/v1/generate"
3+
STREAM: False
34
STREAM_ENDPOINT: "/api/extra/generate/stream"
45
DATA_ENDPOINT: "/api/extra/generate/check"
56
WORD_LIMIT: 500
6-
DEFAULT_BODY: '{"stop_sequence": "", "max_length":300, "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, "mirostat":2, "mirostat_tau":5.0, "mirostat_eta":0.1, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}'
7-
ANALYSIS_BODY: '{"stop_sequence": "\n\n", "max_length":300, "max_context_length":4096, "temperature":0.15, "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, "mirostat":2, "mirostat_tau":5.0, "mirostat_eta":0.1, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}'
8-
MEMORY_SIZE: 1024
7+
DEFAULT_BODY: '{"stop_sequence": "", "max_length":500, "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, "mirostat":2, "mirostat_tau":5.0, "mirostat_eta":0.1, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}'
8+
ANALYSIS_BODY: '{"banned_tokens":"\n\n", "stop_sequence": "", "max_length":500, "max_context_length":4096, "temperature":0.15, "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, "mirostat":2, "mirostat_tau":5.0, "mirostat_eta":0.1, "sampler_order":[6,0,1,3,4,2,5], "seed":-1}'
9+
MEMORY_SIZE: 512
910
PRE_PROMPT: 'Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.\n\n'
10-
BASE_PROMPT: '### Instruction: Rewrite the following text in your own words using vivid language. Text:\n\n {input_text} \n\nEnd of text.\n\n### Response:\n'
11+
BASE_PROMPT: "History: [{history}]. ### Instruction: Rewrite the following text in your own words using vivid language. 'History' can be used to create a context for what you write. Text:\n\n [{input_text}] \n\nEnd of text.\n\n### Response:\n"
1112
DIALOGUE_PROMPT: 'The following is a conversation between {character1} and {character2}. {character2_description}. Chat history: {previous_conversation}\n\n {character2}s sentiment towards {character1}: {sentiment}. ### Instruction: Write a single response as {character2}, using {character2} description.\n\n### Response:\n'
1213
ITEM_PROMPT: '### Instruction: Items:[{items}];Characters:[{character1},{character2}] Text:[{text}] \n\nIn the supplied text, was an item explicitly given, taken, dropped or put somewhere? Insert your thoughts about it in [my thoughts], and the results in "item", "from" and "to". Insert {character1}s sentiment towards {character2} in a single word in [sentiment assessment]. Write your response in JSON format. Example: {{ "thoughts":"[my thoughts]", "result": {{ "item":"", "from":"", "to":""}}, {{"sentiment":"[sentiment assessment]"}} }} End of example. \n\n Make sure the response is valid JSON\n\n### Response:\n'
1314

tale/llm_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _do_process_result(self, url, player_io: TextBuffer, io) -> str:
3535
""" Process the result from the stream endpoint """
3636
tries = 0
3737
old_text = ''
38-
while tries < 2:
38+
while tries < 4:
3939
time.sleep(0.5)
4040
data = requests.post(url)
4141
text = json.loads(data.text)['results'][0]['text']

tale/llm_utils.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self):
2929
self.item_prompt = config_file['ITEM_PROMPT']
3030
self._story_background = ''
3131
self.io_util = IoUtil()
32-
self.stream = True
32+
self.stream = config_file['STREAM']
3333
self.connection = None
3434

3535
def evoke(self, player_io: TextBuffer, message: str, max_length : bool=False, rolling_prompt='', alt_prompt=''):
@@ -39,8 +39,7 @@ def evoke(self, player_io: TextBuffer, message: str, max_length : bool=False, ro
3939
trimmed_message = parse_utils.remove_special_chars(str(message))
4040
base_prompt = alt_prompt if alt_prompt else self.base_prompt
4141
amount = int(len(trimmed_message) * 2.5)
42-
prompt = rolling_prompt if not alt_prompt else ''
43-
prompt += base_prompt.format(input_text=str(trimmed_message))
42+
prompt = base_prompt.format(history=rolling_prompt if not alt_prompt else '', input_text=str(trimmed_message))
4443

4544
rolling_prompt = self.update_memory(rolling_prompt, trimmed_message)
4645

@@ -71,8 +70,7 @@ def generate_dialogue(self, conversation: str, character_card: str, character_na
7170

7271
request_body = self.default_body
7372
request_body['prompt'] = prompt
74-
response = requests.post(self.url, data=json.dumps(request_body))
75-
text = parse_utils.trim_response(json.loads(response.text)['results'][0]['text'])
73+
text = parse_utils.trim_response(self.io_util.synchronous_request(self.url + self.endpoint, request_body))
7674

7775
item_handling_result, new_sentiment = self.dialogue_analysis(text, character_card, character_name, target)
7876

@@ -83,9 +81,7 @@ def dialogue_analysis(self, text: str, character_card: str, character_name: str,
8381
prompt = self.generate_item_prompt(text, items, character_name, target)
8482
request_body = self.analysis_body
8583
request_body['prompt'] = prompt
86-
response = requests.post(self.url, data=json.dumps(request_body))
87-
88-
text = parse_utils.trim_response(json.loads(response.text)['results'][0]['text'])
84+
text = parse_utils.trim_response(self.io_util.synchronous_request(self.url + self.endpoint, request_body))
8985
try:
9086
json_result = json.loads(text.replace('\n', ''))
9187
except JSONDecodeError as exc:

0 commit comments

Comments
 (0)