Skip to content

Commit

Permalink
Improve input/output transformation configuration (#504)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler authored Nov 27, 2024
1 parent 9e1e5b4 commit a148ea5
Show file tree
Hide file tree
Showing 25 changed files with 3,269 additions and 2,201 deletions.
18 changes: 17 additions & 1 deletion 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,13 @@ export enum TRANSFORM_CONTEXT {
INPUT = 'input',
OUTPUT = 'output',
}
export enum TRANSFORM_TYPE {
STRING = 'String',
FIELD = 'Field',
EXPRESSION = 'Expression',
TEMPLATE = 'Template',
}
export const NO_TRANSFORMATION = 'No transformation';
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,13 +498,21 @@ 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 EMPTY_OUTPUT_MAP_ENTRY = EMPTY_INPUT_MAP_ENTRY;
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';
export const PROMPT_FIELD = 'prompt'; // TODO: likely expand to support a pattern and/or multiple (e.g., "prompt", "prompt_template", etc.)
export enum CONFIG_STEP {
INGEST = 'Ingestion pipeline',
SEARCH = 'Search pipeline',
Expand Down
67 changes: 55 additions & 12 deletions common/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ObjectSchema } from 'yup';
import {
COMPONENT_CLASS,
PROCESSOR_TYPE,
PROMPT_FIELD,
TRANSFORM_TYPE,
WORKFLOW_TYPE,
} from './constants';

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

export type ConfigFieldValue = string | {};

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

export type MapArrayFormValue = MapFormValue[];

export type ExpressionVar = {
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?: ExpressionVar[];
};

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

export type InputMapFormValue = InputMapEntry[];
export type OutputMapFormValue = OutputMapEntry[];

export type InputMapArrayFormValue = InputMapFormValue[];
export type OutputMapArrayFormValue = OutputMapFormValue[];

export type WorkflowFormValues = {
ingest: FormikValues;
search: FormikValues;
Expand All @@ -110,31 +137,48 @@ export type WorkflowSchemaObj = {
};
export type WorkflowSchema = ObjectSchema<WorkflowSchemaObj>;

// Form / schema interfaces for the ingest docs sub-form
/**
********** MODAL SUB-FORM TYPES/INTERFACES **********
We persist sub-forms in the form modals s.t. data is only
saved back to the parent form if the user explicitly saves.
We define the structure of the forms here.
*/

// Ingest docs modal
export type IngestDocsFormValues = {
docs: FormikValues;
};
export type IngestDocsSchema = WorkflowSchema;

// Form / schema interfaces for the request query sub-form
// Search request modal
export type RequestFormValues = {
request: ConfigFieldValue;
};
export type RequestSchema = WorkflowSchema;

// Form / schema interfaces for the input transform sub-form
// Input transform modal
export type InputTransformFormValues = {
input_map: MapArrayFormValue;
input_map: InputMapArrayFormValue;
one_to_one: ConfigFieldValue;
};
export type InputTransformSchema = WorkflowSchema;

// Form / schema interfaces for the output transform sub-form
// Output transform modal
export type OutputTransformFormValues = {
output_map: MapArrayFormValue;
full_response_path: ConfigFieldValue;
};
export type OutputTransformSchema = WorkflowSchema;

// Configure template modal
export type TemplateFormValues = Omit<Transform, 'transformType'>;

// Configure expression modal
export type ExpressionFormValues = {
expression: string;
};

// Configure multi-expression modal
export type MultiExpressionFormValues = {
expressions: ExpressionVar[];
};

/**
********** WORKSPACE TYPES/INTERFACES **********
Expand Down Expand Up @@ -429,7 +473,6 @@ export type ModelInterface = {
export type ConnectorParameters = {
model?: string;
dimensions?: number;
[PROMPT_FIELD]?: string;
};

export type Model = {
Expand Down
4 changes: 2 additions & 2 deletions public/configs/ml_processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export abstract class MLProcessor extends Processor {
},
{
id: 'input_map',
type: 'mapArray',
type: 'inputMapArray',
},
{
id: 'output_map',
type: 'mapArray',
type: 'outputMapArray',
},
];
this.optionalFields = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import {
IConfigField,
IndexMappings,
IngestDocsFormValues,
IngestDocsSchema,
isVectorSearchUseCase,
SearchHit,
SOURCE_OPTIONS,
Expand Down Expand Up @@ -78,7 +77,7 @@ export function SourceDataModal(props: SourceDataProps) {
docs: getFieldSchema({
type: 'jsonArray',
} as IConfigField),
}) as IngestDocsSchema;
}) as yup.Schema;

// persist standalone values. update / initialize when it is first opened
const [tempDocs, setTempDocs] = useState<string>('[]');
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
}
/>
);
}
Loading

0 comments on commit a148ea5

Please sign in to comment.