mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2026-01-03 11:04:51 +00:00
Update chatbot_ai.py
This commit is contained in:
parent
a08b43bbb8
commit
3e5fc4ceba
1 changed files with 1 additions and 3 deletions
|
|
@ -31,14 +31,12 @@ async def chatbot(c, m):
|
||||||
msg = await kirimPesan(m, "Wait a moment looking for your answer..")
|
msg = await kirimPesan(m, "Wait a moment looking for your answer..")
|
||||||
try:
|
try:
|
||||||
response = (await http.post("https://api.openai.com/v1/chat/completions", headers=headers, json=json_data)).json()
|
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"])
|
return await editPesan(msg, err["message"])
|
||||||
answer = response["choices"][0]["message"]["content"]
|
answer = response["choices"][0]["message"]["content"]
|
||||||
await editPesan(msg, answer)
|
await editPesan(msg, answer)
|
||||||
except MessageTooLong:
|
except MessageTooLong:
|
||||||
answerlink = await post_to_telegraph(False, "MissKaty ChatBot ", answer)
|
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)
|
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:
|
except Exception as err:
|
||||||
await editPesan(msg, f"Oppss. ERROR: {str(err)}")
|
await editPesan(msg, f"Oppss. ERROR: {str(err)}")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue