File size: 874 Bytes
805c3e0 36ad45e 0f33e7d 1ef8a31 0f33e7d 1ef8a31 36ad45e 0f33e7d |
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 |
import os
import openai
from fastapi import FastAPI
openai.api_key = os.environ.get("openai_api_key")
app = FastAPI()
_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:"
@app.get("/")
def read_root():
response = openai.Completion.create(
engine="text-davinci-002",
prompt=prompt(_tweet, roast=True),
temperature=0.7,
max_tokens=60,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].text.strip() |