Skip to content

Commit 2042c38

Browse files
author
Keivan Vosoughi
committed
fix: minor update to DataGenerator Configure component for consistency before PR creation
1 parent f688818 commit 2042c38

File tree

4 files changed

+59
-18
lines changed

4 files changed

+59
-18
lines changed

app/client/src/pages/DataGenerator/Configure.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import FileSelectorButton from './FileSelectorButton';
1313
import UseCaseSelector from './UseCaseSelector';
1414
import { useLocation, useParams } from 'react-router-dom';
1515
import { WizardModeType } from '../../types';
16-
import { get } from 'lodash';
1716

1817

1918
const StepContainer = styled(Flex)`
@@ -96,10 +95,13 @@ const Configure = () => {
9695
validateForm()
9796
}, [form, formData])
9897

99-
// keivan
98+
10099
useEffect(() => {
101100
if (formData && formData?.inference_type === undefined && isEmpty(generate_file_name)) {
102101
form.setFieldValue('inference_type', ModelProviders.CAII);
102+
setTimeout(() => {
103+
form.setFieldValue('use_case','custom');
104+
}, 1000);
103105
}
104106
}, [formData]);
105107

@@ -251,18 +253,19 @@ const Configure = () => {
251253
</Form.Item>
252254
{(formData?.workflow_type === WorkflowType.SUPERVISED_FINE_TUNING ||
253255
formData?.workflow_type === WorkflowType.FREE_FORM_DATA_GENERATION) &&
254-
<UseCaseSelector />}
256+
<UseCaseSelector form={form} />}
255257

256258
{(
257259
formData?.workflow_type === WorkflowType.SUPERVISED_FINE_TUNING ||
258260
formData?.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION) &&
259261
<Form.Item
260262
name='doc_paths'
261-
label='Context'
263+
label='Input File'
262264
labelCol={labelCol}
263265
dependencies={['workflow_type']}
264266
shouldUpdate
265267
validateTrigger="['onBlur','onChange']"
268+
tooltip='Select a file from your project that contains the initial data to be augmented.'
266269
validateFirst
267270
rules={[
268271
() => ({
@@ -307,6 +310,7 @@ const Configure = () => {
307310
label='Input Key'
308311
labelCol={labelCol}
309312
validateTrigger={['workflow_type', 'onChange']}
313+
tooltip='Choose the key or column from your uploaded file that will be used as the input for data generation.'
310314
shouldUpdate
311315
rules={[
312316
() => ({
@@ -330,6 +334,7 @@ const Configure = () => {
330334
name='output_key'
331335
label='Output Key'
332336
labelCol={labelCol}
337+
tooltip='Name the value or column where the prompts will be saved. If left blank, this will default to “Prompt".'
333338
shouldUpdate
334339
>
335340
<Input />
@@ -338,6 +343,7 @@ const Configure = () => {
338343
name='output_value'
339344
label='Output Value'
340345
labelCol={labelCol}
346+
tooltip='Enter the name for the generated values corresponding to each input. If left blank, this will default to “Completion”.'
341347
shouldUpdate
342348
>
343349
<Input />

app/client/src/pages/DataGenerator/CustomPromptButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ const CustomPromptButton: React.FC<Props> = ({ model_id, inference_type, caii_en
157157
disabled={mutation.isPending}
158158
rows={15}
159159
autoSize
160-
placeholder={'Enter instructions for a custom prompt'}
160+
placeholder={'Generate prompt from the example data'}
161161
/>
162162
</Form.Item>
163163
</Form>

app/client/src/pages/DataGenerator/Examples.tsx

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import PCModalContent from './PCModalContent';
1212
import { ExampleType, File, QuestionSolution, WorkflowType } from './types';
1313
import FileSelectorButton from './FileSelectorButton';
1414

15-
import { fetchFileContent, getExampleType, useGetExamplesByUseCase } from './hooks';
15+
import { fetchExamplesByUseCase, fetchFileContent, getExampleType, useGetExamplesByUseCase } from './hooks';
1616
import { useState } from 'react';
1717
import FreeFormExampleTable from './FreeFormExampleTable';
1818
import { L } from 'vitest/dist/chunks/reporters.DTtkbAtP.js';
@@ -54,14 +54,27 @@ const Examples: FunctionComponent = () => {
5454
const form = Form.useFormInstance();
5555
const [records, setRecords] = useState<Record<string, string>[]>([]);
5656
const workflowType = form.getFieldValue('workflow_type');
57-
const { examples, isLoading: examplesLoading, refetch } =
58-
useGetExamplesByUseCase(form.getFieldValue('use_case'));
57+
// const { examples, isLoading: examplesLoading } =
58+
// useGetExamplesByUseCase(form.getFieldValue('use_case'));
59+
// console.log('------------------> examples', examples);
5960

6061
const mutation = useMutation({
6162
mutationFn: fetchFileContent
6263
});
6364

65+
const restore_mutation = useMutation({
66+
mutationFn: fetchExamplesByUseCase
67+
});
68+
69+
useEffect(() => {
70+
console.log('------------------> useEffect 0');
71+
const useCase = form.getFieldValue('use_case');
72+
restore_mutation.mutate(useCase);
73+
}, [form.getFieldValue('use_case')]);
74+
75+
6476
useEffect(() => {
77+
console.log('------------------> useEffect 1');
6578
const example_path = form.getFieldValue('example_path');
6679
if (!isEmpty(example_path)) {
6780
mutation.mutate({
@@ -70,21 +83,37 @@ const Examples: FunctionComponent = () => {
7083
}
7184
}, [form.getFieldValue('example_path'), form.getFieldValue('workflow_type')]);
7285

73-
useEffect(() => {
74-
console.log('------------------> useEffect')
86+
useEffect(() => {
87+
console.log('------------------> useEffect 2', mutation.data);
7588
if (!isEmpty(mutation.data)) {
89+
console.log('------------------> 1');
7690
form.setFieldValue('examples', mutation.data);
7791
if (!isEqual(mutation.data, records)) {
7892
setRecords(mutation.data);
7993
}
8094

81-
} else if (Array.isArray(examples) && !isEqual(examples, records)) {
95+
}
96+
// else if (Array.isArray(examples) && !isEqual(examples, records)) {
97+
// console.log('------------------> 2');
98+
// form.setFieldValue('examples', examples);
99+
// setRecords(examples);
100+
// }
101+
}, [mutation.data]);
102+
103+
useEffect(() => {
104+
console.log('------------------> useEffect 3', restore_mutation.data);
105+
if (!isEmpty(restore_mutation.data)) {
106+
const examples = get(restore_mutation.data, 'examples', []);
82107
form.setFieldValue('examples', examples);
83108
setRecords(examples);
84109
}
85-
}, [mutation.data, examples]);
86-
110+
}, [restore_mutation.data]);
87111

112+
const onRestoreDefaults = async() => {
113+
console.log('------------------> onRestoreDefaults');
114+
const useCase = form.getFieldValue('use_case');
115+
restore_mutation.mutate(useCase);
116+
}
88117

89118
const onAddFiles = (files: File[]) => {
90119
if (!isEmpty (files)) {
@@ -104,16 +133,21 @@ const Examples: FunctionComponent = () => {
104133
span: 10
105134
};
106135

107-
const showEmptyState = workflowType === WorkflowType.FREE_FORM_DATA_GENERATION &&
136+
const showEmptyState = (workflowType === WorkflowType.FREE_FORM_DATA_GENERATION &&
108137
isEmpty(mutation.data) &&
109-
records.length === 0;
138+
records.length === 0) ||
139+
(form.getFieldValue('use_case') === 'custom' &&
140+
isEmpty(form.getFieldValue('examples')));
110141

111142
console.log('examples', form.getFieldValue('examples'));
112143
console.log('records', records);
144+
console.log('use_case', form.getFieldValue('use_case'));
145+
console.log('example_path', form.getFieldValue('example_path'));
146+
console.log('mutation', mutation);
113147

114148
return (
115149
<Container>
116-
{examplesLoading && <Loading />}
150+
{mutation?.isPending || restore_mutation.isPending && <Loading />}
117151
<Header align='center' justify='space-between'>
118152
<StyledTitle level={3}>
119153
<Space>
@@ -149,8 +183,8 @@ const Examples: FunctionComponent = () => {
149183
<ModalButtonGroup gap={8} justify='end'>
150184
<Button onClick={() => Modal.destroyAll()}>{'Cancel'}</Button>
151185
<Button
152-
onClick={() => {
153-
refetch();
186+
onClick={async () => {
187+
await onRestoreDefaults();
154188
Modal.destroyAll();
155189
}}
156190
type='primary'

app/client/src/pages/DataGenerator/hooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ export const fetchExamplesByUseCase = async (use_case: string) => {
280280
}
281281

282282
export const useGetExamplesByUseCase = (use_case: string) => {
283+
console.log('------------------> useGetExamplesByUseCase', use_case);
283284
const { data, isLoading, isError, error, isFetching, refetch } = useQuery(
284285
{
285286
queryKey: ['fetchUseCaseTopics', fetchExamplesByUseCase],

0 commit comments

Comments
 (0)