Skip to content

Commit

Permalink
Merge pull request #247 from Scale3-Labs/dylan/s3en-2696-eval-deletion
Browse files Browse the repository at this point in the history
Adding ability to delete evaluation runs
  • Loading branch information
dylanzuber-scale3 committed Aug 27, 2024
2 parents 288d802 + be2dad7 commit dadc2a4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
ClipboardIcon,
FlaskConical,
RefreshCwIcon,
TrashIcon,
} from "lucide-react";
import Link from "next/link";
import { useParams, useRouter } from "next/navigation";
Expand Down Expand Up @@ -121,7 +122,7 @@ export default function Evaluations() {
});

const fetchExperiments = useQuery({
queryKey: ["fetch-experiments-query"],
queryKey: ["fetch-experiments-query", projectId, datasetId, page],
queryFn: async () => {
const response = await fetch(
`/api/run?projectId=${projectId}&datasetId=${datasetId}&page=${page}&pageSize=25`
Expand Down Expand Up @@ -167,6 +168,36 @@ export default function Evaluations() {
refetchOnWindowFocus: false,
});

const handleDeleteSelectedRuns = async () => {
if (comparisonRunIds.length === 0) return;

try {
const response = await fetch("/api/run", {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
runIds: comparisonRunIds,
projectId,
}),
});

if (!response.ok) {
const error = await response.json();
throw new Error(error?.message || "Failed to delete evaluations");
}

setComparisonRunIds([]);
await fetchExperiments.refetch();
toast.success("Selected evaluations deleted successfully.");
} catch (error) {
toast.error("Failed to delete evaluations", {
description: error instanceof Error ? error.message : String(error),
});
}
};

const columns: ColumnDef<Run>[] = [
{
size: 50,
Expand Down Expand Up @@ -438,6 +469,16 @@ export default function Evaluations() {
{viewMetrics ? "Hide Metrics" : "View Metrics"}
<AreaChartIcon className="h-4 w-4 ml-1" />
</Button>

{comparisonRunIds.length > 0 && (
<Button
variant="destructive"
size="icon"
onClick={handleDeleteSelectedRuns}
>
<TrashIcon className="h-4 w-4" />
</Button>
)}
</div>
<div className="flex items-center gap-2">
<Badge variant={"outline"} className="text-sm">
Expand Down
9 changes: 6 additions & 3 deletions app/api/run/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,14 @@ export async function DELETE(req: NextRequest) {
}

const data = await req.json();
const { id } = data;
const { runIds, projectId } = data;

await prisma.run.delete({
await prisma.run.deleteMany({
where: {
id,
runId: {
in: runIds,
},
projectId: projectId,
},
});

Expand Down

0 comments on commit dadc2a4

Please sign in to comment.