Skip to content
Snippets Groups Projects
Commit 1ee8db1f authored by sanjaycal's avatar sanjaycal
Browse files

Be able to add training recipes to the workflow(though I still need to have it...

Be able to add training recipes to the workflow(though I still need to have it run those in the API)
parent 25634956
No related branches found
No related tags found
No related merge requests found
...@@ -9,42 +9,106 @@ import { ...@@ -9,42 +9,106 @@ import {
Modal, Modal,
ModalClose, ModalClose,
ModalDialog, ModalDialog,
Option,
Select,
Stack, Stack,
Textarea, Textarea,
} from '@mui/joy'; } from '@mui/joy';
import { useState } from 'react'; import { useState } from 'react';
import * as chatAPI from 'renderer/lib/transformerlab-api-sdk'; import * as chatAPI from 'renderer/lib/transformerlab-api-sdk';
import useSWR from 'swr';
import { node } from 'webpack';
export default function NewNodeModal({ open, onClose, workflowId }) { const fetcher = (url: any) => fetch(url).then((res) => res.json());
const [state, setState] = useState(null);
export default function NewNodeModal({ open, onClose, selectedWorkflow }) {
const [mode, setMode] = useState('OTHER');
console.log(mode);
const {
data: trainingTemplatesData,
error: trainingTemplatesError,
isLoading: isLoading,
} = useSWR(chatAPI.GET_TRAINING_TEMPLATE_URL(), fetcher);
const {
data: workflowsData,
error: workflowsError,
isLoading: workflowsIsLoading,
} = useSWR(chatAPI.Endpoints.Workflows.List(), fetcher);
console.log(trainingTemplatesData);
const handleModeChange = (event: React.ChangeEvent<HTMLSelectElement>) => {
setMode(event.target.outerText);
};
return ( return (
<Modal open={open} onClose={() => onClose()}> <Modal open={open} onClose={() => onClose()}>
<ModalDialog> <ModalDialog>
<ModalClose /> <ModalClose />
<DialogTitle>Create new Node</DialogTitle> <DialogTitle>Create new Node</DialogTitle>
<DialogContent>Fill in the information.</DialogContent> <DialogContent>text</DialogContent>
<form <form
onSubmit={async (event: React.FormEvent<HTMLFormElement>) => { onSubmit={async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault(); event.preventDefault();
const formData = new FormData(event.currentTarget); const formData = new FormData(event.currentTarget);
const node = formData.get('node') as string; const name = formData.get('name') as string;
//const nodes = formData.get('nodes') as string; if (mode == 'TRAIN') {
await fetch( const template = formData.get('trainingTemplate') as string;
chatAPI.Endpoints.Workflows.AddNode( const config = JSON.parse(selectedWorkflow.config);
workflowId, console.log(config);
node const node = {
) name: name,
); type: 'TRAIN',
out: (config.nodes.length + 1).toString(),
template: template,
};
await fetch(
chatAPI.Endpoints.Workflows.AddNode(
selectedWorkflow.id,
JSON.stringify(node)
)
);
} else {
const node = JSON.parse(formData.get('node') as string);
node.name = name;
await fetch(
chatAPI.Endpoints.Workflows.AddNode(
selectedWorkflow.id,
JSON.stringify(node)
)
);
}
onClose(); onClose();
}} }}
> >
<Stack spacing={2}> <Stack spacing={2}>
<FormControl> <Select
<FormLabel>Nodes</FormLabel> labelId="mode-label"
<Textarea minRows={4} autoFocus required name="node" /> id="mode-select"
</FormControl> value={mode}
onChange={handleModeChange}
>
<Option value="OTHER">OTHER</Option>
<Option value="TRAIN">TRAIN</Option>
</Select>
<FormLabel>Name</FormLabel>
<Textarea minRows={4} autoFocus required name="name" />
{mode == 'TRAIN' ? (
<Select name="trainingTemplate">
{trainingTemplatesData.map((template) => (
<Option value={template[1]}>{template[1]}</Option>
))}
</Select>
) : (
<FormControl>
<FormLabel>Nodes</FormLabel>
<Textarea minRows={4} autoFocus required name="node" />
</FormControl>
)}
<Button type="submit">Submit</Button> <Button type="submit">Submit</Button>
</Stack> </Stack>
</form> </form>
......
...@@ -74,7 +74,7 @@ export default function Workflows({ experimentInfo }) { ...@@ -74,7 +74,7 @@ export default function Workflows({ experimentInfo }) {
setNewNodeflowModalOpen(false); setNewNodeflowModalOpen(false);
mutateWorkflows(); mutateWorkflows();
}} }}
workflowId={selectedWorkflow?.id} selectedWorkflow={selectedWorkflow}
/> />
)} )}
<Typography level="h1">Workflows</Typography> <Typography level="h1">Workflows</Typography>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment