Skip to content

Commit c1bf55d

Browse files
author
Keivan Vosoughi
committed
Regenerate Issues using PDF Files
1 parent 17d811b commit c1bf55d

File tree

9 files changed

+73
-30
lines changed

9 files changed

+73
-30
lines changed

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

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,28 @@ const Configure: FunctionComponent = () => {
5555
const location = useLocation();
5656
const { template_name, generate_file_name } = useParams();
5757
const [wizardModeType, setWizardModeType] = useState(getWizardModeType(location));
58+
console.log('wizardModeType', wizardModeType);
5859

5960
useEffect(() => {
6061
if (wizardModeType === WizardModeType.DATA_AUGMENTATION) {
6162
setWizardModeType(WizardModeType.DATA_AUGMENTATION);
62-
form.setFieldValue('workflow_type', 'freeform');
63+
form.setFieldValue('workflow_type', 'custom');
6364
} else {
6465
setWizardModeType(WizardModeType.DATA_GENERATION);
65-
form.setFieldValue('workflow_type', 'custom');
66+
form.setFieldValue('workflow_type', 'freeform');
6667
}
6768
}, [location, wizardModeType]);
6869

70+
console.log('wizardModeType', wizardModeType);
71+
6972
useEffect(() => {
73+
console.log('useEffect 2');
7074
if (template_name) {
71-
form.setFieldValue('use_case', template_name);
75+
setTimeout(() => {
76+
console.log('setting template name');
77+
form.setFieldValue('use_case', template_name);
78+
}, 1000);
79+
7280
}
7381
}, [template_name]);
7482

@@ -85,6 +93,7 @@ const Configure: FunctionComponent = () => {
8593
delete values.doc_paths;
8694
delete values.output_key;
8795
delete values.output_value;
96+
console.log('validateForm', values);
8897

8998
const allFieldsFilled = Object.values(values).every(value => Boolean(value));
9099
if (allFieldsFilled && isFunction(setIsStepValid)) {
@@ -99,10 +108,11 @@ const Configure: FunctionComponent = () => {
99108

100109

101110
useEffect(() => {
111+
console.log('useEffect 1');
102112
if (formData && formData?.inference_type === undefined && isEmpty(generate_file_name)) {
103113
form.setFieldValue('inference_type', ModelProviders.CAII);
104114
setTimeout(() => {
105-
form.setFieldValue('use_case','custom');
115+
form.setFieldValue('use_case', template_name ? template_name : 'custom');
106116
}, 1000);
107117
}
108118
}, [formData]);
@@ -253,18 +263,32 @@ const Configure: FunctionComponent = () => {
253263
)}
254264
</Select>
255265
</Form.Item>
256-
{(formData?.workflow_type === WorkflowType.SUPERVISED_FINE_TUNING ||
257-
formData?.workflow_type === WorkflowType.FREE_FORM_DATA_GENERATION) &&
258-
<UseCaseSelector form={form} />}
266+
267+
<UseCaseSelector form={form} hidden={formData?.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION} />
259268

260269
{(
261-
formData?.workflow_type === WorkflowType.SUPERVISED_FINE_TUNING ||
262-
formData?.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION) &&
270+
formData?.workflow_type === WorkflowType.FREE_FORM_DATA_GENERATION ||
271+
(formData?.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION &&
272+
formData?.use_case === 'custom')) &&
273+
<Form.Item
274+
noStyle
275+
shouldUpdate={(prevValues, currentValues) =>
276+
prevValues.doc_paths !== currentValues.doc_paths ||
277+
prevValues.use_case !== currentValues.use_case
278+
}
279+
>
280+
{({}) => {
281+
const useCase = form.getFieldValue('use_case');
282+
if (useCase === 'custom') {
283+
284+
}
285+
return (
286+
263287
<Form.Item
264288
name='doc_paths'
265-
label='Input File'
289+
label={(useCase === 'custom' && formData?.workflow_type === WorkflowType.FREE_FORM_DATA_GENERATION) ? 'Context' : 'Input File'}
266290
labelCol={labelCol}
267-
dependencies={['workflow_type']}
291+
dependencies={['workflow_type', 'use_case]']}
268292
shouldUpdate
269293
validateTrigger="['onBlur','onChange']"
270294
tooltip='Select a file from your project that contains the initial data to be augmented.'
@@ -302,9 +326,9 @@ const Configure: FunctionComponent = () => {
302326
>
303327
<Flex>
304328
<Select placeholder={'Select project files'} mode="multiple" value={selectedFiles || []} onChange={onFilesChange} allowClear/>
305-
<FileSelectorButton onAddFiles={onAddFiles} workflowType={form.getFieldValue('workflow_type')} allowFileTypes={['pdf', 'docx']}/>
329+
<FileSelectorButton onAddFiles={onAddFiles} workflowType={form.getFieldValue('workflow_type')} allowFileTypes={['pdf', 'docx', 'json']}/>
306330
</Flex>
307-
</Form.Item>}
331+
</Form.Item>)}}</Form.Item>}
308332
{formData?.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION &&
309333
<>
310334
<Form.Item

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const Examples: FunctionComponent = () => {
149149
</Space>
150150
</StyledTitle>
151151
<Flex align='center' gap={15}>
152-
{workflowType === WorkflowType.FREE_FORM_DATA_GENERATION &&
152+
{(workflowType === WorkflowType.CUSTOM_DATA_GENERATION || workflowType === WorkflowType.FREE_FORM_DATA_GENERATION) &&
153153
<>
154154
<Form.Item
155155
name="example_path"
@@ -158,7 +158,7 @@ const Examples: FunctionComponent = () => {
158158
style={{ display: 'none' }}
159159
shouldUpdate
160160
rules={[
161-
{ required: true }
161+
{ required: false }
162162
]}
163163
>
164164
<Input disabled />

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ const Finish = () => {
202202
}
203203

204204
let topicTabs = [];
205-
if (!hasDocSeeds && formValues.workflow_type !== WorkflowType.CUSTOM_DATA_GENERATION &&
205+
console.log('Preparing topics...', formValues.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION)
206+
if (!hasDocSeeds && formValues.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION && formValues.use_case !== 'custom' &&
206207
hasTopics(genDatasetResp) && !isEmpty(genDatasetResp?.results)) {
207208
const values = Object.values(genDatasetResp?.results);
208209

@@ -297,6 +298,10 @@ const Finish = () => {
297298
</>
298299
)
299300
}
301+
console.log('Finish >> ');
302+
console.log('hasTopics', hasTopics(genDatasetResp));
303+
console.log('formValues', formValues);
304+
console.log('isDemo', isDemo, topicTabs);
300305

301306
return (
302307
<div>
@@ -322,12 +327,12 @@ const Finish = () => {
322327
</StyledButton>
323328
</Flex>
324329
)}
325-
{isDemo && formValues.workflow_type !== WorkflowType.CUSTOM_DATA_GENERATION && hasTopics(genDatasetResp && !hasDocSeeds) && (
330+
{(isDemo && formValues.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION && formValues.use_case !== 'custom' && hasTopics(genDatasetResp) && !hasDocSeeds) && (
326331
<TabsContainer title={'Generated Dataset'}>
327332
<Tabs tabPosition='left' items={topicTabs}/>
328333
</TabsContainer>
329334
)}
330-
{formValues.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION &&
335+
{formValues.workflow_type === WorkflowType.CUSTOM_DATA_GENERATION && formValues.use_case === 'custom' &&
331336
<CustomResultTable results={genDatasetResp?.results || []} />
332337
}
333338
{hasDocSeeds && <SeedResultTable results={genDatasetResp?.results || {}} />}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ interface Props {
4545
}
4646

4747
const FreeFormTable: FunctionComponent<Props> = ({ data }) => {
48+
console.log('FreeFormTable', data);
4849
const [colDefs, setColDefs] = useState([]);
4950
const [rowData, setRowData] = useState([]);
5051

5152
useEffect(() => {
5253
if (!isEmpty(data)) {
54+
console.log('data', data);
5355
const columnNames = Object.keys(first(data));
5456
const columnDefs = columnNames.map((colName) => ({
5557
field: colName,

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const SeedsFormItem = styled(StyledFormItem)`
7676

7777
const Prompt = () => {
7878
const form = Form.useFormInstance();
79+
console.log('form', form);
7980
const selectedTopics = Form.useWatch('topics');
8081
const numQuestions = Form.useWatch('num_questions');
8182
const datasetSize = Form.useWatch('num_questions');
@@ -108,6 +109,12 @@ const Prompt = () => {
108109
input_value,
109110
output_key
110111
);
112+
113+
console.log('values', form.getFieldsValue(true));
114+
console.log('values', form);
115+
console.log('workflow_type', workflow_type);
116+
console.log('useCase', useCase);
117+
console.log('dataset_size', dataset_size);
111118
const mutation = useMutation({
112119
mutationFn: fetchSeedList
113120
});
@@ -176,7 +183,7 @@ const Prompt = () => {
176183
isStepValid = true;
177184
}
178185
setIsStepValid(isStepValid)
179-
} else if(!isEmpty(doc_paths) && workflow_type === WorkflowType.SUPERVISED_FINE_TUNING) {
186+
} else if(!isEmpty(doc_paths) && workflow_type === WorkflowType.FREE_FORM_DATA_GENERATION) {
180187
setIsStepValid(isNumber(datasetSize) && datasetSize > 0);
181188
} else {
182189
setIsStepValid(true);
@@ -293,7 +300,7 @@ const Prompt = () => {
293300

294301

295302
</div>
296-
{((workflow_type === WorkflowType.CUSTOM_DATA_GENERATION && !isEmpty(doc_paths)) ||
303+
{((workflow_type === WorkflowType.FREE_FORM_DATA_GENERATION && !isEmpty(doc_paths)) ||
297304
(workflow_type === WorkflowType.SUPERVISED_FINE_TUNING && !isEmpty(doc_paths))) &&
298305
<StyledFormItem
299306
name={'num_questions'}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ const TopicsTable: FC<TopicsTableProps> = ({ formData, topic }) => {
5252
render: (_text: QuestionSolution, record: QuestionSolution) => <>{record.solution}</>
5353
},
5454
]
55-
const dataSource = formData.results[topic]
55+
console.log('topic', topic);
56+
const dataSource = formData.results[topic];
57+
console.log('dataSource', dataSource);
5658
return (
5759
<StyledTable
5860
columns={cols}
@@ -87,12 +89,14 @@ interface SuccessProps {
8789
isDemo?: boolean;
8890
}
8991
const Success: FC<SuccessProps> = ({ formData, isDemo = true }) => {
92+
console.log('Success', formData);
9093
const topicTabs = formData?.results && Object.keys(formData.results).map((topic, i) => ({
9194
key: `tab-${i}`,
9295
label: <Popover content={topic}><Text>{topic}</Text></Popover>,
9396
value: topic.replace(/\n/g, ' '),
9497
children: <TopicsTable formData={formData} topic={topic} />
9598
}));
99+
console.log('topicTabs', topicTabs);
96100
const nextStepsList = [
97101
{
98102
avatar: '',

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import get from "lodash/get";
66

77
interface Props {
88
form: FormInstance<any>;
9+
hidden?: boolean;
910
}
1011

1112

12-
const UseCaseSelector: FunctionComponent<Props> = ({ form }) => {
13+
const UseCaseSelector: FunctionComponent<Props> = ({ form, hidden }) => {
1314
const [useCases, setUseCases] = useState<UseCase[]>([]);
1415
const useCasesReq = useGetUseCases();
1516

@@ -45,6 +46,7 @@ const UseCaseSelector: FunctionComponent<Props> = ({ form }) => {
4546
labelCol={{
4647
span: 8
4748
}}
49+
hidden={hidden}
4850
shouldUpdate
4951
>
5052
<Select placeholder={'Select a template'} onChange={onChange}>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export const useDatasetSize = (
213213
input_value: string,
214214
output_key: string
215215
) => {
216-
if (workflow_type !== WorkflowType.CUSTOM_DATA_GENERATION || isEmpty(doc_paths)) {
216+
if (workflow_type !== WorkflowType.CUSTOM_DATA_GENERATION && isEmpty(doc_paths)) {
217217
return {
218218
data: 0
219219
}

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,11 @@ export const getHttpStatusCodeVerb = (statusCode: number) => {
109109

110110
export const getWizardModeType = (location: any) => {
111111
const pathname = location?.pathname || '';
112-
switch (pathname) {
113-
case '/data-augmentation':
114-
return WizardModeType.DATA_AUGMENTATION;
115-
case '/data-generator':
116-
return WizardModeType.DATA_GENERATION;
117-
default:
118-
return null;
112+
console.log('pathname', pathname);
113+
if (pathname.includes('/data-augmentation')) {
114+
return WizardModeType.DATA_AUGMENTATION;
115+
} else if (pathname.includes('/data-generator')) {
116+
return WizardModeType.DATA_GENERATION;
119117
}
118+
return null;
120119
}

0 commit comments

Comments
 (0)