Update chatbot_ai.py

This commit is contained in:
yasirarism 2023-03-20 19:06:42 +07:00 committed by GitHub
parent a08b43bbb8
commit 3e5fc4ceba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -31,14 +31,12 @@ async def chatbot(c, m):
msg = await kirimPesan(m, "Wait a moment looking for your answer..")
try:
response = (await http.post("https://api.openai.com/v1/chat/completions", headers=headers, json=json_data)).json()
if err := response["error"]:
if err := response.get("error"):
return await editPesan(msg, err["message"])
answer = response["choices"][0]["message"]["content"]
await editPesan(msg, answer)
except MessageTooLong:
answerlink = await post_to_telegraph(False, "MissKaty ChatBot ", answer)
await editPesan(msg, f"Question for your answer has exceeded TG text limit, check this link to view.\n\n{answerlink}", disable_web_page_preview=True)
except (MessageNotModified, MessageIdInvalid):
pass
except Exception as err:
await editPesan(msg, f"Oppss. ERROR: {str(err)}")