Skip to content
Snippets Groups Projects
Commit e68762e2 authored by ali asaria's avatar ali asaria
Browse files

split out eval tasks into separate component

parent 488ff45a
Branches
Tags
No related merge requests found
/* eslint-disable jsx-a11y/anchor-is-valid */ /* eslint-disable jsx-a11y/anchor-is-valid */
import { useRef, useState } from 'react'; import { useState } from 'react';
import useSWR from 'swr'; import useSWR from 'swr';
import * as chatAPI from 'renderer/lib/transformerlab-api-sdk'; import * as chatAPI from 'renderer/lib/transformerlab-api-sdk';
...@@ -8,67 +8,27 @@ import Sheet from '@mui/joy/Sheet'; ...@@ -8,67 +8,27 @@ import Sheet from '@mui/joy/Sheet';
import { import {
Button, Button,
Table,
Typography, Typography,
Modal, Modal,
ModalDialog, ModalDialog,
ModalClose, ModalClose,
DialogTitle,
DialogContent,
Stack, Stack,
FormControl, FormControl,
FormLabel, FormLabel,
Input, Input,
Option, Option,
Box,
IconButton,
Dropdown, Dropdown,
MenuButton, MenuButton,
Menu, Menu,
MenuItem, MenuItem,
Alert, Alert,
} from '@mui/joy'; } from '@mui/joy';
import { import { PlusCircleIcon } from 'lucide-react';
FileTextIcon,
PlayIcon,
PlusCircleIcon,
Trash2Icon,
XSquareIcon,
} from 'lucide-react';
import { generateFriendlyName } from 'renderer/lib/utils'; import { generateFriendlyName } from 'renderer/lib/utils';
import DynamicPluginForm from '../DynamicPluginForm'; import DynamicPluginForm from '../DynamicPluginForm';
import EvalJobsTable from './EvalJobsTable.tsx'; import EvalJobsTable from './EvalJobsTable.tsx';
const parseTmTheme = require('monaco-themes').parseTmTheme; import EvalTasksTable from './EvalTasksTable';
function listEvals(evalString) {
let result = [];
if (evalString) {
result = JSON.parse(evalString);
}
return result;
}
async function evaluationRun(
experimentId: string,
plugin: string,
evaluator: string
) {
// fetch(
// chatAPI.Endpoints.Experiment.RunEvaluation(experimentId, plugin, evaluator)
// );
await fetch(
chatAPI.Endpoints.Jobs.Create(
experimentId,
'EVAL',
'QUEUED',
JSON.stringify({
plugin: plugin,
evaluator: evaluator,
})
)
);
}
function getTemplateParametersForPlugin(pluginName, plugins) { function getTemplateParametersForPlugin(pluginName, plugins) {
if (!pluginName || !plugins) { if (!pluginName || !plugins) {
...@@ -206,7 +166,7 @@ export default function Eval({ ...@@ -206,7 +166,7 @@ export default function Eval({
<Dropdown> <Dropdown>
<MenuButton <MenuButton
startDecorator={<PlusCircleIcon />} startDecorator={<PlusCircleIcon />}
variant="soft" variant="outlined"
color="success" color="success"
sx={{ width: 'fit-content', mb: 1 }} sx={{ width: 'fit-content', mb: 1 }}
> >
...@@ -235,79 +195,10 @@ export default function Eval({ ...@@ -235,79 +195,10 @@ export default function Eval({
flex: 1, flex: 1,
}} }}
> >
<Table aria-label="basic table" stickyHeader> <EvalTasksTable
<thead> experimentInfo={experimentInfo}
<tr> experimentInfoMutate={experimentInfoMutate}
<th>Evaluator</th> />
<th style={{ width: '80px' }}>&nbsp;</th>
<th>Tasks</th>
<th>Plugin</th>
<th style={{ textAlign: 'right' }}>&nbsp;</th>
<th style={{ textAlign: 'right' }}>&nbsp;</th>
</tr>
</thead>
<tbody>
{listEvals(experimentInfo?.config?.evaluations) &&
listEvals(experimentInfo?.config?.evaluations)?.map(
(evaluations) => (
<tr key={evaluations.name}>
<td style={{ overflow: 'hidden' }}>{evaluations.name}</td>
<td>
{/* <Button
variant="soft"
onClick={() => {
setSelectedPlugin(evaluations.plugin);
setCurrentEvaluator(evaluations.name);
setEditModalOpen(true);
}}
>
Edit
</Button> */}
</td>
<td style={{ overflow: 'hidden' }}>
{evaluations?.script_parameters?.task}&nbsp;
<FileTextIcon size={14} />
</td>
<td>{evaluations.plugin}</td>
<td style={{ textAlign: 'right' }}>
{' '}
<Button
startDecorator={<PlayIcon />}
variant="soft"
color="success"
onClick={async () =>
await evaluationRun(
experimentInfo.id,
evaluations.plugin,
evaluations.name
)
}
>
Queue
</Button>
</td>
<td style={{ textAlign: 'right' }}>
<Stack direction="row">
<IconButton
onClick={async () => {
await fetch(
chatAPI.Endpoints.Experiment.DeleteEval(
experimentInfo.id,
evaluations.name
)
);
experimentInfoMutate();
}}
>
<Trash2Icon />
</IconButton>
</Stack>
</td>
</tr>
)
)}
</tbody>
</Table>
</Sheet> </Sheet>
<Sheet <Sheet
sx={{ sx={{
......
import { Button, IconButton, Stack, Table } from '@mui/joy';
import { FileTextIcon, PlayIcon, Trash2Icon } from 'lucide-react';
import * as chatAPI from 'renderer/lib/transformerlab-api-sdk';
function listEvals(evalString) {
let result = [];
if (evalString) {
result = JSON.parse(evalString);
}
return result;
}
async function evaluationRun(
experimentId: string,
plugin: string,
evaluator: string
) {
// fetch(
// chatAPI.Endpoints.Experiment.RunEvaluation(experimentId, plugin, evaluator)
// );
await fetch(
chatAPI.Endpoints.Jobs.Create(
experimentId,
'EVAL',
'QUEUED',
JSON.stringify({
plugin: plugin,
evaluator: evaluator,
})
)
);
}
export default function EvalTasksTable({
experimentInfo,
experimentInfoMutate,
}) {
return (
<>
<Table aria-label="basic table" stickyHeader>
<thead>
<tr>
<th>Evaluator</th>
<th style={{ width: '80px' }}>&nbsp;</th>
<th>Tasks</th>
<th>Plugin</th>
<th style={{ textAlign: 'right' }}>&nbsp;</th>
<th style={{ textAlign: 'right' }}>&nbsp;</th>
</tr>
</thead>
<tbody>
{listEvals(experimentInfo?.config?.evaluations) &&
listEvals(experimentInfo?.config?.evaluations)?.map(
(evaluations) => (
<tr key={evaluations.name}>
<td style={{ overflow: 'hidden' }}>{evaluations.name}</td>
<td>
{/* <Button
variant="soft"
onClick={() => {
setSelectedPlugin(evaluations.plugin);
setCurrentEvaluator(evaluations.name);
setEditModalOpen(true);
}}
>
Edit
</Button> */}
</td>
<td style={{ overflow: 'hidden' }}>
{evaluations?.script_parameters?.task}&nbsp;
<FileTextIcon size={14} />
</td>
<td>{evaluations.plugin}</td>
<td style={{ textAlign: 'right' }}>
<Button
startDecorator={<PlayIcon />}
variant="soft"
color="success"
onClick={async () =>
await evaluationRun(
experimentInfo.id,
evaluations.plugin,
evaluations.name
)
}
>
Queue
</Button>
</td>
<td style={{ textAlign: 'right' }}>
<Stack direction="row">
<IconButton
onClick={async () => {
await fetch(
chatAPI.Endpoints.Experiment.DeleteEval(
experimentInfo.id,
evaluations.name
)
);
experimentInfoMutate();
}}
>
<Trash2Icon />
</IconButton>
</Stack>
</td>
</tr>
)
)}
</tbody>
</Table>
</>
);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment