From 1c3d0a1f3df735a4f6e243c443fe503f97ed9cac Mon Sep 17 00:00:00 2001 From: Weves Date: Tue, 29 Aug 2023 14:23:49 -0700 Subject: [PATCH] Add environment variable which disables answering when an answer is not found --- backend/danswer/configs/app_configs.py | 3 +++ backend/danswer/listeners/slack_listener.py | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/backend/danswer/configs/app_configs.py b/backend/danswer/configs/app_configs.py index 96ea079fe..31c37c75b 100644 --- a/backend/danswer/configs/app_configs.py +++ b/backend/danswer/configs/app_configs.py @@ -196,3 +196,6 @@ DANSWER_BOT_DISPLAY_ERROR_MSGS = os.environ.get( "false", "", ] +DANSWER_BOT_DISABLE_DOCS_ONLY_ANSWER = os.environ.get( + "DANSWER_BOT_DISABLE_DOCS_ONLY_ANSWER", "" +).lower() not in ["false", ""] diff --git a/backend/danswer/listeners/slack_listener.py b/backend/danswer/listeners/slack_listener.py index f9ed5e21e..0e5ab0a67 100644 --- a/backend/danswer/listeners/slack_listener.py +++ b/backend/danswer/listeners/slack_listener.py @@ -12,6 +12,7 @@ from slack_sdk.socket_mode.response import SocketModeResponse from sqlalchemy.orm import Session from danswer.configs.app_configs import DANSWER_BOT_ANSWER_GENERATION_TIMEOUT +from danswer.configs.app_configs import DANSWER_BOT_DISABLE_DOCS_ONLY_ANSWER from danswer.configs.app_configs import DANSWER_BOT_DISPLAY_ERROR_MSGS from danswer.configs.app_configs import DANSWER_BOT_NUM_DOCS_TO_DISPLAY from danswer.configs.app_configs import DANSWER_BOT_NUM_RETRIES @@ -274,6 +275,13 @@ def process_slack_event(client: SocketModeClient, req: SocketModeRequest) -> Non top_documents_str = _process_documents(answer.top_ranked_docs, doc_identifiers) if not answer.answer: + if DANSWER_BOT_DISABLE_DOCS_ONLY_ANSWER: + logger.info( + "Unable to find answer - not responding since the " + "`DANSWER_BOT_DISABLE_DOCS_ONLY_ANSWER` env variable is set" + ) + return + text = f"Sorry, I was unable to find an answer, but I did find some potentially relevant docs 🤓\n\n{top_documents_str}" else: top_documents_str_with_header = (