Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update v0.35.2 #95

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llm_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ZONE_TEMPLATE: '{{"name":name of the room, "description": "75 words", "races":[]
DUNGEON_LOCATION_TEMPLATE: '{"index": (int), "name": "", "description": 25 words}'
CHARACTER_TEMPLATE: '{"name":"", "description": "50 words", "appearance": "25 words", "personality": "50 words", "money":(int), "level":"", "gender":"m/f/n", "age":(int), "race":"", "occupation":""}'
FOLLOW_TEMPLATE: '{{"response":"yes or no", "reason":"50 words"}}'
ITEM_TYPES: ["Weapon", "Wearable", "Health", "Money", "Trash", "Food", "Drink", "Key"]
ITEM_TYPES: ["Weapon", "Wearable", "Health", "Money", "Trash"]
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..'
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.'
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}'
Expand Down Expand Up @@ -45,4 +45,4 @@ ACTION_PROMPT: '<context>{context}</context>\n[USER_START]Act as as {character_n
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}'
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.'
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.'
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}'
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}'
7 changes: 7 additions & 0 deletions tale/cmds/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,13 @@ def do_enrich(player: Player, parsed: base.ParseResult, ctx: util.Context) -> No
if len(parsed.args) != 1:
raise ParseError("You need to define 'items' or 'creatures'.")

if parsed.args[0] == "food":
items = ctx.driver.llm_util.generate_world_items(item_types=['Food', 'Drink']) # type: WorldItemsResponse
if items.valid:
player.tell("(generated: %s, items)" % (len(items.items)))
for item in items.items:
ctx.driver.story._catalogue.add_item(item)
return
if parsed.args[0] == "items":
items = ctx.driver.llm_util.generate_world_items() # type: WorldItemsResponse
if items.valid:
Expand Down
4 changes: 2 additions & 2 deletions tale/llm/llm_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,12 +209,12 @@ def generate_start_zone(self, location_desc: str, story_type: str, story_context
world_generation_context = WorldGenerationContext(story_context=story_context, story_type=story_type, world_info=world_info, world_mood=world_info['world_mood'])
return self._world_building.generate_start_zone(location_desc, context=world_generation_context)

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


def generate_world_creatures(self, story_context: str = '', story_type: str = '', world_info: str = '', world_mood: int = None) -> WorldCreaturesResponse:
Expand Down
6 changes: 2 additions & 4 deletions tale/llm/world_building.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,10 @@ def generate_start_zone(self, location_desc: str, context: WorldGenerationContex
return None


def generate_world_items(self, world_generation_context: WorldGenerationContext) -> WorldItemsResponse:
""" Since 0.16.1 returns a json array, rather than a list of items"""
def generate_world_items(self, world_generation_context: WorldGenerationContext, item_types: list = []) -> WorldItemsResponse:
prompt = self.world_items_prompt.format(context = '{context}',
item_template=self.item_template,
item_types=self.item_types)
item_types=item_types or self.item_types)
request_body = deepcopy(self.default_body)
if self.json_grammar_key:
request_body[self.json_grammar_key] = self.json_grammar
Expand All @@ -240,7 +239,6 @@ def generate_world_items(self, world_generation_context: WorldGenerationContext)
return WorldItemsResponse()

def generate_world_creatures(self, world_generation_context: WorldGenerationContext) -> WorldCreaturesResponse:
""" Since 0.16.1 returns a json array, rather than a list of creatures"""
prompt = self.world_creatures_prompt.format(context = '{context}',
creature_template=self.creature_template)
request_body = deepcopy(self.default_body)
Expand Down
2 changes: 1 addition & 1 deletion tale/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def sellprofit(self, value: float) -> None:


class Shopkeeper(LivingNpc):
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:
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:
super(Shopkeeper, self).__init__(name=name, gender=gender,
title=title, descr=descr, short_descr=short_descr, age=age, personality=personality, occupation=occupation, race=race, parse_occupation=parse_occupation)
self.privileges.add("shopkeeper") # allow for some item transfers (buy/sell) that would otherwise be blocked
Expand Down
4 changes: 2 additions & 2 deletions tale/tio/if_browser_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ def wsgi_handle_eventsource(self, environ: Dict[str, Any], parameters: Dict[str,
"items": items if location else '',
"exits": exits if location else '',
}
result = "event: text\nid: {event_id}\ndata: {data}\n\n"\
result = "event: text\nid: {event_id}\ndata: {data}"\
.format(event_id=str(time.time()), data=json.dumps(response))
yield result.encode("utf-8")
yield (result + "\n\n"+ ' ' * 150 + "\n\n").encode("utf-8")
elif data:
for d in data:
result = "event: data\nid: {event_id}\ndata: {data}\n\n"\
Expand Down
3 changes: 0 additions & 3 deletions tests/test_character_loader.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import json
import pytest
import tests.files
from tale.load_character import CharacterLoader, CharacterV2

class TestCharacterLoader():
Expand Down
Loading