Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show GenAI signal analysis errors in Slack message. #5287

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 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,14 @@ def create_action_buttons_message(
return Message(blocks=signal_metadata_blocks).build()["blocks"]


def create_signal_metadata_blocks(signal_metadata_blocks: list[Block], message: str) -> list[Block]:
metroid-samus marked this conversation as resolved.
Show resolved Hide resolved
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 +324,8 @@ 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.")
metroid-samus marked this conversation as resolved.
Show resolved Hide resolved
return signal_metadata_blocks
message = "Unable to generate GenAI signal analysis. No signal instances found."
return create_signal_metadata_blocks(signal_metadata_blocks, message)

# Fetch related cases
related_cases = []
Expand Down Expand Up @@ -370,16 +378,14 @@ 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
return create_signal_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}"
return create_signal_metadata_blocks(signal_metadata_blocks, message)

response = genai_plugin.instance.chat_completion(
prompt=f"""
Expand All @@ -403,11 +409,10 @@ 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."

return create_signal_metadata_blocks(signal_metadata_blocks, message)


def create_signal_engagement_message(
Expand Down
Loading