-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security solution] Generative AI Connector (#157228)
- Loading branch information
1 parent
2781645
commit 029eb31
Showing
45 changed files
with
2,094 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
[[gen-ai-action-type]] | ||
== Generative AI connector and action | ||
++++ | ||
<titleabbrev>Generative AI</titleabbrev> | ||
++++ | ||
|
||
The Generative AI connector uses https://github.com/axios/axios[axios] to send a POST request to an OpenAI provider, either OpenAI or Azure OpenAI. The connector uses the <<execute-connector-api,run connector API>> to send the request. | ||
|
||
[float] | ||
[[define-gen-ai-ui]] | ||
=== Create connectors in {kib} | ||
|
||
You can create connectors in *{stack-manage-app} > {connectors-ui}*. For example: | ||
|
||
[role="screenshot"] | ||
image::management/connectors/images/gen-ai-connector.png[Generative AI connector] | ||
|
||
[float] | ||
[[gen-ai-connector-configuration]] | ||
==== Connector configuration | ||
|
||
Generative AI connectors have the following configuration properties: | ||
|
||
Name:: The name of the connector. | ||
API Provider:: The OpenAI API provider, either OpenAI or Azure OpenAI. | ||
API URL:: The OpenAI request URL. | ||
API Key:: The OpenAI or Azure OpenAI API key for authentication. | ||
|
||
[float] | ||
[[preconfigured-gen-ai-configuration]] | ||
=== Create preconfigured connectors | ||
|
||
If you are running {kib} on-prem, you can define connectors by | ||
adding `xpack.actions.preconfigured` settings to your `kibana.yml` file. | ||
For example: | ||
|
||
[source,text] | ||
-- | ||
xpack.actions.preconfigured: | ||
my-gen-ai: | ||
name: preconfigured-gen-ai-connector-type | ||
actionTypeId: .gen-ai | ||
config: | ||
apiUrl: https://api.openai.com/v1/chat/completions | ||
apiProvider: 'Azure OpenAI' | ||
secrets: | ||
apiKey: superlongapikey | ||
-- | ||
|
||
Config defines information for the connector type. | ||
|
||
`apiProvider`:: A string that corresponds to *OpenAI API Provider*. | ||
`apiUrl`:: A URL string that corresponds to the *OpenAI API URL*. | ||
|
||
Secrets defines sensitive information for the connector type. | ||
|
||
`apiKey`:: A string that corresponds to *OpenAI API Key*. | ||
|
||
[float] | ||
[[gen-ai-action-configuration]] | ||
=== Test connectors | ||
|
||
You can test connectors with the <<execute-connector-api,run connector API>> or | ||
as you're creating or editing the connector in {kib}. For example: | ||
|
||
[role="screenshot"] | ||
image::management/connectors/images/gen-ai-params-test.png[Generative AI params test] | ||
|
||
The Generative AI actions have the following configuration properties. | ||
|
||
Body:: A JSON payload sent to the OpenAI API URL. For example: | ||
+ | ||
[source,text] | ||
-- | ||
{ | ||
"model": "gpt-3.5-turbo", | ||
"messages": [ | ||
{ | ||
"role": "user", | ||
"content": "Hello world" | ||
} | ||
] | ||
} | ||
-- | ||
[float] | ||
[[gen-ai-connector-networking-configuration]] | ||
=== Connector networking configuration | ||
|
||
Use the <<action-settings, Action configuration settings>> to customize connector networking configurations, such as proxies, certificates, or TLS settings. You can set configurations that apply to all your connectors or use `xpack.actions.customHostSettings` to set per-host configurations. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/actions/server/sub_action_framework/helpers/validators.test.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,32 @@ | ||
/* | ||
* 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 { assertURL } from './validators'; | ||
|
||
describe('Validators', () => { | ||
describe('assertURL function', () => { | ||
it('valid URL with a valid protocol and hostname does not throw an error', () => { | ||
expect(() => assertURL('https://www.example.com')).not.toThrow(); | ||
}); | ||
|
||
it('invalid URL throws an error with a relevant message', () => { | ||
expect(() => assertURL('invalidurl')).toThrowError('Invalid URL'); | ||
}); | ||
|
||
it('URL with an invalid protocol throws an error with a relevant message', () => { | ||
expect(() => assertURL('ftp://www.example.com')).toThrowError('Invalid protocol'); | ||
}); | ||
|
||
it('function handles case sensitivity of protocols correctly', () => { | ||
expect(() => assertURL('hTtPs://www.example.com')).not.toThrow(); | ||
}); | ||
|
||
it('function handles URLs with query parameters and fragment identifiers correctly', () => { | ||
expect(() => assertURL('https://www.example.com/path?query=value#fragment')).not.toThrow(); | ||
}); | ||
}); | ||
}); |
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
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/stack_connectors/common/gen_ai/constants.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,24 @@ | ||
/* | ||
* 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 GEN_AI_TITLE = i18n.translate( | ||
'xpack.stackConnectors.components.genAi.connectorTypeTitle', | ||
{ | ||
defaultMessage: 'Generative AI', | ||
} | ||
); | ||
export const GEN_AI_CONNECTOR_ID = '.gen-ai'; | ||
export enum SUB_ACTION { | ||
RUN = 'run', | ||
TEST = 'test', | ||
} | ||
export enum OpenAiProviderType { | ||
OpenAi = 'OpenAI', | ||
AzureAi = 'Azure OpenAI', | ||
} |
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,22 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
|
||
// Connector schema | ||
export const GenAiConfigSchema = schema.object({ | ||
apiProvider: schema.string(), | ||
apiUrl: schema.string(), | ||
}); | ||
|
||
export const GenAiSecretsSchema = schema.object({ apiKey: schema.string() }); | ||
|
||
// Run action schema | ||
export const GenAiRunActionParamsSchema = schema.object({ | ||
body: schema.string(), | ||
}); | ||
export const GenAiRunActionResponseSchema = schema.object({}, { unknowns: 'ignore' }); |
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,19 @@ | ||
/* | ||
* 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 { TypeOf } from '@kbn/config-schema'; | ||
import { | ||
GenAiConfigSchema, | ||
GenAiSecretsSchema, | ||
GenAiRunActionParamsSchema, | ||
GenAiRunActionResponseSchema, | ||
} from './schema'; | ||
|
||
export type GenAiConfig = TypeOf<typeof GenAiConfigSchema>; | ||
export type GenAiSecrets = TypeOf<typeof GenAiSecretsSchema>; | ||
export type GenAiRunActionParams = TypeOf<typeof GenAiRunActionParamsSchema>; | ||
export type GenAiRunActionResponse = TypeOf<typeof GenAiRunActionResponseSchema>; |
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 |
---|---|---|
|
@@ -14,6 +14,9 @@ | |
"actions", | ||
"esUiShared", | ||
"triggersActionsUi" | ||
], | ||
"extraPublicDirs": [ | ||
"public/common" | ||
] | ||
} | ||
} |
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,11 @@ | ||
/* | ||
* 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 GenAiLogo from '../connector_types/gen_ai/logo'; | ||
|
||
export { GEN_AI_CONNECTOR_ID } from '../../common/gen_ai/constants'; | ||
export { GenAiLogo }; |
Oops, something went wrong.