Skip to content

Commit

Permalink
[Security Solution] [Elastic AI Assistant] Consolidates settings into…
Browse files Browse the repository at this point in the history
… a single modal (#160468)

## Summary

This PR fixes the disjointed settings across the assistant by combining
them all into a single settings modal. It also resolves the Connector
`Model` configuration not being available when using the `OpenAI`
variant of the GenAI Connector.

Additional issues resolved:
- [x] Clearing conversation doesn't restore default system prompt
- [X] Double repeated welcome prompt
- [X] Clicking skip button broken

Resolves: elastic/security-team#7110
Resolves:
#161039 (review)
Resolves:
#161027 (review)

#### Conversations

<p align="center">
<img width="500"
src="https://github.com/elastic/kibana/assets/2946766/80e271e8-d12a-4d00-b6eb-d63cda2d8017"
/>
</p> 

#### Quick Prompts

<p align="center">
<img width="500"
src="https://github.com/elastic/kibana/assets/2946766/417c49c0-2029-49f1-a2f3-b9d0ae3690d3"
/>
</p> 

#### System Prompts

<p align="center">
<img width="500"
src="https://github.com/elastic/kibana/assets/2946766/cc2bac93-bfba-49c1-b5b8-6a6efa1c0a92"
/>
</p> 

#### Anonymization

<p align="center">
<img width="500"
src="https://github.com/elastic/kibana/assets/2946766/9a65683a-06cc-4cc7-9397-9db2633b20a3"
/>
</p> 









### Checklist

Delete any items that are not applicable to this PR.

- [X] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [X] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
spong authored Jul 12, 2023
1 parent 85a99c9 commit b323923
Show file tree
Hide file tree
Showing 66 changed files with 2,469 additions and 1,371 deletions.
3 changes: 2 additions & 1 deletion x-pack/packages/kbn-elastic-assistant/impl/assistant/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { HttpSetup } from '@kbn/core-http-browser';
import type { Message } from '../assistant_context/types';
import { Conversation } from '../assistant_context/types';
import { API_ERROR } from './translations';
import { MODEL_GPT_3_5_TURBO } from '../connectorland/models/model_selector/model_selector';

export interface FetchConnectorExecuteAction {
apiConfig: Conversation['apiConfig'];
Expand All @@ -33,7 +34,7 @@ export const fetchConnectorExecuteAction = async ({
const body =
apiConfig?.provider === OpenAiProviderType.OpenAi
? {
model: 'gpt-3.5-turbo',
model: apiConfig.model ?? MODEL_GPT_3_5_TURBO,
messages: outboundMessages,
n: 1,
stop: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const AssistantOverlay = React.memo<Props>(({ isAssistantEnabled }) => {
const handleShortcutPress = useCallback(() => {
// Try to restore the last conversation on shortcut pressed
if (!isModalVisible) {
setConversationId(localStorageLastConversationId || WELCOME_CONVERSATION_TITLE);
setConversationId(localStorageLastConversationId ?? WELCOME_CONVERSATION_TITLE);
}

setIsModalVisible(!isModalVisible);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const TEST_IDS = {
ADD_SYSTEM_PROMPT: 'addSystemPrompt',
PROMPT_SUPERSELECT: 'promptSuperSelect',
CONVERSATIONS_MULTISELECTOR_OPTION: (id: string) => `conversationMultiSelectorOption-${id}`,
SETTINGS_MODAL: 'settingsModal',
SYSTEM_PROMPT_MODAL: {
ID: 'systemPromptModal',
PROMPT_TEXT: 'systemPromptModalPromptText',
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ import useEvent from 'react-use/lib/useEvent';
import { css } from '@emotion/react';

import { OpenAiProviderType } from '@kbn/stack-connectors-plugin/common/gen_ai/constants';
import { Conversation } from '../../..';
import { useAssistantContext } from '../../assistant_context';
import { Conversation } from '../../../..';
import { useAssistantContext } from '../../../assistant_context';
import * as i18n from './translations';
import { DEFAULT_CONVERSATION_TITLE } from '../use_conversation/translations';
import { useConversation } from '../use_conversation';
import { SystemPromptSelectorOption } from '../prompt_editor/system_prompt/system_prompt_modal/system_prompt_selector/system_prompt_selector';
import { DEFAULT_CONVERSATION_TITLE } from '../../use_conversation/translations';
import { useConversation } from '../../use_conversation';
import { SystemPromptSelectorOption } from '../../prompt_editor/system_prompt/system_prompt_modal/system_prompt_selector/system_prompt_selector';

const isMac = navigator.platform.toLowerCase().indexOf('mac') >= 0;

interface Props {
conversationId?: string;
defaultConnectorId?: string;
defaultProvider?: OpenAiProviderType;
onSelectionChange?: (value: string) => void;
selectedConversationId: string | undefined;
setSelectedConversationId: React.Dispatch<React.SetStateAction<string>>;
shouldDisableKeyboardShortcut?: () => boolean;
isDisabled?: boolean;
}
Expand All @@ -56,17 +56,16 @@ export type ConversationSelectorOption = EuiComboBoxOptionOption<{

export const ConversationSelector: React.FC<Props> = React.memo(
({
conversationId = DEFAULT_CONVERSATION_TITLE,
selectedConversationId = DEFAULT_CONVERSATION_TITLE,
defaultConnectorId,
defaultProvider,
onSelectionChange,
setSelectedConversationId,
shouldDisableKeyboardShortcut = () => false,
isDisabled = false,
}) => {
const { allSystemPrompts } = useAssistantContext();

const { deleteConversation, setConversation } = useConversation();
const [selectedConversationId, setSelectedConversationId] = useState<string>(conversationId);

const { conversations } = useAssistantContext();
const conversationIds = useMemo(() => Object.keys(conversations), [conversations]);
Expand Down Expand Up @@ -112,7 +111,13 @@ export const ConversationSelector: React.FC<Props> = React.memo(
}
setSelectedConversationId(searchValue);
},
[allSystemPrompts, defaultConnectorId, defaultProvider, setConversation]
[
allSystemPrompts,
defaultConnectorId,
defaultProvider,
setConversation,
setSelectedConversationId,
]
);

// Callback for when user deletes a conversation
Expand All @@ -124,32 +129,29 @@ export const ConversationSelector: React.FC<Props> = React.memo(
setTimeout(() => {
deleteConversation(cId);
}, 0);
// onSystemPromptDeleted(cId);
},
[conversationIds, deleteConversation, selectedConversationId]
[conversationIds, deleteConversation, selectedConversationId, setSelectedConversationId]
);

const onChange = useCallback(
(newOptions: ConversationSelectorOption[]) => {
if (newOptions.length === 0) {
setSelectedOptions([]);
// handleSelectionChange([]);
} else if (conversationOptions.findIndex((o) => o.label === newOptions?.[0].label) !== -1) {
setSelectedConversationId(newOptions?.[0].label);
}
// setSelectedConversationId(value ?? DEFAULT_CONVERSATION_TITLE);
},
[conversationOptions]
[conversationOptions, setSelectedConversationId]
);

const onLeftArrowClick = useCallback(() => {
const prevId = getPreviousConversationId(conversationIds, selectedConversationId);
setSelectedConversationId(prevId);
}, [conversationIds, selectedConversationId]);
}, [conversationIds, selectedConversationId, setSelectedConversationId]);
const onRightArrowClick = useCallback(() => {
const nextId = getNextConversationId(conversationIds, selectedConversationId);
setSelectedConversationId(nextId);
}, [conversationIds, selectedConversationId]);
}, [conversationIds, selectedConversationId, setSelectedConversationId]);

// Register keyboard listener for quick conversation switching
const onKeyDown = useCallback(
Expand Down Expand Up @@ -186,9 +188,8 @@ export const ConversationSelector: React.FC<Props> = React.memo(
useEvent('keydown', onKeyDown);

useEffect(() => {
onSelectionChange?.(selectedConversationId);
setSelectedOptions(conversationOptions.filter((c) => c.label === selectedConversationId));
}, [conversationOptions, onSelectionChange, selectedConversationId]);
}, [conversationOptions, selectedConversationId]);

const renderOption: (
option: ConversationSelectorOption,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
export const SELECTED_CONVERSATION_LABEL = i18n.translate(
'xpack.elasticAssistant.assistant.conversationSelector.defaultConversationTitle',
{
defaultMessage: 'Selected conversation',
defaultMessage: 'Conversations',
}
);

Expand Down
Loading

0 comments on commit b323923

Please sign in to comment.