Add environment variable which disables answering when an answer is not found

This commit is contained in:
Weves 2023-08-29 14:23:49 -07:00 committed by Chris Weaver
parent 3c5cdb07c1
commit 1c3d0a1f3d
2 changed files with 11 additions and 0 deletions

View File

@ -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", ""]

View File

@ -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 = (