Skip to content

Commit

Permalink
Add empty source input checks (ingest & search) (#398)
Browse files Browse the repository at this point in the history
* Add empty source input checks; remove legacy files

Signed-off-by: Tyler Ohlsen <[email protected]>

* repeat for output transform

Signed-off-by: Tyler Ohlsen <[email protected]>

* add disabled check

Signed-off-by: Tyler Ohlsen <[email protected]>

---------

Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler authored Sep 20, 2024
1 parent 95049f7 commit dd20c6f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 9 deletions.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ export function ConfigurePromptModal(props: ConfigurePromptModalProps) {
items: PROMPT_PRESETS.map((preset: PromptPreset) => ({
name: preset.name,
onClick: () => {
setFieldValue(
modelConfigPath,
customStringify({
...JSON.parse(modelConfig),
prompt: preset.prompt,
})
);
try {
setFieldValue(
modelConfigPath,
customStringify({
...JSON.parse(modelConfig),
prompt: preset.prompt,
})
);
} catch {}
setFieldTouched(modelConfigPath, true);
setPresetsPopoverOpen(false);
},
Expand Down Expand Up @@ -158,7 +160,10 @@ export function ConfigurePromptModal(props: ConfigurePromptModalProps) {
tabSize={2}
onChange={(value) => setPromptStr(value)}
onBlur={(e) => {
let updatedModelConfig = JSON.parse(modelConfig);
let updatedModelConfig = {} as any;
try {
updatedModelConfig = JSON.parse(modelConfig);
} catch {}
if (isEmpty(promptStr)) {
// if the input is blank, it is assumed the user
// does not want any prompt. hence, remove the "prompt" field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
EuiPopoverTitle,
EuiIconTip,
EuiSwitch,
EuiCallOut,
} from '@elastic/eui';
import {
IConfigField,
Expand Down Expand Up @@ -106,6 +107,22 @@ export function InputTransformModal(props: InputTransformModalProps) {
const map = getIn(values, props.inputMapFieldPath) as MapArrayFormValue;
const oneToOnePath = `${props.baseConfigPath}.${props.config.id}.one_to_one`;
const oneToOne = getIn(values, oneToOnePath);
const docs = getIn(values, 'ingest.docs');
let docObjs = [] as {}[] | undefined;
try {
docObjs = JSON.parse(docs);
} catch {}
const query = getIn(values, 'search.request');
let queryObj = {} as {} | undefined;
try {
queryObj = JSON.parse(query);
} catch {}
const onIngestAndNoDocs =
props.context === PROCESSOR_CONTEXT.INGEST && isEmpty(docObjs);
const onSearchAndNoQuery =
(props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST ||
props.context === PROCESSOR_CONTEXT.SEARCH_RESPONSE) &&
isEmpty(queryObj);

// selected transform state
const transformOptions = map.map((_, idx) => ({
Expand Down Expand Up @@ -226,6 +243,20 @@ export function InputTransformModal(props: InputTransformModalProps) {
<EuiFlexGroup direction="column">
<EuiFlexItem>
<>
{(onIngestAndNoDocs || onSearchAndNoQuery) && (
<>
<EuiCallOut
size="s"
title={
onIngestAndNoDocs
? 'No source documents detected. Fetching is unavailable.'
: 'No source query detected. Fetching is unavailable.'
}
color="warning"
/>
<EuiSpacer size="s" />
</>
)}
<EuiText color="subdued">{description}</EuiText>
<EuiSpacer size="s" />
{props.context === PROCESSOR_CONTEXT.SEARCH_RESPONSE && (
Expand All @@ -252,6 +283,7 @@ export function InputTransformModal(props: InputTransformModalProps) {
<EuiSmallButton
style={{ width: '100px' }}
isLoading={isFetching}
disabled={onIngestAndNoDocs || onSearchAndNoQuery}
onClick={async () => {
setIsFetching(true);
switch (props.context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EuiSmallButtonEmpty,
EuiPopoverTitle,
EuiCodeBlock,
EuiCallOut,
} from '@elastic/eui';
import {
IConfigField,
Expand Down Expand Up @@ -91,6 +92,22 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
const map = getIn(values, props.outputMapFieldPath) as MapArrayFormValue;
const fullResponsePathPath = `${props.baseConfigPath}.${props.config.id}.full_response_path`;
const fullResponsePath = getIn(values, fullResponsePathPath);
const docs = getIn(values, 'ingest.docs');
let docObjs = [] as {}[] | undefined;
try {
docObjs = JSON.parse(docs);
} catch {}
const query = getIn(values, 'search.request');
let queryObj = {} as {} | undefined;
try {
queryObj = JSON.parse(query);
} catch {}
const onIngestAndNoDocs =
props.context === PROCESSOR_CONTEXT.INGEST && isEmpty(docObjs);
const onSearchAndNoQuery =
(props.context === PROCESSOR_CONTEXT.SEARCH_REQUEST ||
props.context === PROCESSOR_CONTEXT.SEARCH_RESPONSE) &&
isEmpty(queryObj);

// popover state containing the model interface details, if applicable
const [popoverOpen, setPopoverOpen] = useState<boolean>(false);
Expand Down Expand Up @@ -141,6 +158,20 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
<EuiFlexGroup direction="column">
<EuiFlexItem>
<>
{(onIngestAndNoDocs || onSearchAndNoQuery) && (
<>
<EuiCallOut
size="s"
title={
onIngestAndNoDocs
? 'No source documents detected. Fetching is unavailable.'
: 'No source query detected. Fetching is unavailable.'
}
color="warning"
/>
<EuiSpacer size="s" />
</>
)}
<EuiText color="subdued">
Fetch some sample output data and see how it is transformed.
</EuiText>
Expand Down Expand Up @@ -211,6 +242,7 @@ export function OutputTransformModal(props: OutputTransformModalProps) {
<EuiSmallButton
style={{ width: '100px' }}
isLoading={isFetching}
disabled={onIngestAndNoDocs || onSearchAndNoQuery}
onClick={async () => {
setIsFetching(true);
switch (props.context) {
Expand Down
5 changes: 4 additions & 1 deletion public/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ export function prepareDocsForSimulate(
indexName: string
): SimulateIngestPipelineDoc[] {
const preparedDocs = [] as SimulateIngestPipelineDoc[];
const docObjs = JSON.parse(docs) as {}[];
let docObjs = [] as {}[];
try {
docObjs = JSON.parse(docs) as {}[];
} catch {}
docObjs.forEach((doc) => {
preparedDocs.push({
_index: indexName,
Expand Down

0 comments on commit dd20c6f

Please sign in to comment.