File size: 752 Bytes
1ef8a31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import openai

openai.api_key = os.environ.get("openai_api_key")


_tweet = "I'm a pretty average middle aged guy, got a solid job and had a good family but things got messy and took " \
         "a turn for the worst. Everyone says you need to hit rock bottom to go back up so here I am!"


def prompt(tweet, roast=True):
    roast_or_toast = "snarky joke" if roast else "encouragement"
    return f"A user tweeted this tweet:\n\n{tweet}\\n\nThe following {roast_or_toast} was given as an answer:"


response = openai.Completion.create(
    engine="text-davinci-002",
    prompt=prompt(_tweet, roast=False),
    temperature=0.7,
    max_tokens=60,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
)

print(response.choices[0].text.strip())