Slack Rate Limit Options (#952)

This commit is contained in:
Yuhong Sun
2024-01-15 21:47:24 -08:00
committed by GitHub
parent 53add2c801
commit 44905d36e5
3 changed files with 14 additions and 5 deletions

View File

@@ -51,7 +51,7 @@ ENABLE_DANSWERBOT_REFLEXION = (
# Currently not support chain of thought, probably will add back later # Currently not support chain of thought, probably will add back later
DANSWER_BOT_DISABLE_COT = True DANSWER_BOT_DISABLE_COT = True
# Maximum Questions Per Minute # Maximum Questions Per Minute, Default Uncapped
DANSWER_BOT_MAX_QPM = int(os.environ.get("DANSWER_BOT_MAX_QPM", "100")) DANSWER_BOT_MAX_QPM = int(os.environ.get("DANSWER_BOT_MAX_QPM") or 0) or None
# Maximum time to wait when a question is queued # Maximum time to wait when a question is queued
DANSWER_BOT_MAX_WAIT_TIME = int(os.environ.get("DANSWER_BOT_MAX_WAIT_TIME", "180")) DANSWER_BOT_MAX_WAIT_TIME = int(os.environ.get("DANSWER_BOT_MAX_WAIT_TIME") or 180)

View File

@@ -355,7 +355,7 @@ def read_slack_thread(
class SlackRateLimiter: class SlackRateLimiter:
def __init__(self) -> None: def __init__(self) -> None:
self.max_qpm = DANSWER_BOT_MAX_QPM self.max_qpm: int | None = DANSWER_BOT_MAX_QPM
self.max_wait_time = DANSWER_BOT_MAX_WAIT_TIME self.max_wait_time = DANSWER_BOT_MAX_WAIT_TIME
self.active_question = 0 self.active_question = 0
self.last_reset_time = time.time() self.last_reset_time = time.time()
@@ -374,11 +374,15 @@ class SlackRateLimiter:
client=client, client=client,
channel=channel, channel=channel,
receiver_ids=None, receiver_ids=None,
text=f"Your question has been queued. You are in position {position}... please wait a moment :loading:", text=f"Your question has been queued. You are in position {position}.\n"
f"Please wait a moment :hourglass_flowing_sand:",
thread_ts=thread_ts, thread_ts=thread_ts,
) )
def is_available(self) -> bool: def is_available(self) -> bool:
if self.max_qpm is None:
return True
self.refill() self.refill()
return self.active_question < self.max_qpm return self.active_question < self.max_qpm
@@ -393,6 +397,9 @@ class SlackRateLimiter:
return func_randid, position return func_randid, position
def waiter(self, func_randid: int) -> None: def waiter(self, func_randid: int) -> None:
if self.max_qpm is None:
return
wait_time = 0 wait_time = 0
while ( while (
self.active_question >= self.max_qpm self.active_question >= self.max_qpm

View File

@@ -139,6 +139,8 @@ services:
- DANSWER_BOT_RESPOND_EVERY_CHANNEL=${DANSWER_BOT_RESPOND_EVERY_CHANNEL:-} - DANSWER_BOT_RESPOND_EVERY_CHANNEL=${DANSWER_BOT_RESPOND_EVERY_CHANNEL:-}
- DANSWER_BOT_DISABLE_COT=${DANSWER_BOT_DISABLE_COT:-} # Currently unused - DANSWER_BOT_DISABLE_COT=${DANSWER_BOT_DISABLE_COT:-} # Currently unused
- NOTIFY_SLACKBOT_NO_ANSWER=${NOTIFY_SLACKBOT_NO_ANSWER:-} - NOTIFY_SLACKBOT_NO_ANSWER=${NOTIFY_SLACKBOT_NO_ANSWER:-}
- DANSWER_BOT_MAX_QPM=${DANSWER_BOT_MAX_QPM:-}
- DANSWER_BOT_MAX_WAIT_TIME=${DANSWER_BOT_MAX_WAIT_TIME:-}
# Logging # Logging
# Leave this on pretty please? Nothing sensitive is collected! # Leave this on pretty please? Nothing sensitive is collected!
# https://docs.danswer.dev/more/telemetry # https://docs.danswer.dev/more/telemetry