forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution] Security Assistant: Prompt Editor / Sends System …
…Prompts / Sends Prompt Context #7 - adds the query editor - passes context and system prompt to the api
- Loading branch information
1 parent
a3ddec0
commit 521f26a
Showing
20 changed files
with
848 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...lugins/security_solution/public/security_assistant/content/prompts/system/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const YOU_ARE_A_HELPFUL_EXPERT_ASSISTANT = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.youAreAHelpfulExpertAssistant', | ||
{ | ||
defaultMessage: | ||
'You are a helpful, expert assistant who answers questions about Elastic Security.', | ||
} | ||
); | ||
|
||
export const USE_THE_FOLLOWING_CONTEXT_TO_ANSWER = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.useTheFollowingContextToAnswer', | ||
{ | ||
defaultMessage: 'Use the following context to answer questions:', | ||
} | ||
); | ||
|
||
export const IF_YOU_DONT_KNOW_THE_ANSWER = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.ifYouDontKnowTheAnswer', | ||
{ | ||
defaultMessage: "If you don't know the answer, don't try to make one up.", | ||
} | ||
); | ||
|
||
export const SUPERHERO_PERSONALITY = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.superheroPersonality', | ||
{ | ||
defaultMessage: 'You have the personality of a mutant superhero who says "bub" a lot.', | ||
} | ||
); | ||
|
||
export const DEFAULT_SYSTEM_PROMPT = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.defaultSystemPrompt', | ||
{ | ||
defaultMessage: `${YOU_ARE_A_HELPFUL_EXPERT_ASSISTANT} ${IF_YOU_DONT_KNOW_THE_ANSWER} | ||
${USE_THE_FOLLOWING_CONTEXT_TO_ANSWER}`, | ||
} | ||
); | ||
|
||
export const DEFAULT_SYSTEM_PROMPT_NAME = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.defaultSystemPromptName', | ||
{ | ||
defaultMessage: 'default system prompt', | ||
} | ||
); | ||
|
||
export const SUPERHERO_SYSTEM_PROMPT = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.superheroSystemPrompt', | ||
{ | ||
defaultMessage: `${YOU_ARE_A_HELPFUL_EXPERT_ASSISTANT} ${IF_YOU_DONT_KNOW_THE_ANSWER} | ||
${SUPERHERO_PERSONALITY} | ||
${USE_THE_FOLLOWING_CONTEXT_TO_ANSWER}`, | ||
} | ||
); | ||
|
||
export const SUPERHERO_SYSTEM_PROMPT_NAME = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.superheroSystemPromptName', | ||
{ | ||
defaultMessage: 'superhero system prompt', | ||
} | ||
); | ||
|
||
export const SYSTEM_PROMPT_CONTEXT = (context: string) => | ||
i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.system.systemPromptContext', | ||
{ | ||
values: { context }, | ||
defaultMessage: `CONTEXT:\n"""\n${context}\n"""`, | ||
} | ||
); |
37 changes: 37 additions & 0 deletions
37
.../plugins/security_solution/public/security_assistant/content/prompts/user/translations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
export const EXPLAIN_THE_MEANING_FROM_CONTEXT_ABOVE = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.user.explainTheMeaningFromContextAbove', | ||
{ | ||
defaultMessage: 'Explain the meaning from the context above', | ||
} | ||
); | ||
|
||
export const THEN_SUMMARIZE_SUGGESTED_KQL_AND_EQL_QUERIES = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.user.thenSummarizeSuggestedKqlAndEqlQueries', | ||
{ | ||
defaultMessage: 'then summarize a list of suggested Elasticsearch KQL and EQL queries', | ||
} | ||
); | ||
|
||
export const FINALLY_SUGGEST_INVESTIGATION_GUIDE_AND_FORMAT_AS_MARKDOWN = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.user.finallySuggestInvestigationGuideAndFormatAsMarkdown', | ||
{ | ||
defaultMessage: 'Finally, suggest an investigation guide, and format it as markdown', | ||
} | ||
); | ||
|
||
export const EXPLAIN_THEN_SUMMARIZE_SUGGEST_INVESTIGATION_GUIDE = i18n.translate( | ||
'xpack.securitySolution.securityAssistant.content.prompts.user.defaultAlertOrEventUserPrompt', | ||
{ | ||
defaultMessage: `${EXPLAIN_THE_MEANING_FROM_CONTEXT_ABOVE}, ${THEN_SUMMARIZE_SUGGESTED_KQL_AND_EQL_QUERIES}. | ||
${FINALLY_SUGGEST_INVESTIGATION_GUIDE_AND_FORMAT_AS_MARKDOWN}.`, | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
x-pack/plugins/security_solution/public/security_assistant/first_prompt_editor/helpers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import type { Prompt } from '../types'; | ||
|
||
export const getPromptById = ({ | ||
prompts, | ||
id, | ||
}: { | ||
prompts: Prompt[]; | ||
id: string; | ||
}): Prompt | undefined => prompts.find((p) => p.id === id); |
105 changes: 105 additions & 0 deletions
105
x-pack/plugins/security_solution/public/security_assistant/first_prompt_editor/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { EuiAvatar, EuiCommentList, EuiText } from '@elastic/eui'; | ||
import React, { useMemo } from 'react'; | ||
import styled from 'styled-components'; | ||
|
||
import type { PromptContext } from '../prompt_context/types'; | ||
import { SystemPrompt } from './system_prompt'; | ||
import type { Prompt } from '../types'; | ||
import { getPromptById } from './helpers'; | ||
|
||
import * as i18n from './translations'; | ||
import { SelectedPromptContexts } from './selected_prompt_contexts'; | ||
|
||
interface Props { | ||
promptContexts: Record<string, PromptContext>; | ||
promptTextPreview: string; | ||
selectedPromptContextIds: string[]; | ||
selectedSystemPromptId: string | null; | ||
setSelectedPromptContextIds: React.Dispatch<React.SetStateAction<string[]>>; | ||
setSelectedSystemPromptId: React.Dispatch<React.SetStateAction<string | null>>; | ||
systemPrompts: Prompt[]; | ||
} | ||
|
||
const PreviewText = styled(EuiText)` | ||
white-space: pre-line; | ||
`; | ||
|
||
const FirstPromptEditorComponent: React.FC<Props> = ({ | ||
promptContexts, | ||
promptTextPreview, | ||
selectedPromptContextIds, | ||
selectedSystemPromptId, | ||
setSelectedPromptContextIds, | ||
setSelectedSystemPromptId, | ||
systemPrompts, | ||
}) => { | ||
const selectedSystemPrompt = useMemo( | ||
() => | ||
getPromptById({ | ||
id: selectedSystemPromptId ?? '', | ||
prompts: systemPrompts, | ||
}), | ||
[selectedSystemPromptId, systemPrompts] | ||
); | ||
|
||
const commentBody = useMemo( | ||
() => ( | ||
<> | ||
<SystemPrompt | ||
selectedSystemPromptId={selectedSystemPromptId} | ||
setSelectedSystemPromptId={setSelectedSystemPromptId} | ||
systemPrompts={systemPrompts} | ||
/> | ||
|
||
<SelectedPromptContexts | ||
promptContexts={promptContexts} | ||
selectedPromptContextIds={selectedPromptContextIds} | ||
setSelectedPromptContextIds={setSelectedPromptContextIds} | ||
/> | ||
|
||
<PreviewText color="subdued"> | ||
{selectedSystemPrompt != null && <>{'\n'}</>} | ||
{promptTextPreview} | ||
</PreviewText> | ||
</> | ||
), | ||
[ | ||
promptContexts, | ||
promptTextPreview, | ||
selectedPromptContextIds, | ||
selectedSystemPrompt, | ||
selectedSystemPromptId, | ||
setSelectedPromptContextIds, | ||
setSelectedSystemPromptId, | ||
systemPrompts, | ||
] | ||
); | ||
|
||
const comments = useMemo( | ||
() => [ | ||
{ | ||
children: commentBody, | ||
event: ( | ||
<EuiText size="xs"> | ||
<i>{i18n.EDITING_PROMPT}</i> | ||
</EuiText> | ||
), | ||
timelineAvatar: <EuiAvatar name="user" size="l" color="subdued" iconType="logoSecurity" />, | ||
timelineAvatarAriaLabel: i18n.YOU, | ||
username: i18n.YOU, | ||
}, | ||
], | ||
[commentBody] | ||
); | ||
|
||
return <EuiCommentList comments={comments} aria-label={i18n.COMMENTS_LIST_ARIA_LABEL} />; | ||
}; | ||
|
||
export const FirstPromptEditor = React.memo(FirstPromptEditorComponent); |
Oops, something went wrong.