Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ability to delete evaluation runs #247

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@ 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,
}),
});

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 +468,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
8 changes: 5 additions & 3 deletions app/api/run/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,13 @@ export async function DELETE(req: NextRequest) {
}

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

await prisma.run.delete({
await prisma.run.deleteMany({
where: {
id,
runId: {
in: runIds,
},
dylanzuber-scale3 marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand Down