From 7a02fd7ad75a4febb23cb6208698b458296e6585 Mon Sep 17 00:00:00 2001 From: Yuhong Sun Date: Sat, 11 May 2024 15:58:33 -0700 Subject: [PATCH] Touchups from Contributor PRs (#1447) --- .vscode/launch.template.jsonc | 8 ++--- backend/danswer/danswerbot/slack/blocks.py | 32 ++++++++++++------- .../slack/handlers/handle_message.py | 5 +-- backend/danswer/danswerbot/slack/listener.py | 7 +++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.template.jsonc b/.vscode/launch.template.jsonc index 6e86a7cef..552516570 100644 --- a/.vscode/launch.template.jsonc +++ b/.vscode/launch.template.jsonc @@ -32,7 +32,7 @@ "AUTH_TYPE": "disabled", "LOG_ALL_MODEL_INTERACTIONS": "True", "LOG_LEVEL": "DEBUG", - "PYTHONUNBUFFERED": "1", + "PYTHONUNBUFFERED": "1" }, "args": [ "model_server.main:app", @@ -51,7 +51,7 @@ "AUTH_TYPE": "disabled", "LOG_ALL_MODEL_INTERACTIONS": "True", "LOG_LEVEL": "DEBUG", - "PYTHONUNBUFFERED": "1", + "PYTHONUNBUFFERED": "1" }, "args": [ "danswer.main:app", @@ -92,10 +92,10 @@ // For the listner to access the Slack API, // DANSWER_BOT_SLACK_APP_TOKEN & DANSWER_BOT_SLACK_BOT_TOKEN need to be set in .env file located in the root of the project { - "name": "Slack Bot Listener", + "name": "Slack Bot", "type": "python", "request": "launch", - "program": "danswer/listeners/slack_listener.py", + "program": "danswer/danswerbot/slack/listener.py", "cwd": "${workspaceFolder}/backend", "envFile": "${workspaceFolder}/.env", "env": { diff --git a/backend/danswer/danswerbot/slack/blocks.py b/backend/danswer/danswerbot/slack/blocks.py index dd50cd490..a881819c5 100644 --- a/backend/danswer/danswerbot/slack/blocks.py +++ b/backend/danswer/danswerbot/slack/blocks.py @@ -38,14 +38,18 @@ from danswer.utils.text_processing import replace_whitespaces_w_space _MAX_BLURB_LEN = 45 -def get_feedback_reminder_blocks(thread_link: str) -> Block: - return SectionBlock( - text=( - f"Eh! You forget to give feedback on <{thread_link}|this answer>. " - "It's essential to help us to improve the quality of the answers. " - "Please rate it by clicking the `Helpful` or `Not helpful` button. Thanks!" - ) +def get_feedback_reminder_blocks(thread_link: str, include_followup: bool) -> Block: + text = ( + f"Please provide feedback on <{thread_link}|this answer>. " + "This is essential to help us to improve the quality of the answers. " + "Please rate it by clicking the `Helpful` or `Not helpful` button. " ) + if include_followup: + text += "\n\nIf you need more help, click the `I need more help from a human!` button. " + + text += "\n\nThanks!" + + return SectionBlock(text=text) def _process_citations_for_slack(text: str) -> str: @@ -82,7 +86,7 @@ def _split_text(text: str, limit: int = 3000) -> list[str]: break # Find the nearest space before the limit to avoid splitting a word - split_at = text.rfind(' ', 0, limit) + split_at = text.rfind(" ", 0, limit) if split_at == -1: # No spaces found, force split split_at = limit @@ -385,14 +389,18 @@ def build_qa_response_blocks( filter_block = SectionBlock(text=f"_{filter_text}_") if not answer: - answer_blocks = [SectionBlock( - text="Sorry, I was unable to find an answer, but I did find some potentially relevant docs 🤓" - )] + answer_blocks = [ + SectionBlock( + text="Sorry, I was unable to find an answer, but I did find some potentially relevant docs 🤓" + ) + ] else: answer_processed = decode_escapes(remove_slack_text_interactions(answer)) if process_message_for_citations: answer_processed = _process_citations_for_slack(answer_processed) - answer_blocks = [SectionBlock(text=text) for text in _split_text(answer_processed)] + answer_blocks = [ + SectionBlock(text=text) for text in _split_text(answer_processed) + ] if quotes: quotes_blocks = build_quotes_block(quotes) diff --git a/backend/danswer/danswerbot/slack/handlers/handle_message.py b/backend/danswer/danswerbot/slack/handlers/handle_message.py index 14efe52a5..de9b48e3c 100644 --- a/backend/danswer/danswerbot/slack/handlers/handle_message.py +++ b/backend/danswer/danswerbot/slack/handlers/handle_message.py @@ -106,7 +106,7 @@ def send_msg_ack_to_user(details: SlackMessageInfo, client: WebClient) -> None: def schedule_feedback_reminder( - details: SlackMessageInfo, client: WebClient + details: SlackMessageInfo, include_followup: bool, client: WebClient ) -> str | None: logger = cast( logging.Logger, @@ -136,7 +136,8 @@ def schedule_feedback_reminder( post_at=int(future.timestamp()), blocks=[ get_feedback_reminder_blocks( - thread_link=permalink.data["permalink"] # type:ignore + thread_link=permalink.data["permalink"], # type:ignore + include_followup=include_followup, ) ], text="", diff --git a/backend/danswer/danswerbot/slack/listener.py b/backend/danswer/danswerbot/slack/listener.py index 819b37dd6..27cb6b82c 100644 --- a/backend/danswer/danswerbot/slack/listener.py +++ b/backend/danswer/danswerbot/slack/listener.py @@ -292,8 +292,13 @@ def process_message( ): return + follow_up = bool( + slack_bot_config + and slack_bot_config.channel_config + and slack_bot_config.channel_config.get("follow_up_tags") is not None + ) feedback_reminder_id = schedule_feedback_reminder( - details=details, client=client.web_client + details=details, client=client.web_client, include_followup=follow_up ) failed = handle_message(