Skip to content

Commit

Permalink
Fix Slack bot
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Co <alex.tuan@mindvalley.com>
  • Loading branch information
onimsha committed Nov 29, 2024
1 parent 971e417 commit e5ca503
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
42 changes: 19 additions & 23 deletions backend/danswer/danswerbot/slack/handlers/handle_message.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import datetime

from danswer.configs.danswerbot_configs import (
DANSWER_BOT_FEEDBACK_REMINDER,
DANSWER_REACT_EMOJI,
)
from danswer.configs.danswerbot_configs import DANSWER_BOT_FEEDBACK_REMINDER
from danswer.configs.danswerbot_configs import DANSWER_REACT_EMOJI
from danswer.danswerbot.slack.blocks import get_feedback_reminder_blocks
from danswer.danswerbot.slack.handlers.handle_regular_answer import (
handle_regular_answer,
Expand All @@ -12,13 +10,11 @@
handle_standard_answers,
)
from danswer.danswerbot.slack.models import SlackMessageInfo
from danswer.danswerbot.slack.utils import (
fetch_slack_user_ids_from_emails,
fetch_user_ids_from_groups,
respond_in_thread,
slack_usage_report,
update_emote_react,
)
from danswer.danswerbot.slack.utils import fetch_slack_user_ids_from_emails
from danswer.danswerbot.slack.utils import fetch_user_ids_from_groups
from danswer.danswerbot.slack.utils import respond_in_thread
from danswer.danswerbot.slack.utils import slack_usage_report
from danswer.danswerbot.slack.utils import update_emote_react
from danswer.db.engine import get_session_with_tenant
from danswer.db.models import SlackChannelConfig
from danswer.db.users import add_slack_user_if_not_exists
Expand Down Expand Up @@ -218,18 +214,18 @@ def handle_message(
if message_info.email:
add_slack_user_if_not_exists(db_session, message_info.email)

# first check if we need to respond with a standard answer
used_standard_answer = handle_standard_answers(
message_info=message_info,
receiver_ids=send_to,
slack_channel_config=slack_channel_config,
prompt=prompt,
logger=logger,
client=client,
db_session=db_session,
)
if used_standard_answer:
return False
#first check if we need to respond with a standard answer
# used_standard_answer = handle_standard_answers(
# message_info=message_info,
# receiver_ids=send_to,
# slack_channel_config=slack_channel_config,
# prompt=prompt,
# logger=logger,
# client=client,
# db_session=db_session,
# )
# if used_standard_answer:
# return False

# if no standard answer applies, try a regular answer
issue_with_regular_answer = handle_regular_answer(
Expand Down
2 changes: 1 addition & 1 deletion backend/danswer/llm/answering/prompts/citations_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def build_citations_system_message(
prompt_str=system_prompt, user_email=user_email
)

logger.info(f"Built system message: {system_prompt}")
logger.debug(f"Built system message: {system_prompt}")

return SystemMessage(content=system_prompt)

Expand Down
20 changes: 10 additions & 10 deletions backend/danswer/prompts/prompt_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@

import redis
from danswer.chat.models import LlmDoc
from danswer.configs.app_configs import AIRTABLE_API_TOKEN
from danswer.configs.app_configs import AIRTABLE_EMPLOYEE_BASE_ID
from danswer.configs.app_configs import AIRTABLE_EMPLOYEE_TABLE_NAME_OR_ID
from danswer.configs.app_configs import REDIS_DB_NUMBER
from danswer.configs.app_configs import REDIS_HOST
from danswer.configs.app_configs import REDIS_PORT
from danswer.configs.app_configs import (
AIRTABLE_API_TOKEN,
AIRTABLE_EMPLOYEE_BASE_ID,
AIRTABLE_EMPLOYEE_TABLE_NAME_OR_ID,
REDIS_DB_NUMBER,
REDIS_HOST,
REDIS_PORT,
)
from danswer.configs.chat_configs import LANGUAGE_HINT
from danswer.configs.constants import DocumentSource
from danswer.context.search.models import InferenceChunk
from danswer.db.models import Prompt
from danswer.llm.answering.models import PromptConfig
from danswer.prompts.chat_prompts import ADDITIONAL_INFO
from danswer.prompts.chat_prompts import CITATION_REMINDER
from danswer.prompts.chat_prompts import ADDITIONAL_INFO, CITATION_REMINDER
from danswer.prompts.constants import CODE_BLOCK_PAT
from danswer.utils.logger import setup_logger
from langchain_core.messages import BaseMessage
from pyairtable import Api as AirtableApi


logger = setup_logger()

logger = setup_logger()
Expand Down Expand Up @@ -74,7 +74,7 @@ def add_employee_context_to_prompt(prompt_str: str, user_email: str) -> str:
# Check Redis for cached employee context
cached_context = redis_client.get(user_email)
if cached_context:
logger.info("Employee context retrieved from Redis.")
logger.info(f"Employee context retrieved from Redis for email: {user_email}")
return prompt_str.replace(
DANSWER_EMPLOYEE_REPLACEMENT, cached_context.decode("utf-8")
)
Expand Down
3 changes: 3 additions & 0 deletions backend/danswer/seeding/prompts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ prompts:
You give concise responses to very simple questions, but provide more thorough responses to
more complex and open-ended questions.
Below is my employee information in Mindvalley:
DANSWER_EMPLOYEE_REPLACEMENT
You are happy to help with writing, analysis, question answering, math, coding and all sorts
of other tasks. You use markdown where reasonable and also for coding.
Expand Down

0 comments on commit e5ca503

Please sign in to comment.