forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[inference] Add support for inference connectors (elastic#204541)
## Summary ~Depends on~ elastic#200249 merged! Fix elastic#199082 - Add support for the `inference` stack connectors to the `inference` plugin (everything is inference) - Adapt the o11y assistant to use the `inference-common` utilities for connector filtering / compat checking ## How to test **1. Starts ES with the unified completion feature flag** ```sh yarn es snapshot --license trial ES_JAVA_OPTS="-Des.inference_unified_feature_flag_enabled=true" ``` **2. Enable the inference connector for Kibana** In the Kibana config file: ```yaml xpack.stack_connectors.enableExperimental: ['inferenceConnectorOn'] ``` **3. Start Dev Kibana** ```sh node scripts/kibana --dev --no-base-path ``` **4. Create an inference connector** Go to `http://localhost:5601/app/management/insightsAndAlerting/triggersActionsConnectors/connectors`, create an inference connector - Type: `AI connector` then - Service: `OpenAI` - API Key: Gwzk... Kidding, please ping someone - Model ID: `gpt-4o` - Task type: `completion` -> save **5. test the o11y assistant** Use the assistant as you would do for any other connector (just make sure the inference connector is selected as the one being used) and do your testing. --------- Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
4fa7b78
commit 3dcae51
Showing
37 changed files
with
894 additions
and
273 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
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
91 changes: 91 additions & 0 deletions
91
x-pack/platform/packages/shared/ai-infra/inference-common/src/connectors.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,91 @@ | ||
/* | ||
* 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 { | ||
InferenceConnectorType, | ||
isSupportedConnectorType, | ||
isSupportedConnector, | ||
RawConnector, | ||
COMPLETION_TASK_TYPE, | ||
} from './connectors'; | ||
|
||
const createRawConnector = (parts: Partial<RawConnector>): RawConnector => { | ||
return { | ||
id: 'id', | ||
actionTypeId: 'connector-type', | ||
name: 'some connector', | ||
config: {}, | ||
...parts, | ||
}; | ||
}; | ||
|
||
describe('isSupportedConnectorType', () => { | ||
it('returns true for supported connector types', () => { | ||
expect(isSupportedConnectorType(InferenceConnectorType.OpenAI)).toBe(true); | ||
expect(isSupportedConnectorType(InferenceConnectorType.Bedrock)).toBe(true); | ||
expect(isSupportedConnectorType(InferenceConnectorType.Gemini)).toBe(true); | ||
expect(isSupportedConnectorType(InferenceConnectorType.Inference)).toBe(true); | ||
}); | ||
it('returns false for unsupported connector types', () => { | ||
expect(isSupportedConnectorType('anything-else')).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('isSupportedConnector', () => { | ||
// TODO | ||
|
||
it('returns true for OpenAI connectors', () => { | ||
expect( | ||
isSupportedConnector(createRawConnector({ actionTypeId: InferenceConnectorType.OpenAI })) | ||
).toBe(true); | ||
}); | ||
|
||
it('returns true for Bedrock connectors', () => { | ||
expect( | ||
isSupportedConnector(createRawConnector({ actionTypeId: InferenceConnectorType.Bedrock })) | ||
).toBe(true); | ||
}); | ||
|
||
it('returns true for Gemini connectors', () => { | ||
expect( | ||
isSupportedConnector(createRawConnector({ actionTypeId: InferenceConnectorType.Gemini })) | ||
).toBe(true); | ||
}); | ||
|
||
it('returns true for OpenAI connectors with the right taskType', () => { | ||
expect( | ||
isSupportedConnector( | ||
createRawConnector({ | ||
actionTypeId: InferenceConnectorType.Inference, | ||
config: { taskType: COMPLETION_TASK_TYPE }, | ||
}) | ||
) | ||
).toBe(true); | ||
}); | ||
|
||
it('returns false for OpenAI connectors with a bad taskType', () => { | ||
expect( | ||
isSupportedConnector( | ||
createRawConnector({ | ||
actionTypeId: InferenceConnectorType.Inference, | ||
config: { taskType: 'embeddings' }, | ||
}) | ||
) | ||
).toBe(false); | ||
}); | ||
|
||
it('returns false for OpenAI connectors without taskType', () => { | ||
expect( | ||
isSupportedConnector( | ||
createRawConnector({ | ||
actionTypeId: InferenceConnectorType.Inference, | ||
config: {}, | ||
}) | ||
) | ||
).toBe(false); | ||
}); | ||
}); |
76 changes: 76 additions & 0 deletions
76
x-pack/platform/packages/shared/ai-infra/inference-common/src/connectors.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,76 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* The list of connector types that can be used with the inference APIs | ||
*/ | ||
export enum InferenceConnectorType { | ||
OpenAI = '.gen-ai', | ||
Bedrock = '.bedrock', | ||
Gemini = '.gemini', | ||
Inference = '.inference', | ||
} | ||
|
||
export const COMPLETION_TASK_TYPE = 'completion'; | ||
|
||
const allSupportedConnectorTypes = Object.values(InferenceConnectorType); | ||
|
||
export interface InferenceConnector { | ||
type: InferenceConnectorType; | ||
name: string; | ||
connectorId: string; | ||
} | ||
|
||
/** | ||
* Checks if a given connector type is compatible for inference. | ||
* | ||
* Note: this check is not sufficient to assert if a given connector can be | ||
* used for inference, as `.inference` connectors need additional check logic. | ||
* Please use `isSupportedConnector` instead when possible. | ||
*/ | ||
export function isSupportedConnectorType(id: string): id is InferenceConnectorType { | ||
return allSupportedConnectorTypes.includes(id as InferenceConnectorType); | ||
} | ||
|
||
/** | ||
* Checks if a given connector is compatible for inference. | ||
* | ||
* A connector is compatible if: | ||
* 1. its type is in the list of allowed types | ||
* 2. for inference connectors, if its taskType is "completion" | ||
*/ | ||
export function isSupportedConnector(connector: RawConnector): connector is RawInferenceConnector { | ||
if (!isSupportedConnectorType(connector.actionTypeId)) { | ||
return false; | ||
} | ||
if (connector.actionTypeId === InferenceConnectorType.Inference) { | ||
const config = connector.config ?? {}; | ||
if (config.taskType !== COMPLETION_TASK_TYPE) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
/** | ||
* Connector types are living in the actions plugin and we can't afford | ||
* having dependencies from this package to some mid-level plugin, | ||
* so we're just using our own connector mixin type. | ||
*/ | ||
export interface RawConnector { | ||
id: string; | ||
actionTypeId: string; | ||
name: string; | ||
config?: Record<string, any>; | ||
} | ||
|
||
interface RawInferenceConnector { | ||
id: string; | ||
actionTypeId: InferenceConnectorType; | ||
name: string; | ||
config?: Record<string, any>; | ||
} |
24 changes: 0 additions & 24 deletions
24
x-pack/platform/plugins/shared/inference/common/connectors.ts
This file was deleted.
Oops, something went wrong.
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
8 changes: 8 additions & 0 deletions
8
x-pack/platform/plugins/shared/inference/server/chat_complete/adapters/inference/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { inferenceAdapter } from './inference_adapter'; |
Oops, something went wrong.