Skip to content

Commit

Permalink
Fix preset configs for ML processors
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler committed Nov 11, 2024
1 parent 8c20543 commit b9d03f0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
IngestPipelineConfig,
JSONPATH_ROOT_SELECTOR,
MapArrayFormValue,
MapFormValue,
ModelInterface,
OutputTransformFormValues,
OutputTransformSchema,
Expand Down Expand Up @@ -157,7 +158,7 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
sampleSourceOutput = JSON.parse(sourceOutput);
const output = generateTransform(
sampleSourceOutput,
tempOutputMap[selectedTransformOption]
reverseKeysAndValues(tempOutputMap[selectedTransformOption])
);
setTransformedOutput(customStringify(output));
} catch {}
Expand Down Expand Up @@ -641,3 +642,14 @@ root object selector "${JSONPATH_ROOT_SELECTOR}"`}
</Formik>
);
}

// since we persist the form keys/values reversed, we have a util fn to reverse back, so we can use
// single util fns for manipulation of the form values (generating transforms, etc.)
function reverseKeysAndValues(values: MapFormValue): MapFormValue {
return values.map((mapEntry) => {
return {
key: mapEntry.value,
value: mapEntry.key,
};
});
}
24 changes: 13 additions & 11 deletions public/pages/workflows/new_workflow/quick_configure_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,10 @@ function updateIngestProcessors(
if (outputMap.length > 0) {
outputMap[0] = {
...outputMap[0],
key: defaultField,
value: defaultField,
};
} else {
outputMap.push({ key: defaultField, value: '' });
outputMap.push({ key: '', value: defaultField });
}
}
field.value = [outputMap] as MapArrayFormValue;
Expand Down Expand Up @@ -344,16 +344,18 @@ function updateSearchRequestProcessors(
}
if (field.id === 'output_map') {
const outputMap = generateMapFromModelOutputs(modelInterface);
const defaultKey = isVectorSearchUseCase ? VECTOR : defaultQueryValue;
const defaultValue = isVectorSearchUseCase
? VECTOR
: defaultQueryValue;
if (outputMap.length > 0) {
outputMap[0] = {
...outputMap[0],
key: defaultKey,
value: defaultValue,
};
} else {
outputMap.push({
key: defaultKey,
value: '',
key: '',
value: defaultValue,
});
}
field.value = [outputMap] as MapArrayFormValue;
Expand Down Expand Up @@ -412,10 +414,10 @@ function updateSearchResponseProcessors(
if (outputMap.length > 0) {
outputMap[0] = {
...outputMap[0],
key: fields.llmResponseField,
value: fields.llmResponseField,
};
} else {
outputMap.push({ key: fields.llmResponseField, value: '' });
outputMap.push({ key: '', value: fields.llmResponseField });
}
}
field.value = [outputMap] as MapArrayFormValue;
Expand Down Expand Up @@ -540,7 +542,7 @@ function generateMapFromModelInputs(
return inputMap;
}

// generate a set of mappings s.t. each value is
// generate a set of mappings s.t. each key is
// a unique model output
function generateMapFromModelOutputs(
modelInterface?: ModelInterface
Expand All @@ -550,8 +552,8 @@ function generateMapFromModelOutputs(
const modelOutputs = parseModelOutputs(modelInterface);
modelOutputs.forEach((modelOutput) => {
outputMap.push({
key: '',
value: modelOutput.label,
key: modelOutput.label,
value: '',
});
});
}
Expand Down

0 comments on commit b9d03f0

Please sign in to comment.