Skip to content

Commit

Permalink
Sync with latest openai lib
Browse files Browse the repository at this point in the history
Signed-off-by: Yasir Aris M <[email protected]>
  • Loading branch information
yasirarism committed Nov 17, 2023
1 parent f9c2e72 commit c4421f4
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion misskaty/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion misskaty/plugins/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
20 changes: 10 additions & 10 deletions misskaty/plugins/chatbot_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -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,
Expand All @@ -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}")
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ aiohttp
chevron
gTTS
regex
apscheduler
apscheduler==3.10.4
pytz
pykeyboard
pySmartDL
Expand All @@ -27,7 +27,7 @@ telethon
pyrate_limiter
cachetools
cloudscraper
openai
openai==1.3.2
GitPython
aiofiles
uvloop
uvloop==0.19.0

0 comments on commit c4421f4

Please sign in to comment.