Skip to content

Instantly share code, notes, and snippets.

@urigoren
Created July 23, 2023 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urigoren/56c2193c5541f477e9912e2e19f7de0e to your computer and use it in GitHub Desktop.
Save urigoren/56c2193c5541f477e9912e2e19f7de0e to your computer and use it in GitHub Desktop.
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