Skip to content

Commit

Permalink
Onboard one-to-one config for ML search resp processors (#343) (#344)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
(cherry picked from commit bfeb79c)

Co-authored-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
opensearch-trigger-bot[bot] and ohltyler authored Sep 4, 2024
1 parent b84da8b commit cc510e6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ export class MLSearchResponseProcessor extends MLProcessor {
constructor() {
super();
this.id = generateId('ml_processor_search_response');
this.optionalFields = [
{
id: 'one_to_one',
type: 'boolean',
},
...(this.optionalFields || []),
];
}
}
20 changes: 9 additions & 11 deletions public/pages/workflow_detail/workflow_inputs/config_field_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ export function ConfigFieldList(props: ConfigFieldListProps) {
return (
<EuiFlexItem grow={false}>
{props.configFields.map((field, idx) => {
const fieldPath = `${props.baseConfigPath}.${props.configId}.${field.id}`;
let el;
switch (field.type) {
case 'string': {
el = (
<EuiFlexItem key={idx}>
<TextField
label={camelCaseToTitleString(field.id)}
fieldPath={`${props.baseConfigPath}.${props.configId}.${field.id}`}
fieldPath={fieldPath}
showError={true}
/>
<EuiSpacer size={CONFIG_FIELD_SPACER_SIZE} />
Expand All @@ -50,10 +51,7 @@ export function ConfigFieldList(props: ConfigFieldListProps) {
case 'select': {
el = (
<EuiFlexItem key={idx}>
<SelectField
field={field}
fieldPath={`${props.baseConfigPath}.${props.configId}.${field.id}`}
/>
<SelectField field={field} fieldPath={fieldPath} />
<EuiSpacer size={CONFIG_FIELD_SPACER_SIZE} />
</EuiFlexItem>
);
Expand All @@ -64,13 +62,13 @@ export function ConfigFieldList(props: ConfigFieldListProps) {
<EuiFlexItem key={idx}>
<BooleanField
label={camelCaseToTitleString(field.id)}
fieldPath={`${props.baseConfigPath}.${props.configId}.${field.id}`}
fieldPath={fieldPath}
enabledOption={{
id: 'true',
id: `${fieldPath}_true`,
label: 'True',
}}
disabledOption={{
id: 'false',
id: `${fieldPath}_false`,
label: 'False',
}}
showLabel={true}
Expand All @@ -85,7 +83,7 @@ export function ConfigFieldList(props: ConfigFieldListProps) {
<EuiFlexItem key={idx}>
<NumberField
label={camelCaseToTitleString(field.id)}
fieldPath={`${props.baseConfigPath}.${props.configId}.${field.id}`}
fieldPath={fieldPath}
showError={true}
/>
<EuiSpacer size={CONFIG_FIELD_SPACER_SIZE} />
Expand All @@ -98,7 +96,7 @@ export function ConfigFieldList(props: ConfigFieldListProps) {
<EuiFlexItem key={idx}>
<JsonField
label={camelCaseToTitleString(field.id)}
fieldPath={`${props.baseConfigPath}.${props.configId}.${field.id}`}
fieldPath={fieldPath}
/>
<EuiSpacer size={CONFIG_FIELD_SPACER_SIZE} />
</EuiFlexItem>
Expand All @@ -111,7 +109,7 @@ export function ConfigFieldList(props: ConfigFieldListProps) {
<JsonField
validate={false}
label={camelCaseToTitleString(field.id)}
fieldPath={`${props.baseConfigPath}.${props.configId}.${field.id}`}
fieldPath={fieldPath}
/>
<EuiSpacer size={CONFIG_FIELD_SPACER_SIZE} />
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React, { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { Field, FieldProps, getIn, useFormikContext } from 'formik';
import { isEmpty } from 'lodash';
import {
EuiCallOut,
EuiCompressedFormRow,
Expand Down Expand Up @@ -45,7 +46,7 @@ export function ModelField(props: ModelFieldProps) {
// keeps re-rendering this component (and subsequently re-fetching data) as they're building flows
const models = useSelector((state: AppState) => state.ml.models);

const { errors, touched } = useFormikContext<WorkspaceFormValues>();
const { errors, touched, values } = useFormikContext<WorkspaceFormValues>();

// Deployed models state
const [deployedModels, setDeployedModels] = useState<ModelItem[]>([]);
Expand All @@ -70,17 +71,18 @@ export function ModelField(props: ModelFieldProps) {

return (
<>
{!props.hasModelInterface && (
<>
<EuiCallOut
size="s"
title="The selected model does not have a model interface. Cannot automatically determine model inputs and outputs."
iconType={'alert'}
color="warning"
/>
<EuiSpacer size="s" />
</>
)}
{!props.hasModelInterface &&
!isEmpty(getIn(values, props.fieldPath)?.id) && (
<>
<EuiCallOut
size="s"
title="The selected model does not have a model interface. Cannot automatically determine model inputs and outputs."
iconType={'alert'}
color="warning"
/>
<EuiSpacer size="s" />
</>
)}
<Field name={props.fieldPath}>
{({ field, form }: FieldProps) => {
return (
Expand Down

0 comments on commit cc510e6

Please sign in to comment.