Skip to content

Commit

Permalink
openai.error.RateLimitError
Browse files Browse the repository at this point in the history
  • Loading branch information
gargmegham committed May 13, 2023
1 parent 97b13a2 commit ee5c7e0
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions bot/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import medicalgpt
from mysql import MySQL
from openai.error import RateLimitError
from telegram import Message
from telegram.ext import filters

Expand Down Expand Up @@ -29,19 +30,22 @@ def get_messages_that_indicate_a_certian_medical_condition(

class CustomFilter(filters.MessageFilter):
def filter(self, message: Message) -> bool:
diagnosed_with = mysql_db.get_attribute(
message.from_user.id, "diagnosed_with"
)
if diagnosed_with and len(diagnosed_with):
return False
result = medicalgpt.Filter().medical_condition_message_filter(
message, condition
)
if result:
mysql_db.set_attribute(
message.from_user.id, "diagnosed_with", f"{condition},{id}"
try:
diagnosed_with = mysql_db.get_attribute(
message.from_user.id, "diagnosed_with"
)
if diagnosed_with and len(diagnosed_with):
return False
result = medicalgpt.Filter().medical_condition_message_filter(
message, condition
)
return result
if result:
mysql_db.set_attribute(
message.from_user.id, "diagnosed_with", f"{condition},{id}"
)
return result
except RateLimitError:
return False

return CustomFilter()

Expand Down

0 comments on commit ee5c7e0

Please sign in to comment.