Spaces:
Runtime error
Runtime error
File size: 2,101 Bytes
b0e72b5 4fe3d9c b0e72b5 c7a90d5 b0e72b5 e7ea6a7 b0e72b5 c7a90d5 b0e72b5 c7a90d5 b0e72b5 c7a90d5 b0e72b5 4fe3d9c bd049e0 4fe3d9c c7a90d5 4fe3d9c c7a90d5 e7ea6a7 c7a90d5 e7ea6a7 c7a90d5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
import openai
import decider_questions
YES = True
NO = False
g_decider_utils_dbg_printing = False
def yesno(question, text, default):
global g_decider_utils_dbg_printing
prompt = text + "\n\n" + question
if g_decider_utils_dbg_printing:
print(prompt)
hopefully_word_yes_or_no = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt,
temperature=0,
max_tokens=20, # At first I tried max_tokens = 1 or 2, but the davinci-002 model produced zero output (immediate stop) unless I increased max_token to around 20
frequency_penalty=0,
presence_penalty=0,
n=1,
)["choices"][0]["text"]
if g_decider_utils_dbg_printing:
print(hopefully_word_yes_or_no)
hopefully_word_yes_or_no = hopefully_word_yes_or_no.upper().strip()
result = default
if default == YES:
if hopefully_word_yes_or_no.startswith("N"):
result = NO
if default == NO:
if hopefully_word_yes_or_no.startswith("Y"):
result = YES
return result
# In certain cases, I need more special-case logic in order to behave correctly,
# which we verify using the unit tests in run_unit_tests.py:
def special_case_is_running_away(text):
might_really_be_fleeing = False
for keyword in ["run", "away", "hide", "escape", "flee", "sprint", "teleport"]:
if keyword in text.lower():
might_really_be_fleeing = True
break
if might_really_be_fleeing:
return yesno(decider_questions.QUESTION_IS_ACTION_RUNNING_AWAY, text, default=NO)
else:
return NO
def special_case_is_magic(text):
is_magic = False
for keyword in ["magic", "spell", "fly", "invisib", "levitat", "shapeshift", "morph", "shrink", "transform", "teleport", "dragon", "genie", "fairy", "demon", "devil", "angel", "griffin", "wand"]:
if keyword in text.lower():
is_magic = True
break
if is_magic:
return YES
else:
return yesno(decider_questions.QUESTION_IS_ACTION_MAGIC, text, default=NO)
|