From a238ece8d9324d5e09068cbd67c2ab556b516ac2 Mon Sep 17 00:00:00 2001 From: Avery Lee Date: Thu, 3 Oct 2024 13:44:26 -0700 Subject: [PATCH 1/4] Show GenAI signal analysis errors in Slack modal. --- .../plugins/dispatch_slack/case/messages.py | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/dispatch/plugins/dispatch_slack/case/messages.py b/src/dispatch/plugins/dispatch_slack/case/messages.py index f44643c2544f..074bf7bf21d4 100644 --- a/src/dispatch/plugins/dispatch_slack/case/messages.py +++ b/src/dispatch/plugins/dispatch_slack/case/messages.py @@ -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]: + 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, @@ -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.") - 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 = [] @@ -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""" @@ -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( From 81bba578ab51ead6a96f3c7bfc3e450b43ecd7f2 Mon Sep 17 00:00:00 2001 From: Avery Lee Date: Thu, 3 Oct 2024 13:52:15 -0700 Subject: [PATCH 2/4] Retain warning logs. --- src/dispatch/plugins/dispatch_slack/case/messages.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/dispatch/plugins/dispatch_slack/case/messages.py b/src/dispatch/plugins/dispatch_slack/case/messages.py index 074bf7bf21d4..8a138d5c1478 100644 --- a/src/dispatch/plugins/dispatch_slack/case/messages.py +++ b/src/dispatch/plugins/dispatch_slack/case/messages.py @@ -325,6 +325,7 @@ def create_genai_signal_analysis_message( if not first_instance_id or not first_instance_signal: message = "Unable to generate GenAI signal analysis. No signal instances found." + log.warning(message) return create_signal_metadata_blocks(signal_metadata_blocks, message) # Fetch related cases @@ -381,10 +382,12 @@ def create_genai_signal_analysis_message( message = ( "Unable to generate GenAI signal analysis. No artificial-intelligence plugin enabled." ) + log.warning(message) return create_signal_metadata_blocks(signal_metadata_blocks, message) if not signal_instance.signal.genai_prompt: message = f"Unable to generate GenAI signal analysis. No GenAI prompt defined for {signal_instance.signal.name}" + log.warning(message) return create_signal_metadata_blocks(signal_metadata_blocks, message) response = genai_plugin.instance.chat_completion( @@ -411,6 +414,7 @@ def create_genai_signal_analysis_message( 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_signal_metadata_blocks(signal_metadata_blocks, message) From 023e6f507addbb24f939913340e7f57d0810401a Mon Sep 17 00:00:00 2001 From: Avery Date: Thu, 3 Oct 2024 13:52:41 -0700 Subject: [PATCH 3/4] Update src/dispatch/plugins/dispatch_slack/case/messages.py Co-authored-by: Marc Vilanova <39573146+mvilanova@users.noreply.github.com> --- src/dispatch/plugins/dispatch_slack/case/messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatch/plugins/dispatch_slack/case/messages.py b/src/dispatch/plugins/dispatch_slack/case/messages.py index 8a138d5c1478..d604fd3720a0 100644 --- a/src/dispatch/plugins/dispatch_slack/case/messages.py +++ b/src/dispatch/plugins/dispatch_slack/case/messages.py @@ -287,7 +287,7 @@ 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]: +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}"), ) From 6c134a9e699bdcde06192f934dd90d874f354354 Mon Sep 17 00:00:00 2001 From: Avery Lee Date: Thu, 3 Oct 2024 13:54:21 -0700 Subject: [PATCH 4/4] Update function name. --- src/dispatch/plugins/dispatch_slack/case/messages.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/dispatch/plugins/dispatch_slack/case/messages.py b/src/dispatch/plugins/dispatch_slack/case/messages.py index d604fd3720a0..aedf77be8f3c 100644 --- a/src/dispatch/plugins/dispatch_slack/case/messages.py +++ b/src/dispatch/plugins/dispatch_slack/case/messages.py @@ -287,7 +287,9 @@ 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]: +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}"), ) @@ -326,7 +328,7 @@ def create_genai_signal_analysis_message( if not first_instance_id or not first_instance_signal: message = "Unable to generate GenAI signal analysis. No signal instances found." log.warning(message) - return create_signal_metadata_blocks(signal_metadata_blocks, message) + return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message) # Fetch related cases related_cases = [] @@ -383,12 +385,12 @@ def create_genai_signal_analysis_message( "Unable to generate GenAI signal analysis. No artificial-intelligence plugin enabled." ) log.warning(message) - return create_signal_metadata_blocks(signal_metadata_blocks, message) + return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message) if not signal_instance.signal.genai_prompt: message = f"Unable to generate GenAI signal analysis. No GenAI prompt defined for {signal_instance.signal.name}" log.warning(message) - return create_signal_metadata_blocks(signal_metadata_blocks, message) + return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message) response = genai_plugin.instance.chat_completion( prompt=f""" @@ -416,7 +418,7 @@ def create_genai_signal_analysis_message( message = "Unable to generate GenAI signal analysis. We received an empty response from the artificial-intelligence plugin." log.warning(message) - return create_signal_metadata_blocks(signal_metadata_blocks, message) + return create_genai_signal_message_metadata_blocks(signal_metadata_blocks, message) def create_signal_engagement_message(