Skip to content

Commit 9350be3

Browse files
authored
Merge pull request #96 from neph1/update-v0.36.1
Update v0.36.1
2 parents 1c878a1 + d8fc907 commit 9350be3

37 files changed

+370
-149
lines changed

llm_config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ 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"}}'
1818
ITEM_TYPES: ["Weapon", "Wearable", "Health", "Money", "Trash"]
19-
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..'
19+
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. Always follow the instructions given, never 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}'
2222
COMBAT_PROMPT: '<context>{context}</context>\nThe following is a combat scene between {attackers} and {defenders} in {location}. [USER_START] Describe the following combat result in about 150 words in vivid language, using the characters weapons and their health status: 1.0 is highest, 0.0 is lowest. Combat Result: {input_text}'
@@ -46,3 +46,4 @@ REQUEST_FOLLOW_PROMPT: '<context>{context}</context>\n[USER_START]Act as as {cha
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.'
4848
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}'
49+
ADVANCE_STORY_PROMPT: '<context>{context}</context>\n[USER_START] Advance the high-level plot outline in the current story, hidden to the player of this roleplaying game. The story progress is a value between 0 and 10. Consider the pacing of the plot when writing the section. A value below 3 is considered early. An inciting event should happen during this phase. Between 3 and 8 is the middle of the story. A climactic event should happen at 8 or 9. Above 9 is considered to be the ending. Use the information supplied inside the <context> tags to write a short paragraph that progresses the plot outline. Use up to 100 words.'

stories/combat_sandbox/story.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from tale.base import Location
88
from tale.driver import Driver
99
from tale.json_story import JsonStory
10-
from tale.llm.llm_ext import DynamicStory
10+
from tale.llm.dynamic_story import DynamicStory
1111
from tale.main import run_from_cmdline
1212
from tale.player import Player, PlayerConnection
1313
from tale.charbuilder import PlayerNaming

stories/demo/story.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
Copyright by Irmen de Jong ([email protected])
66
"""
77
import datetime
8+
import pathlib
89
import sys
910
from typing import Optional, Generator
1011

1112
from tale.driver import Driver
13+
from tale.main import run_from_cmdline
1214
from tale.player import Player, PlayerConnection
1315
from tale.charbuilder import PlayerNaming
1416
from tale.story import *
@@ -85,5 +87,9 @@ def goodbye(self, player: Player) -> None:
8587

8688
if __name__ == "__main__":
8789
# story is invoked as a script, start it.
88-
from tale.main import run_from_cmdline
89-
run_from_cmdline(["--game", sys.path[0]])
90+
gamedir = pathlib.Path(__file__).parent
91+
if gamedir.is_dir() or gamedir.is_file():
92+
cmdline_args = sys.argv[1:]
93+
cmdline_args.insert(0, "--game")
94+
cmdline_args.insert(1, str(gamedir))
95+
run_from_cmdline(cmdline_args)

stories/prancingllama/story.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
from tale.base import Location
77
from tale.cmds import spells
88
from tale.driver import Driver
9-
from tale.llm.llm_ext import DynamicStory
9+
from tale.llm.dynamic_story import DynamicStory
1010
from tale.skills.magic import MagicType
1111
from tale.main import run_from_cmdline
1212
from tale.player import Player, PlayerConnection
1313
from tale.charbuilder import PlayerNaming
1414
from tale.skills.skills import SkillType
1515
from tale.story import *
1616
from tale.skills.weapon_type import WeaponType
17+
from tale.story import StoryContext
1718
from tale.zone import Zone
1819

1920
class Story(DynamicStory):
@@ -34,15 +35,15 @@ class Story(DynamicStory):
3435
config.startlocation_player = "prancingllama.entrance"
3536
config.startlocation_wizard = "prancingllama.entrance"
3637
config.zones = ["prancingllama"]
37-
config.context = "The final outpost high up in a cold, craggy mountain range. It's frequented by adventurers and those seeking to avoid attention."
38+
config.context = StoryContext(base_story="The final outpost high up in a cold, craggy mountain range. A drama unfolds between those avoiding the cold and those seeking the cold. And what is lurking underneath the snow covered peaks and uncharted valleys?")
3839
config.type = "A low level fantasy adventure with focus of character building and interaction."
3940
config.custom_resources = True
4041

4142

4243
def init(self, driver: Driver) -> None:
4344
"""Called by the game driver when it is done with its initial initialization."""
4445
self.driver = driver
45-
self._zones = dict() # type: dict(str, Zone)
46+
self._zones = dict() # type: {str, Zone}
4647
self._zones["The Prancing Llama"] = Zone("The Prancing Llama", description="A cold, craggy mountain range. Snow covered peaks and uncharted valleys hide and attract all manners of creatures.")
4748
import zones.prancingllama
4849
for location in zones.prancingllama.all_locations:
@@ -96,13 +97,13 @@ def goodbye(self, player: Player) -> None:
9697
player.tell("Goodbye, %s. Please come back again soon." % player.title)
9798
player.tell("\n")
9899

99-
def races_for_zone(self, zone: str) -> [str]:
100+
def races_for_zone(self, zone: str) -> list[str]:
100101
return self._catalogue._creatures
101102

102-
def items_for_zone(self, zone: str) -> [str]:
103+
def items_for_zone(self, zone: str) -> list[str]:
103104
return self._catalogue._items
104105

105-
def zone_info(self, zone_name: str, location: str) -> dict():
106+
def zone_info(self, zone_name: str, location: str) -> dict:
106107
zone_info = super.zone_info(zone_name, location)
107108
zone_info['races'] = self.races_for_zone(zone_name)
108109
zone_info['items'] = self.items_for_zone(zone_name)

tale/cmds/normal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import Iterable, List, Dict, Generator, Union, Optional
1212
from tale.llm.LivingNpc import LivingNpc
1313

14-
from tale.llm.llm_ext import DynamicStory
14+
from tale.llm.dynamic_story import DynamicStory
1515
from tale.skills.skills import SkillType
1616

1717
from . import abbreviations, cmd, disabled_in_gamemode, disable_notify_action, overrides_soul, no_soul_parse

tale/driver.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131

3232
from . import __version__ as tale_version_str, _check_required_libraries
3333
from . import mud_context, errors, util, cmds, player, pubsub, charbuilder, lang, verbdefs, vfs, base
34-
from .story import TickMethod, GameMode, MoneyType, StoryBase
34+
from .story import StoryContext, TickMethod, GameMode, MoneyType, StoryBase
3535
from .tio import DEFAULT_SCREEN_WIDTH
3636
from .races import playable_races
3737
from .errors import StoryCompleted
3838
from tale.load_character import CharacterLoader, CharacterV2
39-
from tale.llm.llm_ext import DynamicStory
39+
from tale.llm.dynamic_story import DynamicStory
4040
from tale.llm.llm_utils import LlmUtil
4141
from tale.web.web_utils import clear_resources, copy_web_resources
4242

@@ -535,6 +535,9 @@ def _server_tick(self) -> None:
535535
events, idle_time, subbers = topicinfo[topicname]
536536
if events == 0 and not subbers and idle_time > 30:
537537
pubsub.topic(topicname).destroy()
538+
progress = self.story.increase_progress(0.0001)
539+
if progress:
540+
self.llm_util.advance_story_section(self.story)
538541

539542
def disconnect_idling(self, conn: player.PlayerConnection) -> None:
540543
raise NotImplementedError
@@ -933,7 +936,7 @@ def build_location(self, targetLocation: base.Location, zone: Zone, player: play
933936
# try to add location, and if it fails, remove exit to it
934937
result = dynamic_story.add_location(location, zone=zone.name)
935938
if not result:
936-
for exit in exits: # type: Exit
939+
for exit in exits:
937940
if exit.name == location.name:
938941
exits.remove(exit)
939942
for exit in exits:

tale/dungeon/dungeon_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tale.coord import Coord
66
from tale.item_spawner import ItemSpawner
77
from tale.items.basic import Money
8-
from tale.llm.llm_ext import DynamicStory
8+
from tale.llm.dynamic_story import DynamicStory
99
from tale.mob_spawner import MobSpawner
1010
from tale.zone import Zone
1111

tale/json_story.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from tale.day_cycle.day_cycle import DayCycle
33
from tale.day_cycle.llm_day_cycle_listener import LlmDayCycleListener
44
from tale.items import generic
5-
from tale.llm.llm_ext import DynamicStory
5+
from tale.llm.dynamic_story import DynamicStory
66
from tale.player import Player
77
from tale.random_event import RandomEvent
88
from tale.story import GameMode, StoryConfig
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
from tale.llm.contexts.BaseContext import BaseContext
4+
5+
6+
class AdvanceStoryContext(BaseContext):
7+
8+
def __init__(self, story_context: str):
9+
super().__init__(story_context)
10+
11+
def to_prompt_string(self) -> str:
12+
return f"{self.story_context}"

tale/llm/contexts/BaseContext.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
2-
31
from abc import ABC, abstractmethod
2+
from typing import Union
3+
4+
from tale.story import StoryContext
45

56

67
class BaseContext(ABC):
78

8-
def __init__(self, story_context: str) -> None:
9-
self.story_context = story_context
9+
def __init__(self, story_context: Union[StoryContext, str]) -> None:
10+
if isinstance(story_context, StoryContext):
11+
self.story_context = story_context.to_context_with_past()
12+
else:
13+
self.story_context = story_context
1014

1115
@abstractmethod
1216
def to_prompt_string(self) -> str:

0 commit comments

Comments
 (0)