From 0efa22450aea51ff59f6ea66cc6edce6f1dca500 Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Tue, 14 Jan 2025 14:11:47 -0500 Subject: [PATCH 1/6] [Obs AI Assistant] Fix editing prompt from contextual insights (#201642) --- .../public/components/insight/insight.tsx | 83 +++++++++++++++---- .../alert_details_contextual_insights.tsx | 6 +- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx index 680a92f559f0a..5be7a75449970 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx @@ -14,11 +14,13 @@ import { EuiText, EuiTextArea, EuiCallOut, + EuiLoadingSpinner, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { cloneDeep, isArray, isEmpty, last, once } from 'lodash'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import useObservable from 'react-use/lib/useObservable'; +import dedent from 'dedent'; import { ILicense } from '@kbn/licensing-plugin/public'; import { MessageRole, type Message } from '../../../common/types'; import { ObservabilityAIAssistantChatServiceContext } from '../../context/observability_ai_assistant_chat_service_context'; @@ -41,6 +43,10 @@ import { InsightBase } from './insight_base'; import { ActionsMenu } from './actions_menu'; import { ObservabilityAIAssistantTelemetryEventType } from '../../analytics/telemetry_event_type'; +// defined and used in x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx +const CONTEXT_INSTRUCTION = + 'The following contextual information is available to help you understand the alert'; + function getLastMessageOfType(messages: Message[], role: MessageRole) { return last(messages.filter((msg) => msg.message.role === role)); } @@ -288,16 +294,61 @@ export function Insight({ [service] ); + const getPromptToEdit = () => { + const clonedMessages = cloneDeep(messages.messages); + const lastUserPrompt = getLastMessageOfType(clonedMessages, MessageRole.User)?.message.content; + + if (!lastUserPrompt) { + return ''; + } + + try { + const { instructions = '' } = JSON.parse(lastUserPrompt); + + // instructions is a large multiline string with contextual information appended to it. + // We'll split at CONTEXT_INSTRUCTION so that we can extract the instructions the user needs to edit + const [beforeContextInstruction] = instructions.split(CONTEXT_INSTRUCTION); + return beforeContextInstruction.trim(); + } catch (e) { + return ''; + } + }; + const onEditPrompt = (newPrompt: string) => { const clonedMessages = cloneDeep(messages.messages); const userMessage = getLastMessageOfType(clonedMessages, MessageRole.User); if (!userMessage) return false; - userMessage.message.content = newPrompt; - setIsPromptUpdated(true); - setMessages({ messages: clonedMessages, status: FETCH_STATUS.SUCCESS }); - setEditingPrompt(false); - return true; + try { + const parsedContent = JSON.parse(userMessage.message.content || ''); + + if (!parsedContent.instructions) { + return false; + } + + const [_beforeContextInstruction, afterContextInstruction] = + parsedContent.instructions.split(CONTEXT_INSTRUCTION); + + // Rebuild instructions with the new prompt, preserving everything after the delimiter + const updatedInstructions = dedent( + `${newPrompt} + ${CONTEXT_INSTRUCTION} + ${afterContextInstruction}` + ); + + // Assign the updated instructions + parsedContent.instructions = updatedInstructions; + userMessage.message.content = JSON.stringify(parsedContent); + + setIsPromptUpdated(true); + setMessages({ messages: clonedMessages, status: FETCH_STATUS.SUCCESS }); + setEditingPrompt(false); + return true; + } catch (e) { + // eslint-disable-next-line no-console + console.error('Failed to edit prompt:', e); + return false; + } }; const handleCancel = () => { @@ -372,15 +423,19 @@ export function Insight({ ); } else if (isEditingPrompt) { - children = ( - - ); + const instructionToEdit = getPromptToEdit(); + + if (messages.status === FETCH_STATUS.SUCCESS && instructionToEdit) { + children = ( + + ); + } else { + children = ; + } } else if (!connectors.loading && !connectors.connectors?.length) { children = ( diff --git a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx index 17f7d335624d1..d63fd5d06eccd 100644 --- a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx +++ b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx @@ -13,6 +13,10 @@ import { type AlertDetailsContextualInsight } from '../../../server/services'; import { useKibana } from '../../utils/kibana_react'; import { AlertData } from '../../hooks/use_fetch_alert_detail'; +// used in x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx +const CONTEXT_INSTRUCTION = + 'The following contextual information is available to help you understand the alert'; + export function AlertDetailContextualInsights({ alert }: { alert: AlertData | null }) { const { services: { observabilityAIAssistant, http }, @@ -62,7 +66,7 @@ export function AlertDetailContextualInsights({ alert }: { alert: AlertData | nu instructions: dedent( `I'm an SRE. I am looking at an alert that was triggered. I want to understand why it was triggered, what it means, and what I should do next. - The following contextual information is available to help you understand the alert: + ${CONTEXT_INSTRUCTION}: ${obsAlertContext} The user already know the alert reason so do not repeat this: ${alert.formatted.reason} From 38b8748423f0fb5ebfa1bd7f21d21a6f61874d98 Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Wed, 15 Jan 2025 11:12:36 -0500 Subject: [PATCH 2/6] [Obs AI Assistant] Export context_instruction const from a common package (#206673) --- .../common/context_instruction.ts | 9 +++++++++ .../observability_ai_assistant/common/index.ts | 2 ++ .../observability_ai_assistant/kibana.jsonc | 2 +- .../public/components/insight/insight.tsx | 5 +---- .../plugins/observability/kibana.jsonc | 18 ++++++------------ .../alert_details_contextual_insights.tsx | 5 +---- 6 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/context_instruction.ts diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/context_instruction.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/context_instruction.ts new file mode 100644 index 0000000000000..adf836ddaa73e --- /dev/null +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/context_instruction.ts @@ -0,0 +1,9 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export const CONTEXT_INSTRUCTION = + 'The following contextual information is available to help you understand the alert'; diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts index 0157a6a2b0aae..e0dff6672b6d2 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts @@ -50,3 +50,5 @@ export { concatenateChatCompletionChunks } from './utils/concatenate_chat_comple export { ShortIdTable } from './utils/short_id_table'; export { KnowledgeBaseType } from './types'; + +export { CONTEXT_INSTRUCTION } from './context_instruction'; diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc index ed106c9b6a791..02fddc65aff83 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc @@ -21,6 +21,6 @@ "optionalPlugins": ["cloud", "serverless"], "requiredBundles": ["kibanaReact", "kibanaUtils"], "runtimePluginDependencies": ["ml"], - "extraPublicDirs": [] + "extraPublicDirs": ["common"] } } diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx index 5be7a75449970..1b8a41dae67b2 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx @@ -22,6 +22,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import useObservable from 'react-use/lib/useObservable'; import dedent from 'dedent'; import { ILicense } from '@kbn/licensing-plugin/public'; +import { CONTEXT_INSTRUCTION } from '../../../common/context_instruction'; import { MessageRole, type Message } from '../../../common/types'; import { ObservabilityAIAssistantChatServiceContext } from '../../context/observability_ai_assistant_chat_service_context'; import { useAbortableAsync } from '../../hooks/use_abortable_async'; @@ -43,10 +44,6 @@ import { InsightBase } from './insight_base'; import { ActionsMenu } from './actions_menu'; import { ObservabilityAIAssistantTelemetryEventType } from '../../analytics/telemetry_event_type'; -// defined and used in x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx -const CONTEXT_INSTRUCTION = - 'The following contextual information is available to help you understand the alert'; - function getLastMessageOfType(messages: Message[], role: MessageRole) { return last(messages.filter((msg) => msg.message.role === role)); } diff --git a/x-pack/solutions/observability/plugins/observability/kibana.jsonc b/x-pack/solutions/observability/plugins/observability/kibana.jsonc index 161e388fe29bb..d9a0fab049d13 100644 --- a/x-pack/solutions/observability/plugins/observability/kibana.jsonc +++ b/x-pack/solutions/observability/plugins/observability/kibana.jsonc @@ -1,19 +1,14 @@ { "type": "plugin", "id": "@kbn/observability-plugin", - "owner": [ - "@elastic/obs-ux-management-team" - ], + "owner": ["@elastic/obs-ux-management-team"], "group": "observability", "visibility": "private", "plugin": { "id": "observability", "browser": true, "server": true, - "configPath": [ - "xpack", - "observability" - ], + "configPath": ["xpack", "observability"], "requiredPlugins": [ "aiops", "alerting", @@ -45,7 +40,8 @@ "logsExplorer", "logsShared", "licensing", - "navigation" + "navigation", + "observabilityAIAssistant" ], "optionalPlugins": [ "discover", @@ -68,8 +64,6 @@ "stackAlerts", "spaces" ], - "extraPublicDirs": [ - "common" - ] + "extraPublicDirs": ["common"] } -} \ No newline at end of file +} diff --git a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx index d63fd5d06eccd..5b4a5f30a2627 100644 --- a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx +++ b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx @@ -9,14 +9,11 @@ import React, { useCallback } from 'react'; import { i18n } from '@kbn/i18n'; import { ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils'; import dedent from 'dedent'; +import { CONTEXT_INSTRUCTION } from '@kbn/observability-ai-assistant-plugin/common'; import { type AlertDetailsContextualInsight } from '../../../server/services'; import { useKibana } from '../../utils/kibana_react'; import { AlertData } from '../../hooks/use_fetch_alert_detail'; -// used in x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx -const CONTEXT_INSTRUCTION = - 'The following contextual information is available to help you understand the alert'; - export function AlertDetailContextualInsights({ alert }: { alert: AlertData | null }) { const { services: { observabilityAIAssistant, http }, From 0337e8046b2a966a904022c464bbe4939b0ef98c Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Wed, 15 Jan 2025 15:37:29 -0500 Subject: [PATCH 3/6] [Obs AI Assistant] Update instruction split to only affect alerts (#206673) --- ...uction.ts => alert_context_instruction.ts} | 2 +- .../common/index.ts | 2 +- .../public/components/insight/insight.tsx | 38 ++++++++++++------- .../alert_details_contextual_insights.tsx | 4 +- 4 files changed, 28 insertions(+), 18 deletions(-) rename x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/{context_instruction.ts => alert_context_instruction.ts} (89%) diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/context_instruction.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/alert_context_instruction.ts similarity index 89% rename from x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/context_instruction.ts rename to x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/alert_context_instruction.ts index adf836ddaa73e..f3c8980ea723d 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/context_instruction.ts +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/alert_context_instruction.ts @@ -5,5 +5,5 @@ * 2.0. */ -export const CONTEXT_INSTRUCTION = +export const ALERT_CONTEXT_INSTRUCTION = 'The following contextual information is available to help you understand the alert'; diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts index e0dff6672b6d2..da7affc3b57ab 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts @@ -51,4 +51,4 @@ export { ShortIdTable } from './utils/short_id_table'; export { KnowledgeBaseType } from './types'; -export { CONTEXT_INSTRUCTION } from './context_instruction'; +export { ALERT_CONTEXT_INSTRUCTION } from './alert_context_instruction'; diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx index 1b8a41dae67b2..7a5bdfc89f53f 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx @@ -22,7 +22,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react' import useObservable from 'react-use/lib/useObservable'; import dedent from 'dedent'; import { ILicense } from '@kbn/licensing-plugin/public'; -import { CONTEXT_INSTRUCTION } from '../../../common/context_instruction'; +import { ALERT_CONTEXT_INSTRUCTION } from '../../../common/alert_context_instruction'; import { MessageRole, type Message } from '../../../common/types'; import { ObservabilityAIAssistantChatServiceContext } from '../../context/observability_ai_assistant_chat_service_context'; import { useAbortableAsync } from '../../hooks/use_abortable_async'; @@ -302,10 +302,15 @@ export function Insight({ try { const { instructions = '' } = JSON.parse(lastUserPrompt); - // instructions is a large multiline string with contextual information appended to it. - // We'll split at CONTEXT_INSTRUCTION so that we can extract the instructions the user needs to edit - const [beforeContextInstruction] = instructions.split(CONTEXT_INSTRUCTION); - return beforeContextInstruction.trim(); + // For alerts - instructions is a large multiline string with contextual information appended to it. + // We'll split at ALERT_CONTEXT_INSTRUCTION so that we can extract the instructions the user needs to edit + if (instructions.includes(ALERT_CONTEXT_INSTRUCTION)) { + const [beforeContextInstruction] = instructions.split(ALERT_CONTEXT_INSTRUCTION); + return beforeContextInstruction.trim(); + } + + // in all other cases + return instructions.trim(); } catch (e) { return ''; } @@ -323,15 +328,20 @@ export function Insight({ return false; } - const [_beforeContextInstruction, afterContextInstruction] = - parsedContent.instructions.split(CONTEXT_INSTRUCTION); - - // Rebuild instructions with the new prompt, preserving everything after the delimiter - const updatedInstructions = dedent( - `${newPrompt} - ${CONTEXT_INSTRUCTION} - ${afterContextInstruction}` - ); + // Rebuild instructions with the new prompt + let updatedInstructions; + if (parsedContent.instructions.includes(ALERT_CONTEXT_INSTRUCTION)) { + const [_beforeContextInstruction, afterContextInstruction] = + parsedContent.instructions.split(ALERT_CONTEXT_INSTRUCTION); + + updatedInstructions = dedent( + `${newPrompt} + ${ALERT_CONTEXT_INSTRUCTION} + ${afterContextInstruction}` + ); + } else { + updatedInstructions = newPrompt; + } // Assign the updated instructions parsedContent.instructions = updatedInstructions; diff --git a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx index 5b4a5f30a2627..0bc973efc9b31 100644 --- a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx +++ b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx @@ -9,7 +9,7 @@ import React, { useCallback } from 'react'; import { i18n } from '@kbn/i18n'; import { ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils'; import dedent from 'dedent'; -import { CONTEXT_INSTRUCTION } from '@kbn/observability-ai-assistant-plugin/common'; +import { ALERT_CONTEXT_INSTRUCTION } from '@kbn/observability-ai-assistant-plugin/common'; import { type AlertDetailsContextualInsight } from '../../../server/services'; import { useKibana } from '../../utils/kibana_react'; import { AlertData } from '../../hooks/use_fetch_alert_detail'; @@ -63,7 +63,7 @@ export function AlertDetailContextualInsights({ alert }: { alert: AlertData | nu instructions: dedent( `I'm an SRE. I am looking at an alert that was triggered. I want to understand why it was triggered, what it means, and what I should do next. - ${CONTEXT_INSTRUCTION}: + ${ALERT_CONTEXT_INSTRUCTION}: ${obsAlertContext} The user already know the alert reason so do not repeat this: ${alert.formatted.reason} From 43331aeaf0983078589af93980aa6bb490222b27 Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Thu, 16 Jan 2025 09:46:13 -0500 Subject: [PATCH 4/6] [Obs AI Assistant] Revert instructions split (#206673) --- .../common/alert_context_instruction.ts | 9 ------ .../common/index.ts | 2 -- .../observability_ai_assistant/kibana.jsonc | 2 +- .../public/components/insight/insight.tsx | 28 +------------------ .../plugins/observability/kibana.jsonc | 16 +++++++---- .../alert_details_contextual_insights.tsx | 3 +- 6 files changed, 14 insertions(+), 46 deletions(-) delete mode 100644 x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/alert_context_instruction.ts diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/alert_context_instruction.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/alert_context_instruction.ts deleted file mode 100644 index f3c8980ea723d..0000000000000 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/alert_context_instruction.ts +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export const ALERT_CONTEXT_INSTRUCTION = - 'The following contextual information is available to help you understand the alert'; diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts index da7affc3b57ab..0157a6a2b0aae 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/common/index.ts @@ -50,5 +50,3 @@ export { concatenateChatCompletionChunks } from './utils/concatenate_chat_comple export { ShortIdTable } from './utils/short_id_table'; export { KnowledgeBaseType } from './types'; - -export { ALERT_CONTEXT_INSTRUCTION } from './alert_context_instruction'; diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc index 02fddc65aff83..ed106c9b6a791 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/kibana.jsonc @@ -21,6 +21,6 @@ "optionalPlugins": ["cloud", "serverless"], "requiredBundles": ["kibanaReact", "kibanaUtils"], "runtimePluginDependencies": ["ml"], - "extraPublicDirs": ["common"] + "extraPublicDirs": [] } } diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx index 7a5bdfc89f53f..e5ac1ddd60988 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx @@ -20,9 +20,7 @@ import { i18n } from '@kbn/i18n'; import { cloneDeep, isArray, isEmpty, last, once } from 'lodash'; import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import useObservable from 'react-use/lib/useObservable'; -import dedent from 'dedent'; import { ILicense } from '@kbn/licensing-plugin/public'; -import { ALERT_CONTEXT_INSTRUCTION } from '../../../common/alert_context_instruction'; import { MessageRole, type Message } from '../../../common/types'; import { ObservabilityAIAssistantChatServiceContext } from '../../context/observability_ai_assistant_chat_service_context'; import { useAbortableAsync } from '../../hooks/use_abortable_async'; @@ -301,15 +299,6 @@ export function Insight({ try { const { instructions = '' } = JSON.parse(lastUserPrompt); - - // For alerts - instructions is a large multiline string with contextual information appended to it. - // We'll split at ALERT_CONTEXT_INSTRUCTION so that we can extract the instructions the user needs to edit - if (instructions.includes(ALERT_CONTEXT_INSTRUCTION)) { - const [beforeContextInstruction] = instructions.split(ALERT_CONTEXT_INSTRUCTION); - return beforeContextInstruction.trim(); - } - - // in all other cases return instructions.trim(); } catch (e) { return ''; @@ -328,23 +317,8 @@ export function Insight({ return false; } - // Rebuild instructions with the new prompt - let updatedInstructions; - if (parsedContent.instructions.includes(ALERT_CONTEXT_INSTRUCTION)) { - const [_beforeContextInstruction, afterContextInstruction] = - parsedContent.instructions.split(ALERT_CONTEXT_INSTRUCTION); - - updatedInstructions = dedent( - `${newPrompt} - ${ALERT_CONTEXT_INSTRUCTION} - ${afterContextInstruction}` - ); - } else { - updatedInstructions = newPrompt; - } - // Assign the updated instructions - parsedContent.instructions = updatedInstructions; + parsedContent.instructions = newPrompt; userMessage.message.content = JSON.stringify(parsedContent); setIsPromptUpdated(true); diff --git a/x-pack/solutions/observability/plugins/observability/kibana.jsonc b/x-pack/solutions/observability/plugins/observability/kibana.jsonc index d9a0fab049d13..8b046179027d5 100644 --- a/x-pack/solutions/observability/plugins/observability/kibana.jsonc +++ b/x-pack/solutions/observability/plugins/observability/kibana.jsonc @@ -1,14 +1,19 @@ { "type": "plugin", "id": "@kbn/observability-plugin", - "owner": ["@elastic/obs-ux-management-team"], + "owner": [ + "@elastic/obs-ux-management-team" + ], "group": "observability", "visibility": "private", "plugin": { "id": "observability", "browser": true, "server": true, - "configPath": ["xpack", "observability"], + "configPath": [ + "xpack", + "observability" + ], "requiredPlugins": [ "aiops", "alerting", @@ -40,8 +45,7 @@ "logsExplorer", "logsShared", "licensing", - "navigation", - "observabilityAIAssistant" + "navigation" ], "optionalPlugins": [ "discover", @@ -64,6 +68,8 @@ "stackAlerts", "spaces" ], - "extraPublicDirs": ["common"] + "extraPublicDirs": [ + "common" + ] } } diff --git a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx index 0bc973efc9b31..17f7d335624d1 100644 --- a/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx +++ b/x-pack/solutions/observability/plugins/observability/public/pages/alert_details/alert_details_contextual_insights.tsx @@ -9,7 +9,6 @@ import React, { useCallback } from 'react'; import { i18n } from '@kbn/i18n'; import { ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils'; import dedent from 'dedent'; -import { ALERT_CONTEXT_INSTRUCTION } from '@kbn/observability-ai-assistant-plugin/common'; import { type AlertDetailsContextualInsight } from '../../../server/services'; import { useKibana } from '../../utils/kibana_react'; import { AlertData } from '../../hooks/use_fetch_alert_detail'; @@ -63,7 +62,7 @@ export function AlertDetailContextualInsights({ alert }: { alert: AlertData | nu instructions: dedent( `I'm an SRE. I am looking at an alert that was triggered. I want to understand why it was triggered, what it means, and what I should do next. - ${ALERT_CONTEXT_INSTRUCTION}: + The following contextual information is available to help you understand the alert: ${obsAlertContext} The user already know the alert reason so do not repeat this: ${alert.formatted.reason} From 828946d7ac3e2906e25400f3ce808e7d6d7471e5 Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Thu, 16 Jan 2025 09:53:04 -0500 Subject: [PATCH 5/6] [Obs AI Assistant] Update variable (#206673) --- .../public/components/insight/insight.tsx | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx index e5ac1ddd60988..dc09d750b54ad 100644 --- a/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx +++ b/x-pack/platform/plugins/shared/observability_solution/observability_ai_assistant/public/components/insight/insight.tsx @@ -404,15 +404,11 @@ export function Insight({ ); } else if (isEditingPrompt) { - const instructionToEdit = getPromptToEdit(); + const promptToEdit = getPromptToEdit(); - if (messages.status === FETCH_STATUS.SUCCESS && instructionToEdit) { + if (messages.status === FETCH_STATUS.SUCCESS && promptToEdit) { children = ( - + ); } else { children = ; From e0e1ee81c981f48dd372a0d64f3874fecb109c8f Mon Sep 17 00:00:00 2001 From: Viduni Wickramarachchi Date: Thu, 16 Jan 2025 09:55:35 -0500 Subject: [PATCH 6/6] [Obs AI Assistant] Revert kibana.jsonc new line (#206673) --- .../solutions/observability/plugins/observability/kibana.jsonc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/solutions/observability/plugins/observability/kibana.jsonc b/x-pack/solutions/observability/plugins/observability/kibana.jsonc index 8b046179027d5..161e388fe29bb 100644 --- a/x-pack/solutions/observability/plugins/observability/kibana.jsonc +++ b/x-pack/solutions/observability/plugins/observability/kibana.jsonc @@ -72,4 +72,4 @@ "common" ] } -} +} \ No newline at end of file