Skip to content

Commit

Permalink
[8.15] [Security solution] Remove `isEnabledLangChain` from…
Browse files Browse the repository at this point in the history
… UI and telemetry (elastic#188990) (elastic#189012)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[Security solution] Remove `isEnabledLangChain` from UI and
telemetry (elastic#188990)](elastic#188990)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Steph
Milovic","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-07-23T21:16:41Z","message":"[Security
solution] Remove `isEnabledLangChain` from UI and telemetry
(elastic#188990)","sha":"369eef010605637652b423a3cd715c7b2ec7674b","branchLabelMapping":{"^v8.16.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:
SecuritySolution","ci:cloud-deploy","Team:Security Generative
AI","v8.15.0","v8.16.0"],"title":"[Security solution] Remove
`isEnabledLangChain` from UI and
telemetry","number":188990,"url":"https://github.com/elastic/kibana/pull/188990","mergeCommit":{"message":"[Security
solution] Remove `isEnabledLangChain` from UI and telemetry
(elastic#188990)","sha":"369eef010605637652b423a3cd715c7b2ec7674b"}},"sourceBranch":"main","suggestedTargetBranches":["8.15"],"targetPullRequestStates":[{"branch":"8.15","label":"v8.15.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/188990","number":188990,"mergeCommit":{"message":"[Security
solution] Remove `isEnabledLangChain` from UI and telemetry
(elastic#188990)","sha":"369eef010605637652b423a3cd715c7b2ec7674b"}}]}]
BACKPORT-->

Co-authored-by: Steph Milovic <[email protected]>
  • Loading branch information
kibanamachine and stephmilovic authored Jul 23, 2024
1 parent aa450a4 commit 44d85c7
Show file tree
Hide file tree
Showing 26 changed files with 36 additions and 758 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ describe('AlertsSettings', () => {
it('updates the knowledgeBase settings when the alerts range slider is changed', () => {
const setUpdatedKnowledgeBaseSettings = jest.fn();
const knowledgeBase: KnowledgeBaseConfig = {
isEnabledRAGAlerts: true,
isEnabledKnowledgeBase: false,
latestAlerts: DEFAULT_LATEST_ALERTS,
};

Expand All @@ -36,8 +34,6 @@ describe('AlertsSettings', () => {
fireEvent.change(rangeSlider, { target: { value: '10' } });

expect(setUpdatedKnowledgeBaseSettings).toHaveBeenCalledWith({
isEnabledRAGAlerts: true,
isEnabledKnowledgeBase: false,
latestAlerts: 10,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ describe('use chat send', () => {
assistantTelemetry: {
reportAssistantMessageSent,
},
knowledgeBase: { isEnabledKnowledgeBase: false, isEnabledRAGAlerts: false },
});
});
it('handleOnChatCleared clears the conversation', async () => {
Expand Down Expand Up @@ -150,17 +149,13 @@ describe('use chat send', () => {
expect(reportAssistantMessageSent).toHaveBeenNthCalledWith(1, {
conversationId: testProps.currentConversation?.title,
role: 'user',
isEnabledKnowledgeBase: false,
isEnabledRAGAlerts: false,
actionTypeId: '.gen-ai',
model: undefined,
provider: 'OpenAI',
});
expect(reportAssistantMessageSent).toHaveBeenNthCalledWith(2, {
conversationId: testProps.currentConversation?.title,
role: 'assistant',
isEnabledKnowledgeBase: false,
isEnabledRAGAlerts: false,
actionTypeId: '.gen-ai',
model: undefined,
provider: 'OpenAI',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ export const useChatSend = ({
setUserPrompt,
setCurrentConversation,
}: UseChatSendProps): UseChatSend => {
const {
assistantTelemetry,
knowledgeBase: { isEnabledKnowledgeBase, isEnabledRAGAlerts },
toasts,
} = useAssistantContext();
const { assistantTelemetry, toasts } = useAssistantContext();

const { isLoading, sendMessage, abortStream } = useSendMessage();
const { clearConversation, removeLastMessage } = useConversation();
Expand Down Expand Up @@ -129,8 +125,6 @@ export const useChatSend = ({
assistantTelemetry?.reportAssistantMessageSent({
conversationId: currentConversation.title,
role: userMessage.role,
isEnabledKnowledgeBase,
isEnabledRAGAlerts,
actionTypeId: currentConversation.apiConfig.actionTypeId,
model: currentConversation.apiConfig.model,
provider: currentConversation.apiConfig.provider,
Expand All @@ -149,8 +143,6 @@ export const useChatSend = ({
actionTypeId: currentConversation.apiConfig.actionTypeId,
model: currentConversation.apiConfig.model,
provider: currentConversation.apiConfig.provider,
isEnabledKnowledgeBase,
isEnabledRAGAlerts,
});
},
[
Expand All @@ -159,8 +151,6 @@ export const useChatSend = ({
currentConversation,
editingSystemPromptId,
http,
isEnabledKnowledgeBase,
isEnabledRAGAlerts,
selectedPromptContexts,
sendMessage,
setCurrentConversation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ const AssistantComponent: React.FC<Props> = ({
assistantAvailability: { isAssistantEnabled },
getComments,
http,
knowledgeBase: { isEnabledKnowledgeBase, isEnabledRAGAlerts },
promptContexts,
setLastConversationId,
getLastConversationId,
Expand Down Expand Up @@ -585,7 +584,6 @@ const AssistantComponent: React.FC<Props> = ({
showAnonymizedValues,
refetchCurrentConversation,
regenerateMessage: handleRegenerateResponse,
isEnabledLangChain: isEnabledKnowledgeBase || isEnabledRAGAlerts,
isFetchingResponse: isLoadingChatSend,
setIsStreaming,
currentUserAvatar,
Expand All @@ -612,8 +610,6 @@ const AssistantComponent: React.FC<Props> = ({
showAnonymizedValues,
refetchCurrentConversation,
handleRegenerateResponse,
isEnabledKnowledgeBase,
isEnabledRAGAlerts,
isLoadingChatSend,
currentUserAvatar,
selectedPromptContextsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ const mockUseAssistantContext = {
},
],
setAllSystemPrompts: jest.fn(),
knowledgeBase: {
isEnabledRAGAlerts: false,
isEnabledKnowledgeBase: false,
},
};
jest.mock('../../../../assistant_context', () => {
const original = jest.requireActual('../../../../assistant_context');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ const mockUseAssistantContext = {
setSelectedSettingsTab,
promptContexts: {},
allQuickPrompts: MOCK_QUICK_PROMPTS,
knowledgeBase: {
isEnabledKnowledgeBase: true,
},
};

const testTitle = 'SPL_QUERY_CONVERSION_TITLE';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ export const QuickPrompts: React.FC<QuickPromptsProps> = React.memo(
({ setInput, setIsSettingsModalVisible, trackPrompt, allPrompts }) => {
const [quickPromptsContainerRef, { width }] = useMeasure();

const { knowledgeBase, promptContexts, setSelectedSettingsTab } = useAssistantContext();
const { promptContexts, setSelectedSettingsTab } = useAssistantContext();

const contextFilteredQuickPrompts = useMemo(() => {
const registeredPromptContextTitles = Object.values(promptContexts).map((pc) => pc.category);
// If KB is enabled, include KNOWLEDGE_BASE_CATEGORY so KB dependent quick prompts are shown
if (knowledgeBase.isEnabledKnowledgeBase) {
registeredPromptContextTitles.push(KNOWLEDGE_BASE_CATEGORY);
}
// include KNOWLEDGE_BASE_CATEGORY so KB dependent quick prompts are shown
registeredPromptContextTitles.push(KNOWLEDGE_BASE_CATEGORY);

return allPrompts.filter((prompt) => {
// only quick prompts
if (prompt.promptType !== PromptTypeEnum.quick) {
Expand All @@ -65,7 +64,7 @@ export const QuickPrompts: React.FC<QuickPromptsProps> = React.memo(
});
}
});
}, [allPrompts, knowledgeBase.isEnabledKnowledgeBase, promptContexts]);
}, [allPrompts, promptContexts]);

// Overflow state
const [isOverflowPopoverOpen, setIsOverflowPopoverOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ const mockValues = {
allSystemPrompts: mockSystemPrompts,
allQuickPrompts: mockQuickPrompts,
knowledgeBase: {
isEnabledRAGAlerts: true,
isEnabledKnowledgeBase: true,
latestAlerts: DEFAULT_LATEST_ALERTS,
},
baseConversations: {},
Expand Down Expand Up @@ -82,9 +80,7 @@ const updatedValues = {
],
},
knowledgeBase: {
isEnabledRAGAlerts: false,
isEnabledKnowledgeBase: false,
latestAlerts: DEFAULT_LATEST_ALERTS,
latestAlerts: DEFAULT_LATEST_ALERTS + 10,
},
assistantStreamingEnabled: false,
};
Expand Down Expand Up @@ -206,7 +202,7 @@ describe('useSettingsUpdater', () => {
expect(setKnowledgeBaseMock).toHaveBeenCalledWith(updatedValues.knowledgeBase);
});
});
it('should track which toggles have been updated when saveSettings is called', async () => {
it('should track when alerts count is updated', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook(() =>
useSettingsUpdater(
Expand All @@ -225,16 +221,14 @@ describe('useSettingsUpdater', () => {
await waitForNextUpdate();
const { setUpdatedKnowledgeBaseSettings } = result.current;

setUpdatedKnowledgeBaseSettings(updatedValues.knowledgeBase);

await result.current.saveSettings();
expect(reportAssistantSettingToggled).toHaveBeenCalledWith({
isEnabledKnowledgeBase: false,
isEnabledRAGAlerts: false,
setUpdatedKnowledgeBaseSettings({
...updatedValues.knowledgeBase,
});
await result.current.saveSettings();
expect(reportAssistantSettingToggled).toHaveBeenCalledWith({ alertsCountUpdated: true });
});
});
it('should track only toggles that updated', async () => {
it('should track when streaming is updated', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook(() =>
useSettingsUpdater(
Expand All @@ -251,19 +245,16 @@ describe('useSettingsUpdater', () => {
)
);
await waitForNextUpdate();
const { setUpdatedKnowledgeBaseSettings } = result.current;
const { setUpdatedAssistantStreamingEnabled } = result.current;

setUpdatedKnowledgeBaseSettings({
...updatedValues.knowledgeBase,
isEnabledKnowledgeBase: true,
});
setUpdatedAssistantStreamingEnabled(false);
await result.current.saveSettings();
expect(reportAssistantSettingToggled).toHaveBeenCalledWith({
isEnabledRAGAlerts: false,
assistantStreamingEnabled: false,
});
});
});
it('if no toggles update, do not track anything', async () => {
it('if no settings update, do not track anything', async () => {
await act(async () => {
const { result, waitForNextUpdate } = renderHook(() =>
useSettingsUpdater(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,13 @@ export const useSettingsUpdater = (
const bulkResult = hasBulkConversations
? await bulkUpdateConversations(http, conversationsSettingsBulkActions, toasts)
: undefined;

const didUpdateKnowledgeBase =
knowledgeBase.isEnabledKnowledgeBase !== updatedKnowledgeBaseSettings.isEnabledKnowledgeBase;
const didUpdateRAGAlerts =
knowledgeBase.isEnabledRAGAlerts !== updatedKnowledgeBaseSettings.isEnabledRAGAlerts;
const didUpdateAssistantStreamingEnabled =
assistantStreamingEnabled !== updatedAssistantStreamingEnabled;
if (didUpdateKnowledgeBase || didUpdateRAGAlerts || didUpdateAssistantStreamingEnabled) {
const didUpdateAlertsCount =
knowledgeBase.latestAlerts !== updatedKnowledgeBaseSettings.latestAlerts;
if (didUpdateAssistantStreamingEnabled || didUpdateAlertsCount) {
assistantTelemetry?.reportAssistantSettingToggled({
...(didUpdateKnowledgeBase
? { isEnabledKnowledgeBase: updatedKnowledgeBaseSettings.isEnabledKnowledgeBase }
: {}),
...(didUpdateRAGAlerts
? { isEnabledRAGAlerts: updatedKnowledgeBaseSettings.isEnabledRAGAlerts }
: {}),
...(didUpdateAlertsCount ? { alertsCountUpdated: didUpdateAlertsCount } : {}),
...(didUpdateAssistantStreamingEnabled
? { assistantStreamingEnabled: updatedAssistantStreamingEnabled }
: {}),
Expand All @@ -207,21 +199,20 @@ export const useSettingsUpdater = (
(bulkPromptsResult?.success ?? true)
);
}, [
hasBulkConversations,
hasBulkPrompts,
http,
conversationsSettingsBulkActions,
promptsBulkActions,
toasts,
knowledgeBase.isEnabledKnowledgeBase,
knowledgeBase.isEnabledRAGAlerts,
updatedKnowledgeBaseSettings,
hasBulkConversations,
conversationsSettingsBulkActions,
assistantStreamingEnabled,
updatedAssistantStreamingEnabled,
knowledgeBase.latestAlerts,
updatedKnowledgeBaseSettings,
setAssistantStreamingEnabled,
setKnowledgeBase,
hasBulkAnonymizationFields,
anonymizationFieldsBulkActions,
hasBulkPrompts,
promptsBulkActions,
assistantTelemetry,
]);

Expand Down
2 changes: 0 additions & 2 deletions x-pack/packages/kbn-elastic-assistant/impl/assistant/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/

export interface KnowledgeBaseConfig {
isEnabledRAGAlerts: boolean;
isEnabledKnowledgeBase: boolean;
latestAlerts: number;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@ export const ANONYMIZATION_TABLE_SESSION_STORAGE_KEY = 'anonymizationTable';
export const DEFAULT_LATEST_ALERTS = 20;

export const DEFAULT_KNOWLEDGE_BASE_SETTINGS: KnowledgeBaseConfig = {
isEnabledRAGAlerts: false,
isEnabledKnowledgeBase: false,
latestAlerts: DEFAULT_LATEST_ALERTS,
};
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export interface AssistantProviderProps {
getComments: (commentArgs: {
abortStream: () => void;
currentConversation?: Conversation;
isEnabledLangChain: boolean;
isFetchingResponse: boolean;
refetchCurrentConversation: ({ isStreamRefetch }: { isStreamRefetch?: boolean }) => void;
regenerateMessage: (conversationId: string) => void;
Expand Down Expand Up @@ -106,7 +105,6 @@ export interface UseAssistantContext {
getComments: (commentArgs: {
abortStream: () => void;
currentConversation?: Conversation;
isEnabledLangChain: boolean;
isFetchingResponse: boolean;
refetchCurrentConversation: ({ isStreamRefetch }: { isStreamRefetch?: boolean }) => void;
regenerateMessage: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,12 @@ export interface AssistantTelemetry {
reportAssistantMessageSent: (params: {
conversationId: string;
role: string;
isEnabledKnowledgeBase: boolean;
isEnabledRAGAlerts: boolean;
actionTypeId: string;
model?: string;
provider?: string;
}) => void;
reportAssistantQuickPrompt: (params: { conversationId: string; promptTitle: string }) => void;
reportAssistantSettingToggled: (params: {
isEnabledKnowledgeBase?: boolean;
isEnabledRAGAlerts?: boolean;
assistantStreamingEnabled?: boolean;
}) => void;
reportAssistantSettingToggled: (params: { assistantStreamingEnabled?: boolean }) => void;
}

export interface AssistantAvailability {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ jest.mock('../assistant_context', () => {
const setUpdatedKnowledgeBaseSettings = jest.fn();
const defaultProps = {
knowledgeBase: {
isEnabledKnowledgeBase: true,
isEnabledRAGAlerts: false,
latestAlerts: DEFAULT_LATEST_ALERTS,
},
setUpdatedKnowledgeBaseSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const testProps = {
setIsStreaming: jest.fn(),
refetchCurrentConversation: jest.fn(),
regenerateMessage: jest.fn(),
isEnabledLangChain: false,
isFetchingResponse: false,
currentConversation,
showAnonymizedValues,
Expand Down
Loading

0 comments on commit 44d85c7

Please sign in to comment.