Skip to content

Commit

Permalink
Show GenAI signal analysis errors in Slack message. (#5287)
Browse files Browse the repository at this point in the history
* Show GenAI signal analysis errors in Slack modal.

* Retain warning logs.

* Update src/dispatch/plugins/dispatch_slack/case/messages.py

Co-authored-by: Marc Vilanova <[email protected]>

* Update function name.

---------

Co-authored-by: Marc Vilanova <[email protected]>
  • Loading branch information
metroid-samus and mvilanova authored Oct 3, 2024
1 parent 181f9ab commit efe7ac8
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/dispatch/plugins/dispatch_slack/case/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,16 @@ def create_action_buttons_message(
return Message(blocks=signal_metadata_blocks).build()["blocks"]


def create_genai_signal_message_metadata_blocks(
signal_metadata_blocks: list[Block], message: str
) -> list[Block]:
signal_metadata_blocks.append(
Section(text=f":magic_wand: *GenAI Alert Analysis*\n\n{message}"),
)
signal_metadata_blocks.append(Divider())
return Message(blocks=signal_metadata_blocks).build()["blocks"]


def create_genai_signal_analysis_message(
case: Case,
channel_id: str,
Expand Down Expand Up @@ -316,8 +326,9 @@ def create_genai_signal_analysis_message(
).first()

if not first_instance_id or not first_instance_signal:
log.warning("Unable to generate GenAI signal analysis. No signal instances found.")
return signal_metadata_blocks
message = "Unable to generate GenAI signal analysis. No signal instances found."
log.warning(message)
return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message)

# Fetch related cases
related_cases = []
Expand Down Expand Up @@ -370,16 +381,16 @@ def create_genai_signal_analysis_message(
)

if not genai_plugin:
log.warning(
message = (
"Unable to generate GenAI signal analysis. No artificial-intelligence plugin enabled."
)
return signal_metadata_blocks
log.warning(message)
return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message)

if not signal_instance.signal.genai_prompt:
log.warning(
f"Unable to generate GenAI signal analysis. No GenAI prompt defined for {signal_instance.signal.name}"
)
return signal_metadata_blocks
message = f"Unable to generate GenAI signal analysis. No GenAI prompt defined for {signal_instance.signal.name}"
log.warning(message)
return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message)

response = genai_plugin.instance.chat_completion(
prompt=f"""
Expand All @@ -403,11 +414,11 @@ def create_genai_signal_analysis_message(
)
message = response["choices"][0]["message"]["content"]

signal_metadata_blocks.append(
Section(text=f":magic_wand: *GenAI Alert Analysis*\n\n{message}"),
)
signal_metadata_blocks.append(Divider())
return Message(blocks=signal_metadata_blocks).build()["blocks"]
if not message:
message = "Unable to generate GenAI signal analysis. We received an empty response from the artificial-intelligence plugin."
log.warning(message)

return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message)


def create_signal_engagement_message(
Expand Down

0 comments on commit efe7ac8

Please sign in to comment.