PAYADOR-experiments / prompts.py
sgongora27's picture
init
2b659a0
raw
history blame
12 kB
def prompt_describe_objective (objective, language:str = 'en') -> str:
prompt = ""
if language == 'es':
prompt = prompt_describe_objective_spanish(objective)
else:
prompt = prompt_describe_objective_english(objective)
return prompt
def prompt_describe_objective_english (objective) -> str:
prompt = "Please, provide an alternative way to narrate the following objective, using simple language: "
first_component_class = objective[0].__class__.__name__
second_component_class = objective[1].__class__.__name__
if first_component_class == "Character" and second_component_class == "Location":
prompt+= f'"You have to go to <{objective[1].name}>."'
elif first_component_class == "Character" and second_component_class == "Item":
prompt+= f'"<{objective[0].name}> has to get the item <{objective[1].name}>."'
elif first_component_class == "Item" and second_component_class == "Location":
prompt+= f'"You have to leave item <{objective[0].name}> in place <{objective[1].name}>."'
prompt+="\nPut your generated narration between # characters. For example: # You have to get the <key> # or # You have to reach the <castle> #"
return prompt
def prompt_describe_objective_spanish (objective) -> str:
prompt = "Por favor, dame una forma alternativa de narrar el siguiente objetivo, usando lenguaje simple: "
first_component_class = objective[0].__class__.__name__
second_component_class = objective[1].__class__.__name__
if first_component_class == "Character" and second_component_class == "Location":
prompt+= f'"Tienes que ir a <{objective[1].name}>."'
elif first_component_class == "Character" and second_component_class == "Item":
prompt+= f'"<{objective[0].name}> tiene que conseguir el objeto <{objective[1].name}>."'
elif first_component_class == "Item" and second_component_class == "Location":
prompt+= f'"Tienes que dejar el objeto <{objective[0].name}> en el lugar <{objective[1].name}>."'
prompt+="\nPon tu narración generada entre caracteres #. Por ejemplo: # Tienes que conseguir la <llave> # o # Tienes que llegaral <Castillo> #"
return prompt
def prompt_narrate_current_scene (world_state: str, previous_narrations: 'list[str]', language: str = 'en', starting_scene: bool = False) -> str:
prompt = ""
if language == 'es':
prompt = prompt_narrate_current_scene_spanish(world_state, previous_narrations, starting_scene)
else:
prompt = prompt_narrate_current_scene_english(world_state, previous_narrations, starting_scene)
return prompt
def prompt_narrate_current_scene_english (world_state: str, previous_narrations: 'list[str]', starting_scene: bool = False) -> str:
prompt = "You are a storyteller. Take the following state of the world and narrate it in a few sentences. Be careful not to include details that contradict the current state of the world or that move the story forward. Also, try to use simple sentences and do not overuse poetic language.\n"
if starting_scene:
prompt += "\nTake into account that this is the first scene in the story: introduce the main character, creating a small background story and why that character is in that specific location.\n"
elif len(previous_narrations)==0:
prompt += "Take into account that the player already knows what the main character looks like, so do not mention anything about that. However, it is the first time the player visits this place, so make sure to describe it exhaustively."
else:
prompt += "Take into account that the player already knows what the main character looks like, so do not mention anything about that. Additionally, it is not the first time the player visits this place. Next I’ll give you some previous narrations of this same location (from oldest to newest) so you can be sure to not repeat the same details again:\n"
for narration in previous_narrations:
prompt+=f'- {narration}\n'
prompt+= "\nRemember: you are talking to the player, describing what his or her character has and what he or she can see or feel."
prompt +=f"""This is the state of the world at the moment:
{world_state}
"""
return prompt
def prompt_narrate_current_scene_spanish (world_state: str, previous_narrations: 'list[str]', starting_scene: bool = False) -> str:
prompt = f"""Eres un narrador. Toma el siguiente estado del mundo y nárralo en unas pocas oraciones. Ten cuidado de no incluir detalles que contradigan el estado del mundo actual, o que hagan avanzar la historia. Además, intenta usar oraciones simples, sin abusar del lenguaje poético."""
if starting_scene:
prompt += "\nTen en cuenta que esta es la primera escena en la historia narradad: presenta al personaje del jugador, creando un pequeño trasfondo y por qué este personaje está en ese lugar específicamente.\n"
elif len(previous_narrations)==0:
prompt += "Ten en cuenta que el jugador ya conoce a su personaje, y cómo se ve, así que no menciones nada sobre esto. Sin embargo, es la primera vez que el jugador visita este lugar, así que describelo exaustivamente."
else:
prompt += "Ten en cuenta que el jugador ya conoce a s upersonaje, y cómo se ve, así que no menciones nada sobre esto. Además, no es la primera vez que el jugador visita este lugar. A continuación te daré algunas narraciones previas de este mismo lugar (de la más antigua a la más nueva), así te puedes asegurar de no repetir los mismos detalles de nuevo:\n"
for narration in previous_narrations:
prompt+=f'- {narration}\n'
prompt+= "\nRecuerda: le estás hablando al jugador, describiendo lo que su personaje tiene y lo que puede sentir o ver."
prompt +=f"""Este es el estado del mundo en este momnto:
{world_state}
"""
return prompt
def prompt_world_update (world_state: str, input: str, language: str = 'en') -> str:
prompt = ""
if language == 'es':
prompt = prompt_world_update_spanish(world_state, input)
else:
prompt = prompt_world_update_english(world_state, input)
return prompt
def prompt_world_update_spanish (world_state: str, input: str) -> str:
prompt = f"""Eres un narrador. Estás manejando un mundo ficticio, y el jugador puede interactuar con él. Este es el estado del mundo en este momento:
{world_state}\n\n
Explica los cambios en el mundo a partir de las acciones del jugador en esta entrada "{input}".
Aquí hay algunas aclaraciones:
(A) Si un pasaje está bloqueado, significa que el jugador debe desbloquearlo antes de poder acceder al lugar. Aunque el jugador te diga que va a acceder al lugar bloqueado, tienes que estar seguro de que está cumpliendo con lo pedido para permitirle desbloquear el acceso, por ejemplo usando una llave o resolviendo un puzzle.
(B) Presta atención a a la descripción de los componentes y sus capacidades.
(C) No asumas que lo que dice el jugador siempre tiene sentido; quizás esas acciones intentan hacer algo que el mundo no lo permite.
(D) Sigue siempre el siguiente formato con las tres categorías, usando "None" en cada caso si no hay cambios y repite la categoría por cada caso:
- Moved object: <object> now is in <new_location>
- Blocked passages now available: <now_reachable_location>
- Your location changed: <new_location>
Aquí hay algunos ejemplos sobre el formato, descrito en el anterior punto (D).
Ejemplo 1
- Moved object: <hacha> now is in <Inventory>
- Blocked passages now available: None
- Your location changed: None
Ejemplo 2
- Moved object: None
- Blocked passages now available: None
- Your location changed: <Jardín>
Ejemplo 3
- Moved object: <banana> now is in <Inventory>, <botella> now is in <Inventory>, <hacha> now is in <Hall principal>
- Blocked passages now available: None
- Your location changed: None
Ejemplo 4
- Moved object: <banana> now is in <Inventory>, <botella> now is in <Inventory>, <hacha> now is in <Hall principal>
- Blocked passages now available: <Pequeña habitación>
- Your location changed: None
Ejemplo 5
- Moved object: <banana> now is in <Inventory>, <botella> now is in <Inventory>, <hacha> now is in <Hall principal>
- Blocked passages now available: <Pequeña habitación>
- Your location changed: <Pequeña habitación>
Ejemplo 6
- Moved object: <libro> now is in <John>, <lápiz> now is in <Inventory>
- Blocked passages now available: None
- Your location changed: None
Ejemplo 7
- Moved object: <computadora> now is in <Susan>
- Blocked passages now available: None
- Your location changed: None
Por último, puedes agregar una pequeña oración final narrando los cambios detecados en el estado del mundo (¡sin hacer avanzar la historia y sin crear detalles no incluidos en el estado del mundo!) o respondiendo una pregunta del jugador sobre el estado del mundo, usando el formato: #<tu oración final>#
"""
return prompt
def prompt_world_update_english (world_state: str, input: str) -> str:
prompt = f"""You are a storyteller. You are managing a fictional world, and the player can interact with it. This is the state of the world at the moment:
{world_state}\n\n
Explain the changes in the world after the player actions in this input "{input}".
Here are some clarifications:
(A) If a passage is blocked, then the player must unblock it before being able to reach the place. Even if the player tells you that he is going to access the locked location, you have to be sure that he is complying with what you asked to allow him to unlock the access, for example by using a key or solving a puzzle.
(B) Pay atenttion to the description of the components and their capabilities.
(C) Do not assume that the player input always make sense; maybe those actions try to do something that the world does not allow.
(D) Follow always the following format with the three categories, using "None" in each case if there are no changes and repeat the category for each case:
- Moved object: <object> now is in <new_location>
- Blocked passages now available: <now_reachable_location>
- Your location changed: <new_location>
Here you have some examples.
Example 1
- Moved object: <axe> now is in <Inventory>
- Blocked passages now available: None
- Your location changed: None
Example 2
- Moved object: None
- Blocked passages now available: None
- Your location changed: <Garden>
Example 3
- Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
- Blocked passages now available: None
- Your location changed: None
Example 4
- Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
- Blocked passages now available: <Small room>
- Your location changed: None
Example 5
- Moved object: <banana> now is in <Inventory>, <bottle> now is in <Inventory>, <axe> now is in <Main Hall>
- Blocked passages now available: <Small room>
- Your location changed: <Small room>
Example 6
- Moved object: <book> now is in <John>, <pencil> now is in <Inventory>
- Blocked passages now available: None
- Your location changed: None
Example 7
- Moved object: <computer> now is in <Susan>
- Blocked passages now available: None
- Your location changed: None
Finally, you can add a final short sentence narrating the detected changes in the state of the world (without moving the story forward and creating details not included in the state of the world!) or answering a question of the player about the state of the world, using the format: #<your final sentence>#
"""
return prompt