Skip to content

Commit

Permalink
fix bug in hooks.py
Browse files Browse the repository at this point in the history
don't sleep 1hour from the begining in on RateLimitError
  • Loading branch information
adbenitez committed Jul 23, 2023
1 parent a395ac8 commit 7cae6cf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions deltachat_chatbot/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ async def _filter_messages(event: AttrDict) -> None:
await quota_manager.increase_usage(msg.from_id, reply.usage.total_tokens)
text = reply.choices[0].message.content.strip()
await msg.chat.send_message(text=text, quoted_msg=msg.id)
fail_count = 5
fail_count = 2
await asyncio.sleep(1) # avoid rate limits
except openai.error.RateLimitError as ex:
logging.exception(ex)
await msg.chat.send_message(
text="⏰ I'm not available right now, try again later", quoted_msg=msg.id
)
fail_count = max(fail_count + 1, 60)
fail_count = min(fail_count + 1, 60)
quota_manager.set_rate_limit(60 * fail_count)


Expand Down

0 comments on commit 7cae6cf

Please sign in to comment.