Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Support different input transform types #501

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import {
InputMapEntry,
MapEntry,
PromptPreset,
QueryPreset,
Expand Down Expand Up @@ -468,6 +469,12 @@ export enum TRANSFORM_CONTEXT {
INPUT = 'input',
OUTPUT = 'output',
}
export enum TRANSFORM_TYPE {
STRING = 'String',
FIELD = 'Field',
EXPRESSION = 'Expression',
TEMPLATE = 'Template',
}
export const START_FROM_SCRATCH_WORKFLOW_NAME = 'Start From Scratch';
export const DEFAULT_NEW_WORKFLOW_NAME = 'new_workflow';
export const DEFAULT_NEW_WORKFLOW_DESCRIPTION = 'My new workflow';
Expand All @@ -490,9 +497,17 @@ export enum SORT_ORDER {
export const MAX_DOCS = 1000;
export const MAX_STRING_LENGTH = 100;
export const MAX_JSON_STRING_LENGTH = 10000;
export const MAX_TEMPLATE_STRING_LENGTH = 10000;
export const MAX_WORKFLOW_NAME_TO_DISPLAY = 40;
export const WORKFLOW_NAME_REGEXP = RegExp('^[a-zA-Z0-9_-]*$');
export const EMPTY_MAP_ENTRY = { key: '', value: '' } as MapEntry;
export const EMPTY_INPUT_MAP_ENTRY = {
key: '',
value: {
transformType: '' as TRANSFORM_TYPE,
value: '',
},
} as InputMapEntry;
export const MODEL_OUTPUT_SCHEMA_NESTED_PATH =
'output.properties.inference_results.items.properties.output.items.properties.dataAsMap.properties';
export const MODEL_OUTPUT_SCHEMA_FULL_PATH = 'output.properties';
Expand Down
38 changes: 36 additions & 2 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
COMPONENT_CLASS,
PROCESSOR_TYPE,
PROMPT_FIELD,
TRANSFORM_TYPE,
WORKFLOW_TYPE,
} from './constants';

Expand All @@ -35,7 +36,8 @@ export type ConfigFieldType =
| 'map'
| 'mapArray'
| 'boolean'
| 'number';
| 'number'
| 'inputMapArray';

export type ConfigFieldValue = string | {};

Expand Down Expand Up @@ -100,6 +102,28 @@ export type MapFormValue = MapEntry[];

export type MapArrayFormValue = MapFormValue[];

export type TemplateVar = {
name: string;
transform: string;
};

export type Transform = {
transformType: TRANSFORM_TYPE;
value: string;
// Templates may persist their own set of nested transforms
// to be dynamically injected into the template
nestedVars?: TemplateVar[];
};

export type InputMapEntry = {
key: string;
value: Transform;
};

export type InputMapFormValue = InputMapEntry[];

export type InputMapArrayFormValue = InputMapFormValue[];

export type WorkflowFormValues = {
ingest: FormikValues;
search: FormikValues;
Expand All @@ -124,7 +148,7 @@ export type RequestSchema = WorkflowSchema;

// Form / schema interfaces for the input transform sub-form
export type InputTransformFormValues = {
input_map: MapArrayFormValue;
input_map: InputMapArrayFormValue;
one_to_one: ConfigFieldValue;
};
export type InputTransformSchema = WorkflowSchema;
Expand All @@ -136,6 +160,16 @@ export type OutputTransformFormValues = {
};
export type OutputTransformSchema = WorkflowSchema;

// Form / schema interfaces for the template sub-form
export type TemplateFormValues = Omit<Transform, 'transformType'>;
export type TemplateSchema = WorkflowSchema;

// Form / schema interfaces for the expression/transform sub-form
export type ExpressionFormValues = {
expression: string;
};
export type ExpressionSchema = WorkflowSchema;

/**
********** WORKSPACE TYPES/INTERFACES **********
*/
Expand Down
2 changes: 1 addition & 1 deletion public/configs/ml_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export abstract class MLProcessor extends Processor {
},
{
id: 'input_map',
type: 'mapArray',
type: 'inputMapArray',
},
{
id: 'output_map',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export { MapArrayField } from './map_array_field';
export { BooleanField } from './boolean_field';
export { SelectField } from './select_field';
export { NumberField } from './number_field';
export { SelectWithCustomOptions } from './select_with_custom_options';
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export function MapField(props: MapFieldProps) {
placeholder={
props.keyPlaceholder || 'Input'
}
allowCreate={true}
/>
) : (
<TextField
Expand Down Expand Up @@ -221,6 +222,7 @@ export function MapField(props: MapFieldProps) {
placeholder={
props.valuePlaceholder || 'Output'
}
allowCreate={true}
/>
) : (
<TextField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface SelectWithCustomOptionsProps {
fieldPath: string;
placeholder: string;
options: { label: string }[];
allowCreate?: boolean;
onChange?: () => void;
}

/**
Expand All @@ -31,6 +33,8 @@ export function SelectWithCustomOptions(props: SelectWithCustomOptionsProps) {
const formValue = getIn(values, props.fieldPath);
if (!isEmpty(formValue)) {
setSelectedOption([{ label: formValue }]);
} else {
setSelectedOption([]);
}
}, [getIn(values, props.fieldPath)]);

Expand Down Expand Up @@ -76,9 +80,14 @@ export function SelectWithCustomOptions(props: SelectWithCustomOptionsProps) {
onChange={(options) => {
setFieldTouched(props.fieldPath, true);
setFieldValue(props.fieldPath, get(options, '0.label'));
if (props.onChange) {
props.onChange();
}
}}
onCreateOption={onCreateOption}
customOptionText="Add {searchValue} as a custom option"
onCreateOption={props.allowCreate ? onCreateOption : undefined}
customOptionText={
props.allowCreate ? 'Add {searchValue} as a custom option' : undefined
}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EuiText,
EuiToolTip,
EuiSmallButton,
EuiIconTip,
} from '@elastic/eui';
import {
IProcessorConfig,
Expand All @@ -31,8 +32,15 @@ import {
MapArrayFormValue,
MapEntry,
MapFormValue,
EMPTY_INPUT_MAP_ENTRY,
REQUEST_PREFIX,
REQUEST_PREFIX_WITH_JSONPATH_ROOT_SELECTOR,
} from '../../../../../../common';
import { ModelField } from '../../input_fields';
import {
InputMapFormValue,
InputMapArrayFormValue,
} from '../../../../../../common';
import {
ConfigurePromptModal,
InputTransformModal,
Expand Down Expand Up @@ -138,11 +146,11 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
const modelInputsAsForm = [
parseModelInputs(newModelInterface).map((modelInput) => {
return {
...EMPTY_INPUT_MAP_ENTRY,
key: modelInput.label,
value: '',
} as MapEntry;
}) as MapFormValue,
] as MapArrayFormValue;
};
}) as InputMapFormValue,
] as InputMapArrayFormValue;
const modelOutputsAsForm = [
parseModelOutputs(newModelInterface).map((modelOutput) => {
return {
Expand Down Expand Up @@ -360,10 +368,29 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
)}
<EuiFlexGroup direction="row" justifyContent="spaceBetween">
<EuiFlexItem grow={false}>
<EuiText
size="m"
style={{ marginTop: '4px' }}
>{`Inputs`}</EuiText>
<EuiFlexGroup direction="row" gutterSize="xs">
<EuiFlexItem grow={false}>
<EuiText size="m">Inputs</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiIconTip
content={`Specify a ${
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'query'
: 'document'
} field or define JSONPath to transform the ${
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'query'
: 'document'
} to map to a model input field.${
props.context === PROCESSOR_CONTEXT.SEARCH_RESPONSE
? ` Or, if you'd like to include data from the the original query request, prefix your mapping with "${REQUEST_PREFIX}" or "${REQUEST_PREFIX_WITH_JSONPATH_ROOT_SELECTOR}" - for example, "_request.query.match.my_field"`
: ''
}`}
position="right"
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiToolTip
Expand All @@ -389,6 +416,7 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
<ModelInputs
config={props.config}
baseConfigPath={props.baseConfigPath}
uiConfig={props.uiConfig}
context={props.context}
/>
<EuiSpacer size="l" />
Expand Down
Loading
Loading