Skip to content

Commit d2fa5f4

Browse files
author
Keivan Vosoughi
committed
DSE-45299: Fetching Templates from SDS API for SDS UI
Add UseCaseSlector
1 parent d0cbed5 commit d2fa5f4

File tree

4 files changed

+89
-20
lines changed

4 files changed

+89
-20
lines changed

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { MODEL_PROVIDER_LABELS } from './constants';
1010
import { ModelProviders, ModelProvidersDropdownOpts } from './types';
1111
import { useWizardCtx } from './utils';
1212
import FileSelectorButton from './FileSelectorButton';
13+
import UseCaseSelector from './UseCaseSelector';
1314

1415

1516
const StepContainer = styled(Flex)`
@@ -224,24 +225,7 @@ const Configure = () => {
224225
</Form.Item>
225226
{(formData?.workflow_type === WorkflowType.SUPERVISED_FINE_TUNING ||
226227
formData?.workflow_type === WorkflowType.FREE_FORM_DATA_GENERATION) &&
227-
<Form.Item
228-
name='use_case'
229-
label='Template'
230-
rules={[
231-
{ required: true }
232-
]}
233-
tooltip='A specialize template for generating your dataset'
234-
labelCol={labelCol}
235-
shouldUpdate
236-
>
237-
<Select placeholder={'Select a template'}>
238-
{USECASE_OPTIONS.map(option =>
239-
<Select.Option key={option.value} value={option.value}>
240-
{option.label}
241-
</Select.Option>
242-
)}
243-
</Select>
244-
</Form.Item>}
228+
<UseCaseSelector />}
245229

246230
{(
247231
formData?.workflow_type === WorkflowType.SUPERVISED_FINE_TUNING ||
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { Form, Select } from "antd";
2+
import { FunctionComponent, useEffect, useState } from "react";
3+
import { useGetUseCases } from "./hooks";
4+
import { UseCase } from "../../types";
5+
import get from "lodash/get";
6+
7+
interface Props {}
8+
9+
10+
const UseCaseSelector: FunctionComponent<Props> = () => {
11+
const [useCases, setUseCases] = useState<UseCase[]>([]);
12+
const useCasesReq = useGetUseCases();
13+
console.log('useCasesReq', useCasesReq);
14+
15+
useEffect(() => {
16+
if (useCasesReq.data) {
17+
console.log('useCasesReq.data', useCasesReq.data);
18+
let _useCases = get(useCasesReq, 'data.usecases', []);
19+
_useCases = _useCases.map((useCase: any) => ({
20+
...useCase,
21+
label: useCase.name,
22+
value: useCase.id
23+
}));
24+
console.log('_useCases', _useCases);
25+
setUseCases(_useCases);
26+
}
27+
}, [useCasesReq.data]);
28+
29+
30+
return (
31+
<Form.Item
32+
name='use_case'
33+
label='Template'
34+
rules={[
35+
{ required: true }
36+
]}
37+
tooltip='A specialize template for generating your dataset'
38+
labelCol={{
39+
span: 8
40+
}}
41+
shouldUpdate
42+
>
43+
<Select placeholder={'Select a template'}>
44+
{useCases.map(option =>
45+
<Select.Option key={option.value} value={option.value}>
46+
{option.label}
47+
</Select.Option>
48+
)}
49+
</Select>
50+
</Form.Item>
51+
);
52+
}
53+
54+
export default UseCaseSelector;

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,28 @@ export const useDatasetSize = (
244244
isError,
245245
error
246246
};
247-
}
247+
}
248+
249+
export const fetchUseCases = async () => {
250+
const resp = await fetch(`${BASE_API_URL}/use-cases`, {
251+
method: 'GET'
252+
});
253+
const body = await resp.json();
254+
return body;
255+
}
256+
257+
export const useGetUseCases = () => {
258+
const { data, isLoading, isError, error, isFetching } = useQuery(
259+
{
260+
queryKey: ['fetchUseCases', fetchUseCases],
261+
queryFn: () => fetchUseCases(),
262+
refetchOnWindowFocus: false,
263+
}
264+
);
265+
return {
266+
data,
267+
isLoading: isLoading || isFetching,
268+
isError,
269+
error
270+
};
271+
}

app/client/src/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,11 @@ export const EXPORT_TYPE_LABELS: Record<ExportType, string> = {
4545
export type JobStatus = 'ENGINE_STOPPED' | 'ENGINE_SUCCEEDED' | 'ENGINE_TIMEDOUT' | 'ENGINE_SCHEDULING' | 'ENGINE_RUNNING' | 'null' | 'default';
4646

4747

48-
export const HuggingFaceIconUrl = "https://huggingface.co/front/assets/huggingface_logo-noborder.svg";
48+
export const HuggingFaceIconUrl = "https://huggingface.co/front/assets/huggingface_logo-noborder.svg";
49+
50+
export interface UseCase {
51+
name: string;
52+
id: string;
53+
label: string;
54+
value: string;
55+
}

0 commit comments

Comments
 (0)