|
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()) |