@app.route(‘/message’, methods=[‘POST’])
def mess():
msg = request.json.get(‘msg’)
maxtoken = request.json.get(‘maxtoken’)
req = requests.post('https://api.openai.com/v1/completions',
json={"prompt": msg + " Humorous and professional reply in Chinese", "max_tokens": maxtoken, "model": "text-davinci-003", "temperature": 0.8},
headers={'content-type': 'application/json', 'Authorization': 'Bearer ' + openai_key})
if req.status_code == 200:
reqdic = json.loads(req.text)
res = {
"resmsg": reqdic,
"code": 200
}
Thanks