Touchups from Contributor PRs (#1447)

This commit is contained in:
Yuhong Sun 2024-05-11 15:58:33 -07:00 committed by GitHub
parent 4e759717ab
commit 7a02fd7ad7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 19 deletions

View File

@ -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": {

View File

@ -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)

View File

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

View File

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