include player name and actions in discord prompt, include room count in generator prompt
This commit is contained in:
parent
5a32bd9fc4
commit
af69d5b6b0
|
@ -427,9 +427,33 @@ def embed_from_player(event: PlayerEvent):
|
|||
|
||||
|
||||
def embed_from_prompt(event: PromptEvent):
|
||||
# TODO: ping the player
|
||||
prompt_embed = Embed(title=event.room.name, description=event.character.name)
|
||||
prompt_embed.add_field(name="Prompt", value=truncate(event.prompt))
|
||||
|
||||
if has_player(event.character.name):
|
||||
players = list_players()
|
||||
user = next(
|
||||
(
|
||||
player
|
||||
for player, character in players.items()
|
||||
if character == event.character.name
|
||||
),
|
||||
None,
|
||||
)
|
||||
|
||||
if user:
|
||||
# TODO: use Discord user.mention to ping the user
|
||||
prompt_embed.add_field(
|
||||
name="Player",
|
||||
value=user,
|
||||
)
|
||||
|
||||
for action in event.actions:
|
||||
# TODO: use a prompt template to summarize actions
|
||||
action_name = action["function"]["name"]
|
||||
action_description = action["function"]["description"]
|
||||
prompt_embed.add_field(name=action_name, value=action_description)
|
||||
|
||||
return prompt_embed
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@ current_character: Character | None = None
|
|||
dungeon_master: Agent | None = None
|
||||
|
||||
# game context
|
||||
# TODO: wrap this into a class that can be passed around
|
||||
character_agents: Dict[str, Tuple[Character, Agent]] = {}
|
||||
event_emitter = EventEmitter()
|
||||
game_config: Config = DEFAULT_CONFIG
|
||||
game_systems: List[GameSystem] = []
|
||||
|
@ -41,9 +43,6 @@ prompt_library: PromptLibrary = PromptLibrary(prompts={})
|
|||
system_data: Dict[str, Any] = {}
|
||||
|
||||
|
||||
# TODO: where should this one go?
|
||||
character_agents: Dict[str, Tuple[Character, Agent]] = {}
|
||||
|
||||
STRING_EVENT_TYPE = "message"
|
||||
|
||||
|
||||
|
|
|
@ -38,6 +38,9 @@ from taleweave.utils.string import normalize_name
|
|||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
MAX_NAME_LENGTH = 50
|
||||
DISALLOWED_PUNCTUATION = ['"', ":"]
|
||||
|
||||
|
||||
def get_world_config():
|
||||
config = get_game_config()
|
||||
|
@ -58,12 +61,12 @@ def duplicate_name_parser(existing_names: List[str]):
|
|||
format_prompt("world_generate_error_name_json", name=value)
|
||||
)
|
||||
|
||||
if '"' in value or ":" in value:
|
||||
if any(p in value for p in DISALLOWED_PUNCTUATION):
|
||||
raise ValueError(
|
||||
format_prompt("world_generate_error_name_punctuation", name=value)
|
||||
)
|
||||
|
||||
if len(value) > 50:
|
||||
if len(value) > MAX_NAME_LENGTH:
|
||||
raise ValueError(
|
||||
format_prompt("world_generate_error_name_length", name=value)
|
||||
)
|
||||
|
@ -99,6 +102,8 @@ def generate_room(
|
|||
agent: Agent,
|
||||
world: World,
|
||||
systems: List[GameSystem],
|
||||
current_room: int | None = None,
|
||||
total_rooms: int | None = None,
|
||||
) -> Room:
|
||||
existing_rooms = [room.name for room in list_rooms(world)]
|
||||
|
||||
|
@ -108,6 +113,8 @@ def generate_room(
|
|||
context={
|
||||
"world_theme": world.theme,
|
||||
"existing_rooms": existing_rooms,
|
||||
"current_room": current_room,
|
||||
"total_rooms": total_rooms,
|
||||
},
|
||||
result_parser=duplicate_name_parser(existing_rooms),
|
||||
toolbox=None,
|
||||
|
@ -575,9 +582,11 @@ def generate_world(
|
|||
set_system_data(system.name, data)
|
||||
|
||||
# generate the rooms
|
||||
for _ in range(room_count):
|
||||
for i in range(room_count):
|
||||
try:
|
||||
room = generate_room(agent, world, systems)
|
||||
room = generate_room(
|
||||
agent, world, systems, current_room=i, total_rooms=room_count
|
||||
)
|
||||
generate_system_attributes(agent, world, room, systems)
|
||||
broadcast_generated(entity=room)
|
||||
world.rooms.append(room)
|
||||
|
|
|
@ -299,7 +299,9 @@ def load_or_generate_world(
|
|||
new_rooms = []
|
||||
for i in range(add_rooms):
|
||||
logger.info(f"generating room {i + 1} of {add_rooms}")
|
||||
room = generate_room(world_builder, world, systems)
|
||||
room = generate_room(
|
||||
world_builder, world, systems, current_room=i, total_rooms=add_rooms
|
||||
)
|
||||
new_rooms.append(room)
|
||||
world.rooms.append(room)
|
||||
|
||||
|
|
Loading…
Reference in New Issue