Skip to content

Commit

Permalink
fixes based on CW discussion
Browse files Browse the repository at this point in the history
- Updated frontend descriptions
- removal of 'I need help'-type options
- proper handling of response group
- no response group + ephemeral
  • Loading branch information
joachim-danswer committed Mar 1, 2025
1 parent b03d26f commit ef3c8fc
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 57 deletions.
4 changes: 0 additions & 4 deletions backend/onyx/connectors/slack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ def make_slack_api_rate_limited(
def rate_limited_call(**kwargs: Any) -> SlackResponse:
last_exception = None

if "thread_ts" in kwargs:
if kwargs["thread_ts"] is None:
kwargs.pop("thread_ts", None)

for _ in range(max_retries):
try:
# Make the API call
Expand Down
32 changes: 16 additions & 16 deletions backend/onyx/onyxbot/slack/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,12 @@ def _build_qa_feedback_block(

def _build_ephemeral_publication_block(
channel_id: str,
original_question_ts: str | None = None,
chat_message_id: int | None = None,
message_info: SlackMessageInfo | None = None,
channel_conf: ChannelConfig | None = None,
chat_message_id: int,
message_info: SlackMessageInfo,
original_question_ts: str,
channel_conf: ChannelConfig,
feedback_reminder_id: str | None = None,
) -> Block:
if not chat_message_id:
raise ValueError("Chat message id is required to change the ephemeral message")

if message_info is None:
raise ValueError("Message info is required to change the ephemeral message")

if channel_conf is None:
raise ValueError("Channel config is required to change the ephemeral message")

# check whether the message is in a thread
if (
message_info is not None
Expand Down Expand Up @@ -616,19 +607,28 @@ def build_slack_response_blocks(
)

follow_up_block = []
if channel_conf and channel_conf.get("follow_up_tags") is not None:
if (
channel_conf
and channel_conf.get("follow_up_tags") is not None
and not channel_conf.get("is_ephemeral", False)
):
follow_up_block.append(
_build_follow_up_block(message_id=answer.chat_message_id)
)

publish_ephemeral_message_block = []

if offer_ephemeral_publication:
if (
offer_ephemeral_publication
and answer.chat_message_id is not None
and message_info.msg_to_respond is not None
and channel_conf is not None
):
publish_ephemeral_message_block.append(
_build_ephemeral_publication_block(
channel_id=message_info.channel_to_respond,
original_question_ts=message_info.msg_to_respond,
chat_message_id=answer.chat_message_id,
original_question_ts=message_info.msg_to_respond,
message_info=message_info,
channel_conf=channel_conf,
feedback_reminder_id=feedback_reminder_id,
Expand Down
17 changes: 12 additions & 5 deletions backend/onyx/onyxbot/slack/handlers/handle_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def handle_doc_feedback_button(
external_id = build_feedback_id(query_event_id, doc_id, doc_rank)

channel_id = req.payload["container"]["channel_id"]
thread_ts = req.payload["container"]["thread_ts"]
thread_ts = req.payload["container"].get("thread_ts", None)

data = View(
type="modal",
Expand All @@ -129,7 +129,7 @@ def handle_generate_answer_button(
channel_id = req.payload["channel"]["id"]
channel_name = req.payload["channel"]["name"]
message_ts = req.payload["message"]["ts"]
thread_ts = req.payload["container"]["thread_ts"]
thread_ts = req.payload["container"].get("thread_ts", None)
user_id = req.payload["user"]["id"]
expert_info = expert_info_from_slack_id(user_id, client.web_client, user_cache={})
email = expert_info.email if expert_info else None
Expand Down Expand Up @@ -374,13 +374,20 @@ def handle_slack_feedback(
) -> None:
message_id, doc_id, doc_rank = decompose_action_id(feedback_id)

# Get Onyx user from Slack ID
expert_info = expert_info_from_slack_id(
user_id_to_post_confirmation, client, user_cache={}
)
email = expert_info.email if expert_info else None

with get_session_with_tenant(tenant_id=tenant_id) as db_session:
onyx_user = get_user_by_email(email, db_session) if email else None
if feedback_type in [LIKE_BLOCK_ACTION_ID, DISLIKE_BLOCK_ACTION_ID]:
create_chat_message_feedback(
is_positive=feedback_type == LIKE_BLOCK_ACTION_ID,
feedback_text="",
chat_message_id=message_id,
user_id=None, # no "user" for Slack bot for now
user_id=onyx_user.id if onyx_user else None,
db_session=db_session,
)
remove_scheduled_feedback_reminder(
Expand Down Expand Up @@ -453,7 +460,7 @@ def handle_followup_button(
action_id = cast(str, action.get("block_id"))

channel_id = req.payload["container"]["channel_id"]
thread_ts = req.payload["container"]["thread_ts"]
thread_ts = req.payload["container"].get("thread_ts", None)

update_emote_react(
emoji=DANSWER_FOLLOWUP_EMOJI,
Expand Down Expand Up @@ -536,7 +543,7 @@ def handle_followup_resolved_button(
) -> None:
channel_id = req.payload["container"]["channel_id"]
message_ts = req.payload["container"]["message_ts"]
thread_ts = req.payload["container"]["thread_ts"]
thread_ts = req.payload["container"].get("thread_ts", None)

clicker_name = get_clicker_name(req, client)

Expand Down
3 changes: 2 additions & 1 deletion backend/onyx/onyxbot/slack/handlers/handle_regular_answer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,15 @@ def handle_regular_answer(

# Capture whether response mode for channel is ephemeral
send_as_ephemeral = slack_channel_config.channel_config.get("is_ephemeral", False)
public_only = slack_channel_config.persona is None

# If the channel mis configured to respond with an ephemeral message,
# or the message is a dm to the Onyx bot,we should use the proper user from the email
# Otherwise - if not ephemeral or DM to Onyx Bo- we MUST None as the user to restrict
# to public docs as other people in the channel can see the response.

user = None
if message_info.is_bot_dm or send_as_ephemeral:
if (message_info.is_bot_dm or send_as_ephemeral) and not public_only:
if message_info.email:
with get_session_with_tenant(tenant_id=tenant_id) as db_session:
user = get_user_by_email(message_info.email, db_session)
Expand Down
2 changes: 1 addition & 1 deletion backend/onyx/onyxbot/slack/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ def send_team_member_message(
+ "information to the team. They'll get back to you shortly!"
),
thread_ts=thread_ts,
receiver_ids=receiver_ids,
receiver_ids=None,
send_as_ephemeral=send_as_ephemeral,
)
4 changes: 1 addition & 3 deletions backend/onyx/onyxbot/slack/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,8 @@ def build_feedback_id(


def build_publish_ephemeral_message_id(
original_question_ts: str | None = None,
original_question_ts: str,
) -> str:
if original_question_ts is None:
raise ValueError("Original question timestamp is required")
return "publish_ephemeral_message__" + original_question_ts


Expand Down
9 changes: 9 additions & 0 deletions backend/onyx/server/manage/slack_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ def _form_channel_config(
"also respond to a predetermined set of users."
)

if (
slack_channel_config_creation_request.is_ephemeral
and slack_channel_config_creation_request.respond_member_group_list
):
raise ValueError(
"Cannot set OnyxBot to respond to users in a private (ephemeral) message "
"and also respond to a selected list of users."
)

channel_config: ChannelConfig = {
"channel_name": cleaned_channel_name,
}
Expand Down
44 changes: 19 additions & 25 deletions backend/scripts/document_seeding_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,33 +161,27 @@ class SeedPresaveDocument(BaseModel):
url="https://docs.onyx.app/more/use_cases/overview",
title=overview_title,
content=overview,
title_embedding=list(model.encode(f"search_document: {overview_title}")),
content_embedding=list(
model.encode(f"search_document: {overview_title}\n{overview}")
),
title_embedding=model.encode(f"search_document: {overview_title}"),
content_embedding=model.encode(f"search_document: {overview_title}\n{overview}"),
)

enterprise_search_doc = SeedPresaveDocument(
url="https://docs.onyx.app/more/use_cases/enterprise_search",
title=enterprise_search_title,
content=enterprise_search_1,
title_embedding=list(model.encode(f"search_document: {enterprise_search_title}")),
content_embedding=list(
model.encode(
f"search_document: {enterprise_search_title}\n{enterprise_search_1}"
)
title_embedding=model.encode(f"search_document: {enterprise_search_title}"),
content_embedding=model.encode(
f"search_document: {enterprise_search_title}\n{enterprise_search_1}"
),
)

enterprise_search_doc_2 = SeedPresaveDocument(
url="https://docs.onyx.app/more/use_cases/enterprise_search",
title=enterprise_search_title,
content=enterprise_search_2,
title_embedding=list(model.encode(f"search_document: {enterprise_search_title}")),
content_embedding=list(
model.encode(
f"search_document: {enterprise_search_title}\n{enterprise_search_2}"
)
title_embedding=model.encode(f"search_document: {enterprise_search_title}"),
content_embedding=model.encode(
f"search_document: {enterprise_search_title}\n{enterprise_search_2}"
),
chunk_ind=1,
)
Expand All @@ -196,37 +190,37 @@ class SeedPresaveDocument(BaseModel):
url="https://docs.onyx.app/more/use_cases/ai_platform",
title=ai_platform_title,
content=ai_platform,
title_embedding=list(model.encode(f"search_document: {ai_platform_title}")),
content_embedding=list(
model.encode(f"search_document: {ai_platform_title}\n{ai_platform}")
title_embedding=model.encode(f"search_document: {ai_platform_title}"),
content_embedding=model.encode(
f"search_document: {ai_platform_title}\n{ai_platform}"
),
)

customer_support_doc = SeedPresaveDocument(
url="https://docs.onyx.app/more/use_cases/support",
title=customer_support_title,
content=customer_support,
title_embedding=list(model.encode(f"search_document: {customer_support_title}")),
content_embedding=list(
model.encode(f"search_document: {customer_support_title}\n{customer_support}")
title_embedding=model.encode(f"search_document: {customer_support_title}"),
content_embedding=model.encode(
f"search_document: {customer_support_title}\n{customer_support}"
),
)

sales_doc = SeedPresaveDocument(
url="https://docs.onyx.app/more/use_cases/sales",
title=sales_title,
content=sales,
title_embedding=list(model.encode(f"search_document: {sales_title}")),
content_embedding=list(model.encode(f"search_document: {sales_title}\n{sales}")),
title_embedding=model.encode(f"search_document: {sales_title}"),
content_embedding=model.encode(f"search_document: {sales_title}\n{sales}"),
)

operations_doc = SeedPresaveDocument(
url="https://docs.onyx.app/more/use_cases/operations",
title=operations_title,
content=operations,
title_embedding=list(model.encode(f"search_document: {operations_title}")),
content_embedding=list(
model.encode(f"search_document: {operations_title}\n{operations}")
title_embedding=model.encode(f"search_document: {operations_title}"),
content_embedding=model.encode(
f"search_document: {operations_title}\n{operations}"
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,10 @@ export function SlackChannelConfigFormFields({
/>
<CheckFormField
name="is_ephemeral"
label="Respond to user as ephemeral message"
tooltip="If set, OnyxBot will respond only to the user as an ephemeral message"
label="Respond to user in a private (ephemeral) message"
tooltip="If set, OnyxBot will respond only to the user in a private (ephemeral) message. If you also
chose 'Search' Assistant above, selecting this option will make documents that are private to the user
available for their queries."
/>

<TextArrayField
Expand Down

0 comments on commit ef3c8fc

Please sign in to comment.