From f4bb76914b3b3b4637b00022136ecc0ccecf628f Mon Sep 17 00:00:00 2001
From: SereneWalden <22496084+SereneWalden@users.noreply.github.com>
Date: Thu, 5 Oct 2023 19:47:04 +0800
Subject: [PATCH] add prompt templates and testcases for gen_action_details.py
---
.../st_game/actions/gen_action_details.py | 42 +++--------
.../prompts/action_location_object_vMar11.txt | 30 ++++++++
.../prompts/action_location_sector_v1.txt | 34 +++++++++
examples/st_game/prompts/action_object_v2.txt | 32 ++++++++
.../prompts/generate_pronunciatio_v1.txt | 10 +++
.../tests/actions/test_gen_action_details.py | 73 +++++++++++++++++++
6 files changed, 188 insertions(+), 33 deletions(-)
create mode 100644 examples/st_game/prompts/action_location_object_vMar11.txt
create mode 100644 examples/st_game/prompts/action_location_sector_v1.txt
create mode 100644 examples/st_game/prompts/action_object_v2.txt
create mode 100644 examples/st_game/prompts/generate_pronunciatio_v1.txt
create mode 100644 examples/st_game/tests/actions/test_gen_action_details.py
diff --git a/examples/st_game/actions/gen_action_details.py b/examples/st_game/actions/gen_action_details.py
index 0b5a78913..a734315db 100644
--- a/examples/st_game/actions/gen_action_details.py
+++ b/examples/st_game/actions/gen_action_details.py
@@ -12,34 +12,6 @@ from ..roles.st_role import STRole
from ..maze import Maze
from .st_action import STAction
- # act_world = maze.access_tile(role.scratch.curr_tile)["world"]
- # act_sector = maze.access_tile(role.scratch.curr_tile)["sector"]
- # act_sector = generate_action_sector(act_desp, role, maze)
- # act_arena = generate_action_arena(act_desp, role, maze, act_world, act_sector)
- # act_address = f"{act_world}:{act_sector}:{act_arena}"
- # act_game_object = generate_action_game_object(act_desp, act_address,
- # role, maze)
- # new_address = f"{act_world}:{act_sector}:{act_arena}:{act_game_object}"
- # act_pron = generate_action_pronunciatio(act_desp, role)
- # act_event = generate_action_event_triple(act_desp, role)
- # # Persona's actions also influence the object states. We set those up here.
- # act_obj_desp = generate_act_obj_desc(act_game_object, act_desp, role)
- # act_obj_pron = generate_action_pronunciatio(act_obj_desp, role)
- # act_obj_event = generate_act_obj_event_triple(act_game_object,
- # act_obj_desp, role)
- # Adding the action to role's queue.
- # role.scratch.add_new_action(new_address,
- # int(act_dura),
- # act_desp,
- # act_pron,
- # act_event,
- # None,
- # None,
- # None,
- # None,
- # act_obj_desp,
- # act_obj_pron,
- # act_obj_event)
class GenActionSector(STAction):
@@ -259,7 +231,7 @@ class GenPronunciatio(STAction):
fs = "😋"
return fs
- def run(self, role: STRole, act_desp: str)
+ def run(self, role: STRole, act_desp: str):
def create_prompt_input(act_desp):
if "(" in act_desp:
act_desp = act_desp.split("(")[-1].split(")")[0]
@@ -377,15 +349,15 @@ class GenObjEventTriple(STAction):
fs = (act_game_object, "is", "idle")
return fs
- def run(self, role: STRole, act_game_object, act_obj_desc):
- def create_prompt_input(act_game_object, act_obj_desc):
+ def run(self, role: STRole, act_game_object, act_obj_desp):
+ def create_prompt_input(act_game_object, act_obj_desp):
prompt_input = [act_game_object,
- act_obj_desc,
+ act_obj_desp,
act_game_object]
return prompt_input
prompt_template = "generate_event_triple_v1.txt"
- prompt_input = create_prompt_input(act_game_object, act_obj_desc)
+ prompt_input = create_prompt_input(act_game_object, act_obj_desp)
prompt = self.generate_prompt_with_tmpl_filename(prompt_input, prompt_template)
self.fail_default_resp = self._func_fail_default_resp(role)
output = self._run_v1(prompt)
@@ -407,6 +379,10 @@ class GenActionDetails(STAction):
except:
return False
return True
+
+ def _func_fail_default_resp(self):
+ fs = {}
+ return fs
def run(self,
role: STRole,
diff --git a/examples/st_game/prompts/action_location_object_vMar11.txt b/examples/st_game/prompts/action_location_object_vMar11.txt
new file mode 100644
index 000000000..908750646
--- /dev/null
+++ b/examples/st_game/prompts/action_location_object_vMar11.txt
@@ -0,0 +1,30 @@
+Variables:
+!! -- Persona name
+!! -- Persona's current arena
+!! -- Persona's current sector
+!! -- Persona name
+!! -- target sector
+!! -- Persona's sector's all arenas (minus no access)
+!! -- Curr action seq
+!! -- Persona name
+!! -- Persona's current sector
+
+###
+Jane Anderson is in kitchen in Jane Anderson's house.
+Jane Anderson is going to Jane Anderson's house that has the following areas: {kitchen, bedroom, bathroom}
+Stay in the current area if the activity can be done there. Never go into other people's rooms unless necessary.
+For cooking, Jane Anderson should go to the following area in Jane Anderson's house:
+Answer: {kitchen}
+---
+Tom Watson is in common room in Tom Watson's apartment.
+Tom Watson is going to Hobbs Cafe that has the following areas: {cafe}
+Stay in the current area if the activity can be done there. Never go into other people's rooms unless necessary.
+For getting coffee, Tom Watson should go to the following area in Hobbs Cafe:
+Answer: {cafe}
+---
+
+!! is going to !! that has the following areas: {!!}
+* Stay in the current area if the activity can be done there.
+* NEVER go into other people's rooms unless necessary.
+!! is !!. For !!, !! should go to the following area in !! (MUST pick one of {!!}):
+Answer: {
\ No newline at end of file
diff --git a/examples/st_game/prompts/action_location_sector_v1.txt b/examples/st_game/prompts/action_location_sector_v1.txt
new file mode 100644
index 000000000..f93ed96e0
--- /dev/null
+++ b/examples/st_game/prompts/action_location_sector_v1.txt
@@ -0,0 +1,34 @@
+Variables:
+!! -- Persona name
+!! -- Maze all possible sectors
+!! -- Persona name
+!! -- Persona living sector
+!! -- Persona living sector arenas
+!! -- Persona name
+!! -- Persona current sector
+!! -- Persona current sector arenas
+!! -- curr action description
+!! -- Persona name
+###
+Task -- choose an appropriate area from the area options for a task at hand.
+
+Sam Kim lives in {Sam Kim's house} that has Sam Kim's room, bathroom, kitchen.
+Sam Kim is currently in {Sam Kim's house} that has Sam Kim's room, bathroom, kitchen.
+Area options: {Sam Kim's house, The Rose and Crown Pub, Hobbs Cafe, Oak Hill College, Johnson Park, Harvey Oak Supply Store, The Willows Market and Pharmacy}.
+* Stay in the current area if the activity can be done there. Only go out if the activity needs to take place in another place.
+* Must be one of the "Area options," verbatim.
+For taking a walk, Sam Kim should go to the following area: {Johnson Park}
+---
+Jane Anderson lives in {Oak Hill College Student Dormatory} that has Jane Anderson's room.
+Jane Anderson is currently in {Oak Hill College} that has a classroom, library
+Area options: {Oak Hill College Student Dormatory, The Rose and Crown Pub, Hobbs Cafe, Oak Hill College, Johnson Park, Harvey Oak Supply Store, The Willows Market and Pharmacy}.
+* Stay in the current area if the activity can be done there. Only go out if the activity needs to take place in another place.
+* Must be one of the "Area options," verbatim.
+For eating dinner, Jane Anderson should go to the following area: {Hobbs Cafe}
+---
+!! lives in {!!} that has !!.
+!! is currently in {!!} that has !!. !!
+Area options: {!!}.
+* Stay in the current area if the activity can be done there. Only go out if the activity needs to take place in another place.
+* Must be one of the "Area options," verbatim.
+!! is !!. For !!, !! should go to the following area: {
\ No newline at end of file
diff --git a/examples/st_game/prompts/action_object_v2.txt b/examples/st_game/prompts/action_object_v2.txt
new file mode 100644
index 000000000..1a8a78e16
--- /dev/null
+++ b/examples/st_game/prompts/action_object_v2.txt
@@ -0,0 +1,32 @@
+Variables:
+!! -- curr action seq
+!! -- Objects available
+
+###
+Current activity: sleep in bed
+Objects available: {bed, easel, closet, painting}
+Pick ONE most relevant object from the objects available: bed
+---
+Current activity: painting
+Objects available: {easel, closet, sink, microwave}
+Pick ONE most relevant object from the objects available: easel
+---
+Current activity: cooking
+Objects available: {stove, sink, fridge, counter}
+Pick ONE most relevant object from the objects available: stove
+---
+Current activity: watch TV
+Objects available: {couch, TV, remote, coffee table}
+Pick ONE most relevant object from the objects available: TV
+---
+Current activity: study
+Objects available: {desk, computer, chair, bookshelf}
+Pick ONE most relevant object from the objects available: desk
+---
+Current activity: talk on the phone
+Objects available: {phone, charger, bed, nightstand}
+Pick ONE most relevant object from the objects available: phone
+---
+Current activity: !!
+Objects available: {!!}
+Pick ONE most relevant object from the objects available:
\ No newline at end of file
diff --git a/examples/st_game/prompts/generate_pronunciatio_v1.txt b/examples/st_game/prompts/generate_pronunciatio_v1.txt
new file mode 100644
index 000000000..fd208df18
--- /dev/null
+++ b/examples/st_game/prompts/generate_pronunciatio_v1.txt
@@ -0,0 +1,10 @@
+generate_pronunciatio_v1.txt
+
+Variables:
+!! -- Action description
+
+###
+Convert an action description to an emoji (important: use two or less emojis).
+
+Action description: !!
+Emoji:
\ No newline at end of file
diff --git a/examples/st_game/tests/actions/test_gen_action_details.py b/examples/st_game/tests/actions/test_gen_action_details.py
new file mode 100644
index 000000000..c84de6e6d
--- /dev/null
+++ b/examples/st_game/tests/actions/test_gen_action_details.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# @Desc : unittest of actions/gen_action_details.py
+
+from examples.st_game.actions.gen_action_details import (
+ GenActionDetails,
+ GenActionArena,
+ GenActionSector,
+ GenActionObject,
+ GenActObjDescription,
+ GenEventTriple,
+ GenObjEventTriple,
+ GenPronunciatio
+ )
+from examples.st_game.roles.st_role import STRole
+
+role = STRole(name="Klaus Mueller", start_date="October 4, 2023", curr_time="October 4, 2023, 00:00:00",
+ sim_code="base_the_ville_isabella_maria_klaus")
+maze = role._rc.env.maze
+act_desp = "klaus mueller starts the day by making a coffee"
+act_dura = "20"
+act_world = maze.access_tile(role.scratch.curr_tile)["world"]
+assert act_world == "the Ville"
+
+sector = GenActionSector().run(role, maze, act_desp)
+arena = GenActionArena().run(role, maze, act_desp, act_world, sector)
+temp_address = f"{act_world}:{sector}:{arena}"
+obj = GenActionObject().run(role, act_desp, temp_address)
+
+act_obj_desp = GenActObjDescription().run(role, obj, act_desp)
+# event_triple = GenEventTriple().run(role, act_desp)
+# obj_triple = GenObjEventTriple().run(role, obj, act_obj_desp)
+
+result_dict = GenActionDetails().run(role, act_desp, act_dura)
+
+def test_gen_action_sector():
+ assert isinstance(sector, str)
+ assert sector in role.s_mem.get_str_accessible_sectors(act_world)
+
+def test_gen_action_arena():
+ assert isinstance(arena, str)
+ assert arena in role.s_mem.get_str_accessible_sector_arenas(f"{act_world}:{sector}")
+
+def test_gen_action_obj():
+ assert isinstance(obj, str)
+ assert obj in role.s_mem.get_str_accessible_arena_game_objects(temp_address)
+
+# def test_gen_event_triple():
+# assert len(event_triple) == 3
+
+# def test_gen_obj_event_triple():
+# assert len(obj_triple) == 3
+
+def test_gen_action_details():
+ if result_dict:
+ for key in [
+ "action_address",
+ "action_duration",
+ "act_desp",
+ "action_pronunciatio",
+ "action_event",
+ "chatting_with",
+ "chat",
+ "chatting_with_buffer",
+ "chatting_end_time",
+ "act_obj_description",
+ "act_obj_pronunciatio",
+ "act_obj_event"]:
+ assert key in result_dict
+ assert result_dict["action_address"] == f"{temp_address}:{obj}"
+ assert result_dict["action_duration"] == int(act_dura)
+ assert result_dict["act_obj_description"] == act_obj_desp
+
\ No newline at end of file