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

Support different input transform types #495

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9b8fff8
Set up the config -> form -> schema -> template transformations for i…
ohltyler Nov 20, 2024
1baaa5b
Handle empty casse
ohltyler Nov 20, 2024
8d2303d
Add new input type selector
ohltyler Nov 20, 2024
0f6a2b2
Fix bug of model interface not autopopulating in map
ohltyler Nov 20, 2024
9eee530
Support preset templates
ohltyler Nov 20, 2024
c855704
Dynamically render forms; edge case handling of empty docs
ohltyler Nov 20, 2024
4351a61
Add bucketing logic and add to model config if applicable
ohltyler Nov 21, 2024
a9e873d
Set up new configure_template_modal; add config button when template …
ohltyler Nov 21, 2024
aa21b24
Add nested form state in new template modal
ohltyler Nov 21, 2024
a498dcc
Update layout
ohltyler Nov 21, 2024
d099a63
Update template val form config to support subvars
ohltyler Nov 21, 2024
1acef96
Add multi input var component & form integration
ohltyler Nov 22, 2024
6fb7f7e
Add var copying into input var list
ohltyler Nov 22, 2024
e84930d
Update spacing
ohltyler Nov 22, 2024
2fafae5
Add fetching source data functionality
ohltyler Nov 22, 2024
7a94597
Fix some spacing; add output jsonfield
ohltyler Nov 22, 2024
2387aac
committing but broken
ohltyler Nov 22, 2024
5941c8c
Show transformed prompt
ohltyler Nov 23, 2024
23f41df
add spacer
ohltyler Nov 23, 2024
1d1038d
Add nested template vars to input map
ohltyler Nov 25, 2024
1fd8962
Set up base expression modal
ohltyler Nov 25, 2024
883d1ec
Get expression modal working
ohltyler Nov 25, 2024
acc96f8
Add dynamic rendering if template or expression is populated
ohltyler Nov 25, 2024
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