Skip to content

Commit

Permalink
[Security AI Assistant] Removed connectorTypeTitle from the Conversat…
Browse files Browse the repository at this point in the history
…ion API required params. Replaced usage replaced with actionsClient on server and API call on the client (#179117)

Current PR is fixing bug mentioned
[here](https://github.com/elastic/kibana/pull/179007/files#pullrequestreview-1947890025)
and reducing `connectorTypeTitle`/`llmType` params for AI assistant
APIs.

Streaming is working as it was before:


https://github.com/elastic/kibana/assets/55110838/ff7c2ae8-288f-4cba-bb43-e45367845667
  • Loading branch information
YulNaumenko authored Mar 22, 2024
1 parent b41d423 commit 175b59b
Show file tree
Hide file tree
Showing 61 changed files with 123 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const ExecuteConnectorRequestBody = z.object({
isEnabledRAGAlerts: z.boolean().optional(),
replacements: z.array(Replacement),
size: z.number().optional(),
llmType: z.enum(['bedrock', 'openai']),
});
export type ExecuteConnectorRequestBodyInput = z.input<typeof ExecuteConnectorRequestBody>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ paths:
type: object
required:
- params
- llmType
- replacements
- subAction
properties:
Expand Down Expand Up @@ -61,11 +60,6 @@ paths:
$ref: '../conversations/common_attributes.schema.yaml#/components/schemas/Replacement'
size:
type: number
llmType:
type: string
enum:
- bedrock
- openai
responses:
'200':
description: Successful response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ export const ApiConfig = z.object({
* connector Id
*/
connectorId: z.string(),
/**
* connector Type Title
*/
connectorTypeTitle: z.string(),
/**
* defaultSystemPromptId
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,10 @@ components:
type: object
required:
- connectorId
- connectorTypeTitle
properties:
connectorId:
type: string
description: connector Id
connectorTypeTitle:
type: string
description: connector Type Title
defaultSystemPromptId:
type: string
description: defaultSystemPromptId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { IToasts } from '@kbn/core-notifications-browser';
const conversation1 = {
id: 'conversation1',
title: 'Conversation 1',
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
category: 'default',
messages: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const mockHttp = {

const apiConfig: Conversation['apiConfig'] = {
connectorId: 'foo',
connectorTypeTitle: 'OpenAI',
model: 'gpt-4',
provider: OpenAiProviderType.OpenAi,
};
Expand All @@ -53,7 +52,7 @@ describe('API tests', () => {
expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false,"llmType":"openai"}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":false}',
headers: { 'Content-Type': 'application/json' },
method: 'POST',
signal: undefined,
Expand All @@ -73,7 +72,7 @@ describe('API tests', () => {
expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeStream","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false,"llmType":"openai"}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeStream","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false}',
method: 'POST',
asResponse: true,
rawResponse: true,
Expand All @@ -99,7 +98,7 @@ describe('API tests', () => {
expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[{"uuid":"auuid","value":"real.hostname"}],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":true,"llmType":"openai","alertsIndexPattern":".alerts-security.alerts-default","allow":["a","b","c"],"allowReplacement":["b","c"],"size":30}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[{"uuid":"auuid","value":"real.hostname"}],"isEnabledKnowledgeBase":true,"isEnabledRAGAlerts":true,"alertsIndexPattern":".alerts-security.alerts-default","allow":["a","b","c"],"allowReplacement":["b","c"],"size":30}',
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -122,7 +121,7 @@ describe('API tests', () => {
expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false,"llmType":"openai"}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":false}',
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -145,7 +144,7 @@ describe('API tests', () => {
expect(mockHttp.fetch).toHaveBeenCalledWith(
'/internal/elastic_assistant/actions/connector/foo/_execute',
{
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true,"llmType":"openai"}',
body: '{"model":"gpt-4","message":"This is a test","subAction":"invokeAI","conversationId":"test","replacements":[],"isEnabledKnowledgeBase":false,"isEnabledRAGAlerts":true}',
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { HttpSetup } from '@kbn/core/public';
import { IHttpFetchError } from '@kbn/core-http-browser';
import { ApiConfig, Replacement } from '@kbn/elastic-assistant-common';
import { API_ERROR } from '../translations';
import { getOptionalRequestParams, llmTypeDictionary } from '../helpers';
import { getOptionalRequestParams } from '../helpers';
export * from './conversations';

export interface FetchConnectorExecuteAction {
Expand Down Expand Up @@ -53,7 +53,6 @@ export const fetchConnectorExecuteAction = async ({
signal,
size,
}: FetchConnectorExecuteAction): Promise<FetchConnectorExecuteResponse> => {
const llmType = llmTypeDictionary[apiConfig.connectorTypeTitle];
// TODO: Remove in part 3 of streaming work for security solution
// tracked here: https://github.com/elastic/security-team/issues/7363
// In part 3 I will make enhancements to langchain to introduce streaming
Expand All @@ -76,7 +75,6 @@ export const fetchConnectorExecuteAction = async ({
replacements,
isEnabledKnowledgeBase,
isEnabledRAGAlerts,
llmType,
...optionalRequestParams,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export const ConversationSelector: React.FC<Props> = React.memo(
? {
apiConfig: {
connectorId: defaultConnector.id,
connectorTypeTitle: defaultConnector.connectorTypeTitle,
provider: defaultConnector.apiProvider,
defaultSystemPromptId: defaultSystemPrompt?.id,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ const mockConnector = {
id: 'cool-id-bro',
actionTypeId: '.gen-ai',
name: 'cool name',
connectorTypeTitle: 'OpenAI',
};
jest.mock('../../../connectorland/connector_selector', () => ({
// @ts-ignore
Expand Down Expand Up @@ -231,7 +230,6 @@ describe('ConversationSettings', () => {
...mockConvos[welcomeConvo.title],
apiConfig: {
connectorId: mockConnector.id,
connectorTypeTitle: 'OpenAI',
model: undefined,
provider: undefined,
},
Expand All @@ -243,7 +241,6 @@ describe('ConversationSettings', () => {
...mockConvos[welcomeConvo.title],
apiConfig: {
connectorId: mockConnector.id,
connectorTypeTitle: 'OpenAI',
model: undefined,
provider: undefined,
},
Expand Down Expand Up @@ -331,7 +328,6 @@ describe('ConversationSettings', () => {
id: 'not-the-right-id',
apiConfig: {
connectorId: mockConnector.id,
connectorTypeTitle: 'OpenAI',
model: undefined,
provider: undefined,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface ConversationSettingsProps {
*/
export const ConversationSettings: React.FC<ConversationSettingsProps> = React.memo(
({
actionTypeRegistry,
allSystemPrompts,
defaultConnector,
selectedConversation,
Expand All @@ -68,7 +67,6 @@ export const ConversationSettings: React.FC<ConversationSettingsProps> = React.m
}, [allSystemPrompts, selectedConversation]);

const { data: connectors, isSuccess: areConnectorsFetched } = useLoadConnectors({
actionTypeRegistry,
http,
});

Expand All @@ -89,7 +87,6 @@ export const ConversationSettings: React.FC<ConversationSettingsProps> = React.m
? {
apiConfig: {
connectorId: defaultConnector.id,
connectorTypeTitle: defaultConnector.connectorTypeTitle,
provider: defaultConnector.apiProvider,
defaultSystemPromptId: defaultSystemPrompt?.id,
},
Expand Down Expand Up @@ -231,7 +228,6 @@ export const ConversationSettings: React.FC<ConversationSettingsProps> = React.m
apiConfig: {
...selectedConversation.apiConfig,
connectorId: connector.id,
connectorTypeTitle: connector.connectorTypeTitle,
provider: config?.apiProvider,
model: config?.defaultModel,
},
Expand All @@ -257,7 +253,6 @@ export const ConversationSettings: React.FC<ConversationSettingsProps> = React.m
: {}
).apiConfig ?? {}),
connectorId: connector?.id,
connectorTypeTitle: connector?.connectorTypeTitle,
provider: config?.apiProvider,
model: config?.defaultModel,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('helpers', () => {
category: 'assistant',
theme: {},
messages: [],
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
title: 'conversation_id',
};
Expand All @@ -46,7 +46,7 @@ describe('helpers', () => {
},
},
],
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
category: 'assistant',
title: 'conversation_id',
Expand All @@ -60,7 +60,7 @@ describe('helpers', () => {
id: 'conversation_id',
title: 'conversation_id',
messages: enterpriseMessaging,
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
category: 'assistant',
};
Expand All @@ -86,7 +86,7 @@ describe('helpers', () => {
},
},
],
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
};
const result = getBlockBotConversation(conversation, isAssistantEnabled);
Expand All @@ -102,7 +102,7 @@ describe('helpers', () => {
title: 'conversation_id',
category: 'assistant',
messages: [],
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
};
const result = getBlockBotConversation(conversation, isAssistantEnabled);
Expand All @@ -124,7 +124,7 @@ describe('helpers', () => {
},
},
],
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
};
const result = getBlockBotConversation(conversation, isAssistantEnabled);
Expand All @@ -151,7 +151,6 @@ describe('helpers', () => {
const connectors: AIConnector[] = [
{
actionTypeId: '.gen-ai',
connectorTypeTitle: 'OpenAI',
isPreconfigured: false,
isDeprecated: false,
referencedByCount: 0,
Expand All @@ -175,7 +174,6 @@ describe('helpers', () => {
const connectors: AIConnector[] = [
{
actionTypeId: '.gen-ai',
connectorTypeTitle: 'OpenAI',
isPreconfigured: false,
isDeprecated: false,
referencedByCount: 0,
Expand All @@ -191,7 +189,6 @@ describe('helpers', () => {
},
{
actionTypeId: '.gen-ai',
connectorTypeTitle: 'OpenAI',
isPreconfigured: false,
isDeprecated: false,
referencedByCount: 0,
Expand Down Expand Up @@ -268,7 +265,7 @@ describe('helpers', () => {
messages,
category: 'assistant',
theme: {},
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
};
const baseConversations = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,3 @@ export const getOptionalRequestParams = ({
...optionalSize,
};
};

export const llmTypeDictionary: Record<string, string> = {
'Amazon Bedrock': 'bedrock',
'Azure OpenAI': 'openai',
OpenAI: 'openai',
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ const mockData = {
title: 'Welcome',
category: 'assistant',
messages: [],
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
},
'electric sheep': {
id: 'electric sheep id',
category: 'assistant',
title: 'electric sheep',
messages: [],
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
},
};
Expand Down Expand Up @@ -169,7 +169,7 @@ describe('Assistant', () => {
expect(chatSendSpy).toHaveBeenLastCalledWith(
expect.objectContaining({
currentConversation: {
apiConfig: { connectorId: '123', connectorTypeTitle: 'OpenAI' },
apiConfig: { connectorId: '123' },
replacements: [],
category: 'assistant',
id: 'Welcome Id',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ const AssistantComponent: React.FC<Props> = ({
setConversationTitle,
}) => {
const {
actionTypeRegistry,
assistantTelemetry,
augmentMessageCodeBlocks,
assistantAvailability: { isAssistantEnabled },
Expand Down Expand Up @@ -136,7 +135,6 @@ const AssistantComponent: React.FC<Props> = ({

// Connector details
const { data: connectors, isSuccess: areConnectorsFetched } = useLoadConnectors({
actionTypeRegistry,
http,
});
const defaultConnector = useMemo(() => getDefaultConnector(connectors), [connectors]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const BASE_CONVERSATION: Conversation = {
...WELCOME_CONVERSATION,
apiConfig: {
connectorId: '123',
connectorTypeTitle: 'OpenAI',
defaultSystemPromptId: mockSystemPrompt.id,
},
};
Expand Down Expand Up @@ -377,7 +376,6 @@ describe('SystemPrompt', () => {
category: 'assistant',
apiConfig: {
connectorId: '123',
connectorTypeTitle: 'OpenAI',
defaultSystemPromptId: undefined,
},
title: 'second',
Expand Down Expand Up @@ -462,7 +460,6 @@ describe('SystemPrompt', () => {
...secondMockConversation,
apiConfig: {
connectorId: '123',
connectorTypeTitle: 'OpenAI',
defaultSystemPromptId: mockSystemPrompt.id,
},
},
Expand Down
Loading

0 comments on commit 175b59b

Please sign in to comment.