Fix double-prefixing of 'ml.inference'

This commit is contained in:
Sean Story 2023-04-14 13:28:59 -05:00
parent 952f57ae72
commit 5c20206ebf
2 changed files with 42 additions and 2 deletions

View file

@ -232,6 +232,41 @@ describe('generateMlInferencePipelineBody lib function', () => {
);
});
it('should return something that safely removes redundant prefixes', () => {
const mockTextClassificationModel: MlTrainedModelConfig = {
...mockModel,
...{ inference_config: { text_classification: {} } },
};
const actual: MlInferencePipeline = generateMlInferencePipelineBody({
description: 'my-description',
model: mockTextClassificationModel,
pipelineName: 'my-pipeline',
fieldMappings: [{ sourceField: 'my-source-field', targetField: 'ml.inference.my-source-field_expanded' }],
});
expect(actual).toEqual(
expect.objectContaining({
description: expect.any(String),
processors: expect.arrayContaining([
expect.objectContaining({
remove: {
field: 'ml.inference.my-source-field_expanded',
ignore_missing: true,
},
}),
expect.objectContaining({
inference: expect.objectContaining({
field_map: {
'my-source-field': 'MODEL_INPUT_FIELD',
},
target_field: 'ml.inference.my-source-field_expanded',
}),
}),
]),
})
);
});
it('should return something expected with multiple fields', () => {
const actual: MlInferencePipeline = generateMlInferencePipelineBody({
description: 'my-description',

View file

@ -224,7 +224,9 @@ export const parseMlInferenceParametersFromPipeline = (
return null;
}
return {
destination_field: inferenceProcessor.target_field?.replace('ml.inference.', ''),
destination_field: inferenceProcessor.target_field
? stripMlInferencePrefix(inferenceProcessor.target_field)
: inferenceProcessor.target_field,
model_id: inferenceProcessor.model_id,
pipeline_name: name,
source_field: sourceField,
@ -258,4 +260,7 @@ export const parseModelStateFromStats = (
export const parseModelStateReasonFromStats = (trainedModelStats?: Partial<MlTrainedModelStats>) =>
trainedModelStats?.deployment_stats?.reason;
export const getMlInferencePrefixedFieldName = (fieldName: string) => `ml.inference.${fieldName}`;
export const getMlInferencePrefixedFieldName = (fieldName: string) =>
`ml.inference.${stripMlInferencePrefix(fieldName)}`; // Strip first, then prepend, to prevent against double-prepending
const stripMlInferencePrefix = (fieldName: string) => fieldName.replace('ml.inference.', '');