Spaces:
Runtime error
Runtime error
Commit
·
4fe3d9c
1
Parent(s):
0a1d181
Unit testing the decider questions
Browse files- app.py +2 -1
- decider_questions.py +1 -1
- decider_utils.py +16 -0
- run_unit_tests.py +12 -11
app.py
CHANGED
|
@@ -83,7 +83,8 @@ def run_1_game_turn(s_narr_transcript, s_n_turns_elapsed, s_user_transcript, s_u
|
|
| 83 |
elif decider_utils.yesno(QUESTION_IS_ACTION_LIKELY_LETHAL, s_user_input, default=NO):
|
| 84 |
finally_add2_both_tscripts += game_over_fail_txt("You have taken an action that is likely to result in killing someone.")
|
| 85 |
|
| 86 |
-
elif decider_utils.yesno(QUESTION_IS_USER_ENGAGED_WITH_BANDITS, s_narr_transcript, default=NO)
|
|
|
|
| 87 |
finally_add2_both_tscripts += "Invalid entry. You cannot outrun these bandits.\n"
|
| 88 |
|
| 89 |
elif decider_utils.yesno(QUESTION_IS_ACTION_MAGIC, s_user_input, default=NO):
|
|
|
|
| 83 |
elif decider_utils.yesno(QUESTION_IS_ACTION_LIKELY_LETHAL, s_user_input, default=NO):
|
| 84 |
finally_add2_both_tscripts += game_over_fail_txt("You have taken an action that is likely to result in killing someone.")
|
| 85 |
|
| 86 |
+
elif decider_utils.yesno(QUESTION_IS_USER_ENGAGED_WITH_BANDITS, s_narr_transcript, default=NO) \
|
| 87 |
+
and decider_utils.special_case_is_running_away(s_user_input):
|
| 88 |
finally_add2_both_tscripts += "Invalid entry. You cannot outrun these bandits.\n"
|
| 89 |
|
| 90 |
elif decider_utils.yesno(QUESTION_IS_ACTION_MAGIC, s_user_input, default=NO):
|
decider_questions.py
CHANGED
|
@@ -2,6 +2,6 @@ QUESTION_IS_USER_HOME = "At the end of the above story, is the protagonist locat
|
|
| 2 |
QUESTION_DOES_USER_STILL_HAVE_AT_LEAST_30_GOLD = "At the end of the above story, does the protagonist still have at least 30 gold pieces?"
|
| 3 |
QUESTION_IS_USER_ENGAGED_WITH_BANDITS = "At the end of the above story, is the protagonist currently still engaged in a standoff with bandits?"
|
| 4 |
QUESTION_IS_ACTION_LIKELY_LETHAL = "Is the action just described likely to result in anyone dying?"
|
| 5 |
-
QUESTION_IS_ACTION_RUNNING_AWAY = 'Does
|
| 6 |
QUESTION_IS_ACTION_MAGIC = "Is the action just described an example of using supernatural magical spells / potions / etc?"
|
| 7 |
QUESTION_DID_PROTAGONIST_KILL = "In the story segment above, did the protagonist kill anyone?"
|
|
|
|
| 2 |
QUESTION_DOES_USER_STILL_HAVE_AT_LEAST_30_GOLD = "At the end of the above story, does the protagonist still have at least 30 gold pieces?"
|
| 3 |
QUESTION_IS_USER_ENGAGED_WITH_BANDITS = "At the end of the above story, is the protagonist currently still engaged in a standoff with bandits?"
|
| 4 |
QUESTION_IS_ACTION_LIKELY_LETHAL = "Is the action just described likely to result in anyone dying?"
|
| 5 |
+
QUESTION_IS_ACTION_RUNNING_AWAY = 'Does that sentence describe the act of fleeing?'
|
| 6 |
QUESTION_IS_ACTION_MAGIC = "Is the action just described an example of using supernatural magical spells / potions / etc?"
|
| 7 |
QUESTION_DID_PROTAGONIST_KILL = "In the story segment above, did the protagonist kill anyone?"
|
decider_utils.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import openai
|
|
|
|
| 2 |
|
| 3 |
YES = True
|
| 4 |
NO = False
|
|
@@ -30,3 +31,18 @@ def yesno(question, text, default):
|
|
| 30 |
result = YES
|
| 31 |
|
| 32 |
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import openai
|
| 2 |
+
import decider_questions
|
| 3 |
|
| 4 |
YES = True
|
| 5 |
NO = False
|
|
|
|
| 31 |
result = YES
|
| 32 |
|
| 33 |
return result
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
# In certain cases, I need more special-case logic in order to behave correctly,
|
| 37 |
+
# which we verify using the unit tests in run_unit_tests.py:
|
| 38 |
+
|
| 39 |
+
def special_case_is_running_away(text):
|
| 40 |
+
might_really_be_fleeing = False
|
| 41 |
+
for keyword in ["run", "away", "hide", "escape", "flee", "sprint", "teleport"]:
|
| 42 |
+
if keyword in text.lower():
|
| 43 |
+
might_really_be_fleeing = True
|
| 44 |
+
|
| 45 |
+
if might_really_be_fleeing:
|
| 46 |
+
return yesno(decider_questions.QUESTION_IS_ACTION_RUNNING_AWAY, text, default=NO)
|
| 47 |
+
else:
|
| 48 |
+
return NO
|
run_unit_tests.py
CHANGED
|
@@ -1,25 +1,26 @@
|
|
| 1 |
#! /usr/bin/env python3
|
| 2 |
|
|
|
|
| 3 |
import openai
|
| 4 |
|
| 5 |
openai.organization = os.environ.get("OPENAI_ORGANIZATION")
|
| 6 |
openai.api_key = os.environ.get("OPENAI_KEY")
|
| 7 |
|
| 8 |
|
| 9 |
-
from decider_utils import
|
| 10 |
from decider_questions import *
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
-
assert YES ==
|
| 15 |
-
assert YES ==
|
| 16 |
-
assert YES ==
|
| 17 |
-
assert YES ==
|
| 18 |
|
| 19 |
-
assert NO ==
|
| 20 |
-
assert NO ==
|
| 21 |
-
assert NO ==
|
| 22 |
-
assert NO ==
|
| 23 |
-
assert NO ==
|
| 24 |
-
assert NO ==
|
| 25 |
|
|
|
|
| 1 |
#! /usr/bin/env python3
|
| 2 |
|
| 3 |
+
import os
|
| 4 |
import openai
|
| 5 |
|
| 6 |
openai.organization = os.environ.get("OPENAI_ORGANIZATION")
|
| 7 |
openai.api_key = os.environ.get("OPENAI_KEY")
|
| 8 |
|
| 9 |
|
| 10 |
+
from decider_utils import YES, NO, yesno, special_case_is_running_away
|
| 11 |
from decider_questions import *
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
+
assert YES == special_case_is_running_away("run away")
|
| 16 |
+
assert YES == special_case_is_running_away("I run away")
|
| 17 |
+
assert YES == special_case_is_running_away("flee")
|
| 18 |
+
assert YES == special_case_is_running_away("I flee.")
|
| 19 |
|
| 20 |
+
assert NO == special_case_is_running_away("A")
|
| 21 |
+
assert NO == special_case_is_running_away("B")
|
| 22 |
+
assert NO == special_case_is_running_away("C")
|
| 23 |
+
assert NO == special_case_is_running_away("ok")
|
| 24 |
+
assert NO == special_case_is_running_away("say ok")
|
| 25 |
+
assert NO == special_case_is_running_away("say okay")
|
| 26 |
|