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

[Security Solution] [AI Assistant] Replace polynomial regular expression with constant time string manipulation #209314

Merged
merged 21 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8f59b95
Replace polynomial regular expression with constant string manipulation
KDKHD Feb 3, 2025
b03396a
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 3, 2025
23a2503
Merge branch 'main' into bug/content-references-regex-performance
elasticmachine Feb 3, 2025
edcefc1
Include missing strings in prompts
KDKHD Feb 4, 2025
196a01d
Add test to citations
KDKHD Feb 5, 2025
791b965
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 5, 2025
b3fec5d
update content reference parser
KDKHD Feb 5, 2025
3778d7d
lint
KDKHD Feb 5, 2025
af99911
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 5, 2025
647fb00
lint
KDKHD Feb 5, 2025
4e5663e
Merge branch 'bug/content-referencest-regex-performance' of github.co…
KDKHD Feb 5, 2025
a399f4f
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 5, 2025
dd972ff
test
KDKHD Feb 5, 2025
79ea623
Merge branch 'bug/content-references-regex-performance' of github.com…
KDKHD Feb 5, 2025
92f9d52
Merge branch 'main' into bug/content-references-regex-performance
elasticmachine Feb 5, 2025
4ddac67
Merge branch 'main' into bug/content-references-regex-performance
KDKHD Feb 6, 2025
5ffbcdf
content reference parser - eat empty references to better handle erro…
KDKHD Feb 6, 2025
55ef292
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Feb 6, 2025
fcfaccd
content reference parser - parse references on new lines correctly
KDKHD Feb 6, 2025
86e9ef3
Update x-pack/solutions/security/plugins/elastic_assistant/server/lib…
KDKHD Feb 6, 2025
e5482f0
code review
KDKHD Feb 6, 2025
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
Prev Previous commit
Next Next commit
Add test to citations
  • Loading branch information
KDKHD committed Feb 5, 2025
commit 196a01d37b696ab371d27379f698631d050c5dbd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { BEDROCK_SYSTEM_PROMPT, DEFAULT_SYSTEM_PROMPT, GEMINI_SYSTEM_PROMPT, STRUCTURED_SYSTEM_PROMPT } from "./prompts";

describe('prompts', () => {
it.each([
[DEFAULT_SYSTEM_PROMPT, '{include_citations_prompt_placeholder}', 1],
[GEMINI_SYSTEM_PROMPT, '{include_citations_prompt_placeholder}', 1],
[BEDROCK_SYSTEM_PROMPT, '{include_citations_prompt_placeholder}', 1],
[STRUCTURED_SYSTEM_PROMPT, '{include_citations_prompt_placeholder}', 1],
[DEFAULT_SYSTEM_PROMPT, 'You are a security analyst', 1],
[GEMINI_SYSTEM_PROMPT, 'You are an assistant', 1],
[BEDROCK_SYSTEM_PROMPT, 'You are a security analyst', 1],
])('"%s" contains "%s" %s times', async (prompt: string, containedString: string, expectedCount: number) => {
const regex = new RegExp(containedString, "g");
expect((prompt.match(regex) || []).length).toBe(expectedCount);
})

});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const BASE_GEMINI_PROMPT =
const KB_CATCH =
'If the knowledge base tool gives empty results, do your best to answer the question from the perspective of an expert security analyst.';
export const GEMINI_SYSTEM_PROMPT = `${BASE_GEMINI_PROMPT} ${KB_CATCH} {include_citations_prompt_placeholder}`;
export const BEDROCK_SYSTEM_PROMPT = `${DEFAULT_SYSTEM_PROMPT} Use tools as often as possible, as they have access to the latest data and syntax. Never return <thinking> tags in the response, but make sure to include <result> tags content in the response. Do not reflect on the quality of the returned search results in your response. {include_citations_prompt_placeholder} ALWAYS return the exact response from NaturalLanguageESQLTool verbatim in the final response, without adding further description.`;
export const BEDROCK_SYSTEM_PROMPT = `${DEFAULT_SYSTEM_PROMPT} Use tools as often as possible, as they have access to the latest data and syntax. Never return <thinking> tags in the response, but make sure to include <result> tags content in the response. Do not reflect on the quality of the returned search results in your response. ALWAYS return the exact response from NaturalLanguageESQLTool verbatim in the final response, without adding further description.`;
export const GEMINI_USER_PROMPT = `Now, always using the tools at your disposal, step by step, come up with a response to this request:\n\n`;

export const STRUCTURED_SYSTEM_PROMPT = `Respond to the human as helpfully and accurately as possible. ${KNOWLEDGE_HISTORY} {include_citations_prompt_placeholder} You have access to the following tools:
Expand Down