-
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.
Merge branch 'elastic:main' into deprecate_csp_rule
- Loading branch information
Showing
15 changed files
with
259 additions
and
4 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
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
58 changes: 58 additions & 0 deletions
58
...rprise_search_content/components/search_index/pipelines/ml_inference/inference_config.tsx
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,58 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { useValues } from 'kea'; | ||
|
||
import { EuiSpacer, EuiText } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { | ||
getMlModelTypesForModelConfig, | ||
SUPPORTED_PYTORCH_TASKS, | ||
} from '../../../../../../../common/ml_inference_pipeline'; | ||
import { getMLType } from '../../../shared/ml_inference/utils'; | ||
|
||
import { MLInferenceLogic } from './ml_inference_logic'; | ||
import { ZeroShotClassificationInferenceConfiguration } from './zero_shot_inference_configuration'; | ||
|
||
export const InferenceConfiguration: React.FC = () => { | ||
const { | ||
addInferencePipelineModal: { configuration }, | ||
selectedMLModel, | ||
} = useValues(MLInferenceLogic); | ||
if (!selectedMLModel || configuration.existingPipeline) return null; | ||
const modelType = getMLType(getMlModelTypesForModelConfig(selectedMLModel)); | ||
switch (modelType) { | ||
case SUPPORTED_PYTORCH_TASKS.ZERO_SHOT_CLASSIFICATION: | ||
return ( | ||
<InferenceConfigurationWrapper> | ||
<ZeroShotClassificationInferenceConfiguration /> | ||
</InferenceConfigurationWrapper> | ||
); | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
const InferenceConfigurationWrapper: React.FC = ({ children }) => { | ||
return ( | ||
<> | ||
<EuiSpacer /> | ||
<EuiText> | ||
<h4> | ||
{i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.pipelines.addInferencePipelineModal.steps.configure.inference.title', | ||
{ defaultMessage: 'Inference Configuration' } | ||
)} | ||
</h4> | ||
</EuiText> | ||
{children} | ||
</> | ||
); | ||
}; |
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
89 changes: 89 additions & 0 deletions
89
...tent/components/search_index/pipelines/ml_inference/zero_shot_inference_configuration.tsx
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 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { useValues, useActions } from 'kea'; | ||
|
||
import { EuiComboBox, EuiFormRow, EuiSpacer } from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { IndexViewLogic } from '../../index_view_logic'; | ||
|
||
import { MLInferenceLogic } from './ml_inference_logic'; | ||
|
||
type LabelOptions = Array<{ label: string }>; | ||
|
||
export const ZeroShotClassificationInferenceConfiguration: React.FC = () => { | ||
const { ingestionMethod } = useValues(IndexViewLogic); | ||
const { | ||
addInferencePipelineModal: { configuration }, | ||
} = useValues(MLInferenceLogic); | ||
const { setInferencePipelineConfiguration } = useActions(MLInferenceLogic); | ||
|
||
const zeroShotLabels = configuration?.inferenceConfig?.zero_shot_classification?.labels ?? []; | ||
const labelOptions = zeroShotLabels.map((label) => ({ label })); | ||
|
||
const onLabelChange = (selectedLabels: LabelOptions) => { | ||
const inferenceConfig = | ||
selectedLabels.length === 0 | ||
? undefined | ||
: { | ||
zero_shot_classification: { | ||
...(configuration?.inferenceConfig?.zero_shot_classification ?? {}), | ||
labels: selectedLabels.map(({ label }) => label), | ||
}, | ||
}; | ||
setInferencePipelineConfiguration({ | ||
...configuration, | ||
inferenceConfig, | ||
}); | ||
}; | ||
const onCreateLabel = (labelValue: string, labels: LabelOptions = []) => { | ||
const normalizedLabelValue = labelValue.trim(); | ||
if (!normalizedLabelValue) return; | ||
|
||
const existingLabel = labels.find((label) => label.label === normalizedLabelValue); | ||
if (existingLabel) return; | ||
setInferencePipelineConfiguration({ | ||
...configuration, | ||
inferenceConfig: { | ||
zero_shot_classification: { | ||
...(configuration?.inferenceConfig?.zero_shot_classification ?? {}), | ||
labels: [...zeroShotLabels, normalizedLabelValue], | ||
}, | ||
}, | ||
}); | ||
}; | ||
return ( | ||
<> | ||
<EuiSpacer size="s" /> | ||
<EuiFormRow | ||
label={i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.pipelines.addInferencePipelineModal.steps.configure.inference.zeroShot.labels.label', | ||
{ defaultMessage: 'Class labels' } | ||
)} | ||
fullWidth | ||
> | ||
<EuiComboBox | ||
fullWidth | ||
data-telemetry-id={`entSearchContent-${ingestionMethod}-pipelines-configureInferencePipeline-zeroShot-labels`} | ||
placeholder={i18n.translate( | ||
'xpack.enterpriseSearch.content.indices.pipelines.addInferencePipelineModal.steps.configure.inference.zeroShot.labels.placeholder', | ||
{ defaultMessage: 'Create labels' } | ||
)} | ||
options={labelOptions} | ||
selectedOptions={labelOptions} | ||
onChange={onLabelChange} | ||
onCreateOption={onCreateLabel} | ||
noSuggestions | ||
/> | ||
</EuiFormRow> | ||
</> | ||
); | ||
}; |
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
Oops, something went wrong.