make system format return a list of labels
This commit is contained in:
parent
288fb476a4
commit
60fb4c94cf
|
@ -212,7 +212,8 @@ prompts:
|
||||||
You are an experienced dungeon master creating a visually detailed world for a new adventure set in {{theme | punctuate}} Be
|
You are an experienced dungeon master creating a visually detailed world for a new adventure set in {{theme | punctuate}} Be
|
||||||
creative and original, creating a world that is visually detailed, consistent, and plausible within the context of
|
creative and original, creating a world that is visually detailed, consistent, and plausible within the context of
|
||||||
the setting. Do not repeat yourself unless you are given the same prompt with the same characters, room, and
|
the setting. Do not repeat yourself unless you are given the same prompt with the same characters, room, and
|
||||||
context. {{flavor | punctuate}} The theme of the world must be: {{theme | punctuate}}
|
context. {{flavor | punctuate}}
|
||||||
|
The theme of the world must be: {{theme | punctuate}}
|
||||||
|
|
||||||
world_generate_world_broadcast_theme: |
|
world_generate_world_broadcast_theme: |
|
||||||
Generating a {{theme}} with {{room_count}} rooms
|
Generating a {{theme}} with {{room_count}} rooms
|
||||||
|
@ -344,13 +345,15 @@ prompts:
|
||||||
|
|
||||||
# world simulation
|
# world simulation
|
||||||
world_simulate_character_action: |
|
world_simulate_character_action: |
|
||||||
You are currently in the {{room | name}} room. {{room | describe}}. {{attributes}}.
|
You are currently in the {{room | name}} room. {{room | describe | punctuate}}
|
||||||
The room contains the following characters: {{visible_characters}}.
|
{{'\n'.join(attributes) | punctuate}}
|
||||||
The room contains the following items: {{visible_items}}.
|
The room contains the following characters: {{visible_characters | and_list}}.
|
||||||
Your inventory contains the following items: {{character_items}}.
|
The room contains the following items: {{visible_items | and_list}}.
|
||||||
You can take the following actions: {{actions}}.
|
Your inventory contains the following items: {{character_items | and_list}}.
|
||||||
You can move in the following directions: {{directions}}.
|
You can take the following actions: {{actions | and_list}}.
|
||||||
{{notes_prompt}} {{events_prompt}}
|
You can move in the following directions: {{directions | and_list}}.
|
||||||
|
{{notes_prompt}}
|
||||||
|
{{events_prompt}}
|
||||||
What will you do next? Reply with a JSON function call, calling one of the actions.
|
What will you do next? Reply with a JSON function call, calling one of the actions.
|
||||||
You can only perform one action per turn. What is your next action?
|
You can only perform one action per turn. What is your next action?
|
||||||
world_simulate_character_action_error_json: |
|
world_simulate_character_action_error_json: |
|
||||||
|
@ -367,11 +370,12 @@ prompts:
|
||||||
You can check your notes for important facts or check your calendar for upcoming events. You have {{note_count}} notes.
|
You can check your notes for important facts or check your calendar for upcoming events. You have {{note_count}} notes.
|
||||||
If you have plans with other characters, schedule them on your calendar. You have {{event_count}} events on your calendar.
|
If you have plans with other characters, schedule them on your calendar. You have {{event_count}} events on your calendar.
|
||||||
{{room_summary}}
|
{{room_summary}}
|
||||||
Think about your goals and any quests that you are working on, and plan your next action accordingly.
|
|
||||||
Try to keep your notes accurate and up-to-date. Replace or erase old notes when they are no longer accurate or useful.
|
Try to keep your notes accurate and up-to-date. Replace or erase old notes when they are no longer accurate or useful.
|
||||||
Do not keeps notes about upcoming events, use your calendar for that.
|
Do not keeps notes about upcoming events, use your calendar for that.
|
||||||
|
{{notes_prompt}}
|
||||||
|
{{events_prompt}}
|
||||||
|
Think about your goals and any quests that you are working on, and plan your next action accordingly.
|
||||||
You can perform up to 3 planning actions in a single turn. When you are done planning, reply with 'END'.
|
You can perform up to 3 planning actions in a single turn. When you are done planning, reply with 'END'.
|
||||||
{{notes_prompt}} {{events_prompt}}
|
|
||||||
world_simulate_character_planning_done: |
|
world_simulate_character_planning_done: |
|
||||||
You are done planning your turn.
|
You are done planning your turn.
|
||||||
world_simulate_character_planning_notes_some: |
|
world_simulate_character_planning_notes_some: |
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import Any, Callable, Protocol
|
from typing import Any, Callable, List, Protocol
|
||||||
|
|
||||||
from packit.agent import Agent
|
from packit.agent import Agent
|
||||||
|
|
||||||
|
@ -17,8 +17,12 @@ class SystemFormat(Protocol):
|
||||||
self,
|
self,
|
||||||
entity: WorldEntity,
|
entity: WorldEntity,
|
||||||
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
||||||
) -> str:
|
) -> List[str]:
|
||||||
# TODO: should this return a list?
|
"""
|
||||||
|
Format the given world entity for the given perspective.
|
||||||
|
|
||||||
|
Returns a list of phrases or lines that should be added to the entity's description.
|
||||||
|
"""
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -122,12 +122,12 @@ def digest_listener(event: GameEvent):
|
||||||
def format_digest(
|
def format_digest(
|
||||||
entity: WorldEntity,
|
entity: WorldEntity,
|
||||||
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
||||||
) -> str:
|
) -> List[str]:
|
||||||
if not isinstance(entity, Character):
|
if not isinstance(entity, Character):
|
||||||
return ""
|
return []
|
||||||
|
|
||||||
if perspective != FormatPerspective.SECOND_PERSON:
|
if perspective != FormatPerspective.SECOND_PERSON:
|
||||||
return ""
|
return []
|
||||||
|
|
||||||
buffer = character_buffers[entity.name]
|
buffer = character_buffers[entity.name]
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ def format_digest(
|
||||||
raise ValueError("Character not found in any room")
|
raise ValueError("Character not found in any room")
|
||||||
|
|
||||||
digest = create_turn_digest(world, room, entity, buffer)
|
digest = create_turn_digest(world, room, entity, buffer)
|
||||||
return "\n".join(digest)
|
return digest
|
||||||
|
|
||||||
|
|
||||||
def generate_digest(agent: Any, world: World, entity: WorldEntity):
|
def generate_digest(agent: Any, world: World, entity: WorldEntity):
|
||||||
|
|
|
@ -152,7 +152,7 @@ def format_logic(
|
||||||
entity: WorldEntity,
|
entity: WorldEntity,
|
||||||
rules: LogicTable,
|
rules: LogicTable,
|
||||||
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
||||||
) -> str:
|
) -> List[str]:
|
||||||
labels = []
|
labels = []
|
||||||
|
|
||||||
for label in rules.labels:
|
for label in rules.labels:
|
||||||
|
@ -167,7 +167,7 @@ def format_logic(
|
||||||
if len(labels) > 0:
|
if len(labels) > 0:
|
||||||
logger.debug("adding attribute labels: %s", labels)
|
logger.debug("adding attribute labels: %s", labels)
|
||||||
|
|
||||||
return " ".join(labels)
|
return labels
|
||||||
|
|
||||||
|
|
||||||
def load_logic(filename: str, name_prefix: str = "logic") -> GameSystem:
|
def load_logic(filename: str, name_prefix: str = "logic") -> GameSystem:
|
||||||
|
|
|
@ -199,4 +199,5 @@ def simulate_planning(world: World, turn: int, data: Any | None = None):
|
||||||
|
|
||||||
|
|
||||||
def init_planning():
|
def init_planning():
|
||||||
|
# TODO: add format method that renders the recent notes and upcoming events
|
||||||
return [GameSystem("planning", simulate=simulate_planning)]
|
return [GameSystem("planning", simulate=simulate_planning)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from taleweave.context import get_game_systems
|
from taleweave.context import get_game_systems
|
||||||
from taleweave.game_system import FormatPerspective
|
from taleweave.game_system import FormatPerspective
|
||||||
|
@ -25,7 +26,8 @@ def describe_character(
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Perspective {perspective} is not implemented")
|
raise ValueError(f"Perspective {perspective} is not implemented")
|
||||||
|
|
||||||
return f"{character_description} {attribute_descriptions}"
|
# TODO: use template
|
||||||
|
return f"{character_description} {'. '.join(attribute_descriptions)}"
|
||||||
|
|
||||||
|
|
||||||
def describe_static(entity: WorldEntity) -> str:
|
def describe_static(entity: WorldEntity) -> str:
|
||||||
|
@ -35,7 +37,9 @@ def describe_static(entity: WorldEntity) -> str:
|
||||||
entity.name,
|
entity.name,
|
||||||
attribute_descriptions,
|
attribute_descriptions,
|
||||||
)
|
)
|
||||||
return f"{entity.description} {attribute_descriptions}"
|
|
||||||
|
# TODO: use template
|
||||||
|
return f"{entity.description} {'. '.join(attribute_descriptions)}"
|
||||||
|
|
||||||
|
|
||||||
def describe_entity(
|
def describe_entity(
|
||||||
|
@ -51,20 +55,22 @@ def describe_entity(
|
||||||
def format_attributes(
|
def format_attributes(
|
||||||
entity: WorldEntity,
|
entity: WorldEntity,
|
||||||
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
perspective: FormatPerspective = FormatPerspective.SECOND_PERSON,
|
||||||
) -> str:
|
) -> List[str]:
|
||||||
systems = get_game_systems()
|
systems = get_game_systems()
|
||||||
attribute_descriptions = [
|
attribute_descriptions = []
|
||||||
system.format(entity, perspective=perspective)
|
for system in systems:
|
||||||
for system in systems
|
if system.format:
|
||||||
if system.format
|
attribute_descriptions.extend(
|
||||||
]
|
system.format(entity, perspective=perspective)
|
||||||
|
)
|
||||||
|
|
||||||
attribute_descriptions = [
|
attribute_descriptions = [
|
||||||
description
|
description
|
||||||
for description in attribute_descriptions
|
for description in attribute_descriptions
|
||||||
if len(description.strip()) > 0
|
if len(description.strip()) > 0
|
||||||
]
|
]
|
||||||
|
|
||||||
return f"{'. '.join(attribute_descriptions)}"
|
return attribute_descriptions
|
||||||
|
|
||||||
|
|
||||||
def name_entity(
|
def name_entity(
|
||||||
|
|
Loading…
Reference in New Issue