add room count as an argument
This commit is contained in:
parent
e803f40b75
commit
77ef4610b3
|
@ -1,3 +1,4 @@
|
||||||
adventure/custom_actions.py
|
adventure/custom_actions.py
|
||||||
worlds/
|
worlds/
|
||||||
__pycache__/
|
__pycache__/
|
||||||
|
.env
|
||||||
|
|
|
@ -84,7 +84,7 @@ def action_ask(character: str, question: str) -> str:
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
if character == action_actor.name:
|
if character == action_actor.name:
|
||||||
return "You cannot ask yourself a question. You have wasted your turn. Stop talking to yourself."
|
return "You cannot ask yourself a question. Stop talking to yourself. Try another action."
|
||||||
|
|
||||||
question_actor, question_agent = get_actor_agent_for_name(character)
|
question_actor, question_agent = get_actor_agent_for_name(character)
|
||||||
if not question_actor:
|
if not question_actor:
|
||||||
|
@ -120,7 +120,7 @@ def action_tell(character: str, message: str) -> str:
|
||||||
|
|
||||||
# sanity checks
|
# sanity checks
|
||||||
if character == action_actor.name:
|
if character == action_actor.name:
|
||||||
return "You cannot tell yourself a message. You have wasted your turn. Stop talking to yourself."
|
return "You cannot tell yourself a message. Stop talking to yourself. Try another action."
|
||||||
|
|
||||||
question_actor, question_agent = get_actor_agent_for_name(character)
|
question_actor, question_agent = get_actor_agent_for_name(character)
|
||||||
if not question_actor:
|
if not question_actor:
|
||||||
|
|
|
@ -80,7 +80,8 @@ def generate_actor(
|
||||||
logger.info(f"Generating actor: {name}")
|
logger.info(f"Generating actor: {name}")
|
||||||
description = agent(
|
description = agent(
|
||||||
"Generate a detailed description of the {name} character. What do they look like? What are they wearing? "
|
"Generate a detailed description of the {name} character. What do they look like? What are they wearing? "
|
||||||
"What are they doing? Describe their appearance from the perspective of an outside observer.",
|
"What are they doing? Describe their appearance from the perspective of an outside observer."
|
||||||
|
"Do not include the room or any other characters in the description, because they will move around.",
|
||||||
name=name,
|
name=name,
|
||||||
)
|
)
|
||||||
backstory = agent(
|
backstory = agent(
|
||||||
|
@ -101,8 +102,10 @@ def generate_actor(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def generate_world(agent: Agent, name: str, theme: str) -> World:
|
def generate_world(
|
||||||
room_count = randint(3, 5)
|
agent: Agent, name: str, theme: str, rooms: int | None = None, max_rooms: int = 5
|
||||||
|
) -> World:
|
||||||
|
room_count = rooms or randint(3, max_rooms)
|
||||||
logger.info(f"Generating a {theme} with {room_count} rooms")
|
logger.info(f"Generating a {theme} with {room_count} rooms")
|
||||||
|
|
||||||
existing_actors: List[str] = []
|
existing_actors: List[str] = []
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from json import load
|
from json import load
|
||||||
from os import path
|
from os import environ, path
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
from packit.agent import Agent, agent_easy_connect
|
from packit.agent import Agent, agent_easy_connect
|
||||||
from packit.loops import loop_tool
|
from packit.loops import loop_retry
|
||||||
from packit.results import multi_function_or_str_result
|
from packit.results import multi_function_or_str_result
|
||||||
from packit.toolbox import Toolbox
|
from packit.toolbox import Toolbox
|
||||||
from packit.utils import logger_with_colors
|
from packit.utils import logger_with_colors
|
||||||
|
@ -32,6 +33,8 @@ from adventure.state import create_agents, save_world, save_world_state
|
||||||
|
|
||||||
logger = logger_with_colors(__name__)
|
logger = logger_with_colors(__name__)
|
||||||
|
|
||||||
|
load_dotenv(environ.get("ADVENTURE_ENV", ".env"), override=True)
|
||||||
|
|
||||||
|
|
||||||
# simulation
|
# simulation
|
||||||
def world_result_parser(value, agent, **kwargs):
|
def world_result_parser(value, agent, **kwargs):
|
||||||
|
@ -97,7 +100,7 @@ def simulate_world(world: World, steps: int = 10, callback=None, extra_actions=[
|
||||||
room_directions = list(room.portals.keys())
|
room_directions = list(room.portals.keys())
|
||||||
|
|
||||||
logger.info("starting actor %s turn", actor.name)
|
logger.info("starting actor %s turn", actor.name)
|
||||||
result = loop_tool(
|
result = loop_retry(
|
||||||
agent,
|
agent,
|
||||||
(
|
(
|
||||||
"You are currently in {room_name}. {room_description}. "
|
"You are currently in {room_name}. {room_description}. "
|
||||||
|
@ -121,7 +124,7 @@ def simulate_world(world: World, steps: int = 10, callback=None, extra_actions=[
|
||||||
toolbox=action_tools,
|
toolbox=action_tools,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info(f"{actor.name} step result: {result}")
|
logger.debug(f"{actor.name} step result: {result}")
|
||||||
agent.memory.append(result)
|
agent.memory.append(result)
|
||||||
|
|
||||||
if callback:
|
if callback:
|
||||||
|
@ -146,6 +149,12 @@ def parse_args():
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--player", type=str, help="The name of the character to play as"
|
"--player", type=str, help="The name of the character to play as"
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--rooms", type=int, default=5, help="The number of rooms to generate"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--max-rooms", type=int, help="The maximum number of rooms to generate"
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--state",
|
"--state",
|
||||||
type=str,
|
type=str,
|
||||||
|
@ -201,7 +210,9 @@ def main():
|
||||||
{},
|
{},
|
||||||
llm,
|
llm,
|
||||||
)
|
)
|
||||||
world = generate_world(agent, args.world, args.theme)
|
world = generate_world(
|
||||||
|
agent, args.world, args.theme, rooms=args.rooms, max_rooms=args.max_rooms
|
||||||
|
)
|
||||||
save_world(world, world_file)
|
save_world(world, world_file)
|
||||||
|
|
||||||
create_agents(world, memory=memory, players=players)
|
create_agents(world, memory=memory, players=players)
|
||||||
|
|
Loading…
Reference in New Issue