Skip to content

Commit

Permalink
Refactor model input/output transform configurations (#492) (#493)
Browse files Browse the repository at this point in the history

(cherry picked from commit c2f05e4)

Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 13b83dc commit 5893743
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 90 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

export * from './ml_processor_inputs';
export * from './modals';
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ import {
MapArrayFormValue,
MapEntry,
MapFormValue,
REQUEST_PREFIX,
REQUEST_PREFIX_WITH_JSONPATH_ROOT_SELECTOR,
} from '../../../../../common';
import { MapArrayField, ModelField } from '../input_fields';
} from '../../../../../../common';
import { ModelField } from '../../input_fields';
import {
ConfigurePromptModal,
InputTransformModal,
OutputTransformModal,
OverrideQueryModal,
} from './modals';
import { AppState, getMappings, useAppDispatch } from '../../../../store';
import { ModelInputs } from './model_inputs';
import { AppState, getMappings, useAppDispatch } from '../../../../../store';
import {
formikToPartialPipeline,
getDataSourceId,
parseModelInputs,
parseModelOutputs,
sanitizeJSONPath,
} from '../../../../utils';
import { ConfigFieldList } from '../config_field_list';
import { OverrideQueryModal } from './modals/override_query_modal';
} from '../../../../../utils';
import { ConfigFieldList } from '../../config_field_list';
import { ModelOutputs } from './model_outputs';

interface MLProcessorInputsProps {
uiConfig: WorkflowConfig;
Expand Down Expand Up @@ -83,10 +83,6 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
const inputMapValue = getIn(values, inputMapFieldPath);
const outputMapFieldPath = `${props.baseConfigPath}.${props.config.id}.output_map`;
const outputMapValue = getIn(values, outputMapFieldPath);
const fullResponsePath = getIn(
values,
`${props.baseConfigPath}.${props.config.id}.full_response_path`
);

// contains a configurable prompt field or not. if so, expose some extra
// dedicated UI
Expand Down Expand Up @@ -390,44 +386,10 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="s" />
<MapArrayField
fieldPath={inputMapFieldPath}
keyTitle="Name"
keyPlaceholder="Name"
keyOptions={parseModelInputs(modelInterface)}
valueTitle={
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'Query field'
: 'Document field'
}
valuePlaceholder={
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'Specify a query field'
: 'Define a document field'
}
valueHelpText={`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"`
: ''
}`}
valueOptions={
props.context === PROCESSOR_CONTEXT.INGEST
? docFields
: props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? queryFields
: indexMappingFields
}
addMapEntryButtonText="Add input"
addMapButtonText="Add input group (Advanced)"
mappingDirection="sortLeft"
<ModelInputs
config={props.config}
baseConfigPath={props.baseConfigPath}
context={props.context}
/>
<EuiSpacer size="l" />
<EuiFlexGroup direction="row" justifyContent="spaceBetween">
Expand Down Expand Up @@ -458,29 +420,10 @@ export function MLProcessorInputs(props: MLProcessorInputsProps) {
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="s" />
<MapArrayField
fieldPath={outputMapFieldPath}
keyTitle="Name"
keyPlaceholder="Name"
keyHelpText={`Specify a model output field or define JSONPath to transform the model output to map to a new document field.`}
keyOptions={
fullResponsePath
? undefined
: parseModelOutputs(modelInterface, false)
}
valueTitle={
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'Query field'
: 'New document field'
}
valuePlaceholder={
props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST
? 'Specify a query field'
: 'Define a document field'
}
addMapEntryButtonText="Add output"
addMapButtonText="Add output group (Advanced)"
mappingDirection="sortRight"
<ModelOutputs
config={props.config}
baseConfigPath={props.baseConfigPath}
context={props.context}
/>
<EuiSpacer size="s" />
{inputMapValue.length !== outputMapValue.length &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ import {
PromptPreset,
WorkflowFormValues,
customStringify,
} from '../../../../../../common';
} from '../../../../../../../common';
import {
parseModelInputs,
parseModelInputsObj,
} from '../../../../../utils/utils';
} from '../../../../../../utils/utils';

interface ConfigurePromptModalProps {
config: IProcessorConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
export * from './input_transform_modal';
export * from './output_transform_modal';
export * from './configure_prompt_modal';
export * from './override_query_modal';
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ import {
customStringify,
REQUEST_PREFIX,
REQUEST_PREFIX_WITH_JSONPATH_ROOT_SELECTOR,
} from '../../../../../../common';
} from '../../../../../../../common';
import {
formikToPartialPipeline,
generateTransform,
getFieldSchema,
getInitialValue,
prepareDocsForSimulate,
unwrapTransformedDocs,
} from '../../../../../utils';
} from '../../../../../../utils';
import {
searchIndex,
simulatePipeline,
useAppDispatch,
} from '../../../../../store';
import { getCore } from '../../../../../services';
} from '../../../../../../store';
import { getCore } from '../../../../../../services';
import {
generateArrayTransform,
getDataSourceId,
parseModelInputs,
parseModelInputsObj,
} from '../../../../../utils/utils';
import { BooleanField, MapArrayField } from '../../input_fields';
} from '../../../../../../utils/utils';
import { BooleanField, MapArrayField } from '../../../input_fields';

interface InputTransformModalProps {
uiConfig: WorkflowConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,27 @@ import {
WorkflowConfig,
WorkflowFormValues,
customStringify,
} from '../../../../../../common';
} from '../../../../../../../common';
import {
formikToPartialPipeline,
generateTransform,
getFieldSchema,
getInitialValue,
prepareDocsForSimulate,
unwrapTransformedDocs,
} from '../../../../../utils';
} from '../../../../../../utils';
import {
searchIndex,
simulatePipeline,
useAppDispatch,
} from '../../../../../store';
import { getCore } from '../../../../../services';
import { BooleanField, MapArrayField } from '../../input_fields';
} from '../../../../../../store';
import { getCore } from '../../../../../../services';
import { BooleanField, MapArrayField } from '../../../input_fields';
import {
getDataSourceId,
parseModelOutputs,
parseModelOutputsObj,
} from '../../../../../utils/utils';
} from '../../../../../../utils/utils';

interface OutputTransformModalProps {
uiConfig: WorkflowConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ import {
VECTOR_FIELD_PATTERN,
VECTOR_PATTERN,
WorkflowFormValues,
} from '../../../../../../common';
import { parseModelOutputs } from '../../../../../utils/utils';
import { JsonField } from '../../input_fields';
} from '../../../../../../../common';
import { parseModelOutputs } from '../../../../../../utils/utils';
import { JsonField } from '../../../input_fields';

interface OverrideQueryModalProps {
config: IProcessorConfig;
Expand Down
Loading

0 comments on commit 5893743

Please sign in to comment.