Skip to content

Commit

Permalink
add query validator to ppl submit
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <[email protected]>
  • Loading branch information
ps48 committed Aug 17, 2023
1 parent 3217c6d commit d102a97
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions public/components/llm_chat/components/feedback_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React, { useState } from 'react';
import { HttpStart } from '../../../../../../src/core/public';
import { LANGCHAIN_API } from '../../../../common/constants/llm';
import { coreRefs } from '../../../framework/core_refs';
import { getPPLService } from '../../../../common/utils';

export interface FeedbackFormData {
input: string;
Expand Down Expand Up @@ -104,7 +105,11 @@ export const FeedbackModalContent: React.FC<FeedbackModalContentProps> = (props)
const onSubmit = async (event: React.FormEvent) => {
event.preventDefault();
const errors = {
input: validator.input(props.formData.input),
input:
validator.input(props.formData.input) +
(props.metadata.type === 'ppl_submit'
? await validator.validateQuery(props.formData.input)
: ''),
output: validator.output(props.formData.output),
correct: validator.correct(props.formData.correct),
expectedOutput: validator.expectedOutput(
Expand Down Expand Up @@ -161,7 +166,6 @@ export const FeedbackModalContent: React.FC<FeedbackModalContentProps> = (props)
setFormErrors({ ...formErrors, input: validator.input(e.target.value) });
}}
isInvalid={hasError('input')}
disabled={props.metadata.type === 'ppl_submit'}
/>
</EuiFormRow>
<EuiFormRow
Expand Down Expand Up @@ -271,11 +275,27 @@ const useSubmitFeedback = (data: FeedbackFormData, metadata: FeedbackMetaData, h
};
};

const validatePPLQuery = async (logsQuery: string) => {
let responseMessage = '';
const pplService = getPPLService();
await pplService
.fetch({ query: logsQuery, format: 'jdbc' })
.then((res) => {
if (res === undefined) responseMessage = ' Invalid PPL Query, please re-check the ppl syntax';
})
.catch((error: Error) => {
responseMessage = ' Invalid PPL Query, please re-check the ppl syntax';
});

return responseMessage;
};

const validator = {
input: (text: string) => (text.trim().length === 0 ? ['Input is required'] : []),
output: (text: string) => (text.trim().length === 0 ? ['Output is required'] : []),
correct: (correct: boolean | undefined) =>
correct === undefined ? ['Correctness is required'] : [],
expectedOutput: (text: string, required: boolean) =>
required && text.trim().length === 0 ? ['expectedOutput is required'] : [],
validateQuery: async (logsQuery: string) => await validatePPLQuery(logsQuery),
};

0 comments on commit d102a97

Please sign in to comment.