diff --git a/misskaty/__init__.py b/misskaty/__init__.py index 35e6667563..d43acfddbd 100644 --- a/misskaty/__init__.py +++ b/misskaty/__init__.py @@ -42,7 +42,7 @@ HELPABLE = {} cleanmode = {} botStartTime = time.time() -misskaty_version = "v2.12.1 - Stable" +misskaty_version = "v2.12.2 - Stable" uvloop.install() faulthandler_enable() diff --git a/misskaty/plugins/admin.py b/misskaty/plugins/admin.py index bd052e5417..ed7132cb34 100644 --- a/misskaty/plugins/admin.py +++ b/misskaty/plugins/admin.py @@ -844,7 +844,7 @@ async def set_chat_photo(_, ctx: Message): @app.on_message(filters.group & filters.command('mentionall', COMMAND_HANDLER)) -async def mention(app: Client, msg: types.Message): +async def mentionall(app: Client, msg: types.Message): NUM = 4 user = await msg.chat.get_member(msg.from_user.id) if user.status in (enums.ChatMemberStatus.OWNER, enums.ChatMemberStatus.ADMINISTRATOR): diff --git a/misskaty/plugins/chatbot_ai.py b/misskaty/plugins/chatbot_ai.py index e657d06c2e..27ca4d9b31 100644 --- a/misskaty/plugins/chatbot_ai.py +++ b/misskaty/plugins/chatbot_ai.py @@ -6,8 +6,7 @@ import html import random -import openai -from aiohttp import ClientSession +from openai import AsyncOpenAI, APIConnectionError, RateLimitError, APIStatusError from pyrogram import filters from pyrogram.errors import MessageTooLong from pyrogram.types import Message @@ -17,8 +16,6 @@ from misskaty.helper import check_time_gap, fetch, post_to_telegraph, use_chat_lang from misskaty.vars import BARD_API, COMMAND_HANDLER, OPENAI_API, SUDO -openai.api_key = OPENAI_API - # This only for testing things, since maybe in future it will got blocked @app.on_message(filters.command("bard", COMMAND_HANDLER) & pyro_cooldown.wait(10)) @@ -58,14 +55,14 @@ async def openai_chatbot(_, ctx: Message, strings): is_in_gap, _ = await check_time_gap(uid) if is_in_gap and (uid not in SUDO): return await ctx.reply_msg(strings("dont_spam"), del_in=5) - openai.aiosession.set(ClientSession()) + ai = AsyncOpenAI(api_key=OPENAI_API) pertanyaan = ctx.input msg = await ctx.reply_msg(strings("find_answers_str"), quote=True) num = 0 answer = "" try: - response = await openai.ChatCompletion.acreate( - model="gpt-3.5-turbo-0613", + response = await ai.chat.completions.create( + model="gpt-3.5-turbo", messages=[{"role": "user", "content": pertanyaan}], temperature=0.7, stream=True, @@ -88,6 +85,9 @@ async def openai_chatbot(_, ctx: Message, strings): strings("answers_too_long").format(answerlink=answerlink), disable_web_page_preview=True, ) - except Exception as err: - await msg.edit_msg(f"ERROR: {str(err)}") - await openai.aiosession.get().close() + except APIConnectionError as e: + await msg.edit_msg(f"The server could not be reached because {e.__cause__}") + except RateLimitError as e: + await msg.edit_msg("A 429 status code was received; we should back off a bit.") + except APIStatusError as e: + await msg.edit_msg(f"Another {e.status_code} status code was received with response {e.response}") diff --git a/requirements.txt b/requirements.txt index 9675df97f1..589e59e8fc 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ aiohttp chevron gTTS regex -apscheduler +apscheduler==3.10.4 pytz pykeyboard pySmartDL @@ -27,7 +27,7 @@ telethon pyrate_limiter cachetools cloudscraper -openai +openai==1.3.2 GitPython aiofiles -uvloop \ No newline at end of file +uvloop==0.19.0 \ No newline at end of file