Skip to content

Commit 1c878a1

Browse files
authored
Merge pull request #95 from neph1/update-v0.35.2
Update v0.35.2
2 parents ed3eb51 + 11ef882 commit 1c878a1

File tree

7 files changed

+16
-14
lines changed

7 files changed

+16
-14
lines changed

llm_config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ZONE_TEMPLATE: '{{"name":name of the room, "description": "75 words", "races":[]
1515
DUNGEON_LOCATION_TEMPLATE: '{"index": (int), "name": "", "description": 25 words}'
1616
CHARACTER_TEMPLATE: '{"name":"", "description": "50 words", "appearance": "25 words", "personality": "50 words", "money":(int), "level":"", "gender":"m/f/n", "age":(int), "race":"", "occupation":""}'
1717
FOLLOW_TEMPLATE: '{{"response":"yes or no", "reason":"50 words"}}'
18-
ITEM_TYPES: ["Weapon", "Wearable", "Health", "Money", "Trash", "Food", "Drink", "Key"]
18+
ITEM_TYPES: ["Weapon", "Wearable", "Health", "Money", "Trash"]
1919
PRE_PROMPT: 'You are a creative game keeper for an interactive fiction story telling session. You craft detailed worlds and interesting characters with unique and deep personalities for the player to interact with. Do not acknowledge the task or speak directly to the user, or respond with anything besides the request..'
2020
BASE_PROMPT: '<context>{context}</context>\n[USER_START] Rewrite [{input_text}] in your own words. The information inside the <context> tags should be used to ensure it fits the story. Use about {max_words} words.'
2121
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}'
@@ -45,4 +45,4 @@ ACTION_PROMPT: '<context>{context}</context>\n[USER_START]Act as as {character_n
4545
REQUEST_FOLLOW_PROMPT: '<context>{context}</context>\n[USER_START]Act as as {character_name}.\nUsing the information supplied inside the <context> tag. {character_name} has received a request to follow {target}. Answer based on {character_name}s description and mood. Reason given by {target}: {target_reason}. Respond using JSON in the following format: {follow_template}'
4646
DAY_CYCLE_EVENT_PROMPT: '<context>{context}</context>\n[USER_START] Write up to two sentences describing the transition from {from_time} to {to_time} in {location_name}, using the information supplied inside the <context> tags.'
4747
NARRATIVE_EVENT_PROMPT: '<context>{context}</context>\n[USER_START] Write a narrative event that occurs in {location_name} using the information supplied inside the <context> tags. The event should be related to the location and the characters present. Use up to 50 words.'
48-
RANDOM_SPAWN_PROMPT: '<context>{context}</context>\n[USER_START] An npc or a mob has entered {location_name}. Select either and fill in one of the following templates using the information supplied inside the <context> tags. Respond using JSON in the following format: {npc_template}'
48+
RANDOM_SPAWN_PROMPT: '<context>{context}</context>\n[USER_START] An npc or a mob has entered {location_name}. Select either and fill in one of the following templates using the information supplied inside the <context> tags. Respond using JSON in the following format: {npc_template}'

tale/cmds/wizard.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,13 @@ def do_enrich(player: Player, parsed: base.ParseResult, ctx: util.Context) -> No
753753
if len(parsed.args) != 1:
754754
raise ParseError("You need to define 'items' or 'creatures'.")
755755

756+
if parsed.args[0] == "food":
757+
items = ctx.driver.llm_util.generate_world_items(item_types=['Food', 'Drink']) # type: WorldItemsResponse
758+
if items.valid:
759+
player.tell("(generated: %s, items)" % (len(items.items)))
760+
for item in items.items:
761+
ctx.driver.story._catalogue.add_item(item)
762+
return
756763
if parsed.args[0] == "items":
757764
items = ctx.driver.llm_util.generate_world_items() # type: WorldItemsResponse
758765
if items.valid:

tale/llm/llm_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,12 @@ def generate_start_zone(self, location_desc: str, story_type: str, story_context
209209
world_generation_context = WorldGenerationContext(story_context=story_context, story_type=story_type, world_info=world_info, world_mood=world_info['world_mood'])
210210
return self._world_building.generate_start_zone(location_desc, context=world_generation_context)
211211

212-
def generate_world_items(self, story_context: str = '', story_type: str = '', world_info: str = '', world_mood: int = None) -> WorldItemsResponse:
212+
def generate_world_items(self, story_context: str = '', story_type: str = '', world_info: str = '', world_mood: int = None, item_types: list = []) -> WorldItemsResponse:
213213
world_generation_context = WorldGenerationContext(story_context=story_context or self.__story_context,
214214
story_type=story_type or self.__story_type,
215215
world_info=world_info or self.__world_info,
216216
world_mood=world_mood or self.__story.config.world_mood)
217-
return self._world_building.generate_world_items(world_generation_context)
217+
return self._world_building.generate_world_items(world_generation_context, item_types=item_types)
218218

219219

220220
def generate_world_creatures(self, story_context: str = '', story_type: str = '', world_info: str = '', world_mood: int = None) -> WorldCreaturesResponse:

tale/llm/world_building.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,10 @@ def generate_start_zone(self, location_desc: str, context: WorldGenerationContex
222222
return None
223223

224224

225-
def generate_world_items(self, world_generation_context: WorldGenerationContext) -> WorldItemsResponse:
226-
""" Since 0.16.1 returns a json array, rather than a list of items"""
225+
def generate_world_items(self, world_generation_context: WorldGenerationContext, item_types: list = []) -> WorldItemsResponse:
227226
prompt = self.world_items_prompt.format(context = '{context}',
228227
item_template=self.item_template,
229-
item_types=self.item_types)
228+
item_types=item_types or self.item_types)
230229
request_body = deepcopy(self.default_body)
231230
if self.json_grammar_key:
232231
request_body[self.json_grammar_key] = self.json_grammar
@@ -240,7 +239,6 @@ def generate_world_items(self, world_generation_context: WorldGenerationContext)
240239
return WorldItemsResponse()
241240

242241
def generate_world_creatures(self, world_generation_context: WorldGenerationContext) -> WorldCreaturesResponse:
243-
""" Since 0.16.1 returns a json array, rather than a list of creatures"""
244242
prompt = self.world_creatures_prompt.format(context = '{context}',
245243
creature_template=self.creature_template)
246244
request_body = deepcopy(self.default_body)

tale/shop.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def sellprofit(self, value: float) -> None:
8080

8181

8282
class Shopkeeper(LivingNpc):
83-
def __init__(self, name: str, gender: str, *, title: str = "", descr: str = "", short_descr: str = "", age: int, personality: str, occupation: str = "", race: str = "human", parse_occupation: bool = False) -> None:
83+
def __init__(self, name: str, gender: str, *, title: str = "", descr: str = "", short_descr: str = "", age: int = 0, personality: str = "", occupation: str = "", race: str = "human", parse_occupation: bool = False) -> None:
8484
super(Shopkeeper, self).__init__(name=name, gender=gender,
8585
title=title, descr=descr, short_descr=short_descr, age=age, personality=personality, occupation=occupation, race=race, parse_occupation=parse_occupation)
8686
self.privileges.add("shopkeeper") # allow for some item transfers (buy/sell) that would otherwise be blocked

tale/tio/if_browser_io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ def wsgi_handle_eventsource(self, environ: Dict[str, Any], parameters: Dict[str,
386386
"items": items if location else '',
387387
"exits": exits if location else '',
388388
}
389-
result = "event: text\nid: {event_id}\ndata: {data}\n\n"\
389+
result = "event: text\nid: {event_id}\ndata: {data}"\
390390
.format(event_id=str(time.time()), data=json.dumps(response))
391-
yield result.encode("utf-8")
391+
yield (result + "\n\n"+ ' ' * 150 + "\n\n").encode("utf-8")
392392
elif data:
393393
for d in data:
394394
result = "event: data\nid: {event_id}\ndata: {data}\n\n"\

tests/test_character_loader.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import json
2-
import pytest
3-
import tests.files
41
from tale.load_character import CharacterLoader, CharacterV2
52

63
class TestCharacterLoader():

0 commit comments

Comments
 (0)