Sync with latest openai lib

Signed-off-by: Yasir Aris M <git@yasirdev.my.id>
This commit is contained in:
Yasir Aris M 2023-11-17 16:02:58 +07:00
parent f9c2e724c1
commit c4421f45f5
4 changed files with 15 additions and 15 deletions

View file

@ -42,7 +42,7 @@ MOD_NOLOAD = ["subscene_dl"]
HELPABLE = {} HELPABLE = {}
cleanmode = {} cleanmode = {}
botStartTime = time.time() botStartTime = time.time()
misskaty_version = "v2.12.1 - Stable" misskaty_version = "v2.12.2 - Stable"
uvloop.install() uvloop.install()
faulthandler_enable() faulthandler_enable()

View file

@ -844,7 +844,7 @@ NUM = 4
@app.on_message(filters.group & filters.command('mentionall', COMMAND_HANDLER)) @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 NUM = 4
user = await msg.chat.get_member(msg.from_user.id) user = await msg.chat.get_member(msg.from_user.id)
if user.status in (enums.ChatMemberStatus.OWNER, enums.ChatMemberStatus.ADMINISTRATOR): if user.status in (enums.ChatMemberStatus.OWNER, enums.ChatMemberStatus.ADMINISTRATOR):

View file

@ -6,8 +6,7 @@ import asyncio
import html import html
import random import random
import openai from openai import AsyncOpenAI, APIConnectionError, RateLimitError, APIStatusError
from aiohttp import ClientSession
from pyrogram import filters from pyrogram import filters
from pyrogram.errors import MessageTooLong from pyrogram.errors import MessageTooLong
from pyrogram.types import Message from pyrogram.types import Message
@ -17,8 +16,6 @@ from misskaty.core import pyro_cooldown
from misskaty.helper import check_time_gap, fetch, post_to_telegraph, use_chat_lang 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 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 # 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)) @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) is_in_gap, _ = await check_time_gap(uid)
if is_in_gap and (uid not in SUDO): if is_in_gap and (uid not in SUDO):
return await ctx.reply_msg(strings("dont_spam"), del_in=5) return await ctx.reply_msg(strings("dont_spam"), del_in=5)
openai.aiosession.set(ClientSession()) ai = AsyncOpenAI(api_key=OPENAI_API)
pertanyaan = ctx.input pertanyaan = ctx.input
msg = await ctx.reply_msg(strings("find_answers_str"), quote=True) msg = await ctx.reply_msg(strings("find_answers_str"), quote=True)
num = 0 num = 0
answer = "" answer = ""
try: try:
response = await openai.ChatCompletion.acreate( response = await ai.chat.completions.create(
model="gpt-3.5-turbo-0613", model="gpt-3.5-turbo",
messages=[{"role": "user", "content": pertanyaan}], messages=[{"role": "user", "content": pertanyaan}],
temperature=0.7, temperature=0.7,
stream=True, stream=True,
@ -88,6 +85,9 @@ async def openai_chatbot(_, ctx: Message, strings):
strings("answers_too_long").format(answerlink=answerlink), strings("answers_too_long").format(answerlink=answerlink),
disable_web_page_preview=True, disable_web_page_preview=True,
) )
except Exception as err: except APIConnectionError as e:
await msg.edit_msg(f"ERROR: {str(err)}") await msg.edit_msg(f"The server could not be reached because {e.__cause__}")
await openai.aiosession.get().close() 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}")

View file

@ -10,7 +10,7 @@ aiohttp
chevron chevron
gTTS gTTS
regex regex
apscheduler apscheduler==3.10.4
pytz pytz
pykeyboard pykeyboard
pySmartDL pySmartDL
@ -27,7 +27,7 @@ telethon
pyrate_limiter pyrate_limiter
cachetools cachetools
cloudscraper cloudscraper
openai openai==1.3.2
GitPython GitPython
aiofiles aiofiles
uvloop uvloop==0.19.0