File size: 837 Bytes
b0e72b5
 
 
 
 
 
 
 
a659a92
b0e72b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai

YES = True
NO = False


def yesno(question, text, default):
    prompt = text + "\n\n" + question

    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"]

    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