Created
July 23, 2023 09:45
-
-
Save urigoren/56c2193c5541f477e9912e2e19f7de0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
from decouple import config | |
openai.api_key = config("OPENAI_KEY") | |
YES_TOKEN = frozenset([5297, 3763, 3363, 8505, 3363, 3763, 43335, 3763, 21560]) | |
NO_TOKEN = frozenset([2949, 645, 1400, 3919, 1400, 645, 15285, 645, 8005]) | |
def yes_or_no(txt: str)->bool: | |
response = openai.Completion.create( | |
model="text-davinci-003", | |
prompt=txt, | |
temperature=0, | |
logit_bias={t: 100 for t in YES_TOKEN|NO_TOKEN}, | |
max_tokens=1, | |
) | |
ret = response.choices[0].text.strip().lower()=="yes" | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment