Reevaluate all prompt stats when scenario is hidden (#32)
* Reevaluate when scenario is hidden * Add newline
This commit is contained in:
@@ -5,7 +5,7 @@ import { type Scenario } from "./types";
|
|||||||
import { useExperiment, useHandledAsyncCallback } from "~/utils/hooks";
|
import { useExperiment, useHandledAsyncCallback } from "~/utils/hooks";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
import { Box, Button, Flex, HStack, Icon, Stack, Tooltip } from "@chakra-ui/react";
|
import { Box, Button, Flex, HStack, Icon, Spinner, Stack, Tooltip } from "@chakra-ui/react";
|
||||||
import { cellPadding } from "../constants";
|
import { cellPadding } from "../constants";
|
||||||
import { BsX } from "react-icons/bs";
|
import { BsX } from "react-icons/bs";
|
||||||
import { RiDraggable } from "react-icons/ri";
|
import { RiDraggable } from "react-icons/ri";
|
||||||
@@ -43,11 +43,12 @@ export default function ScenarioEditor({
|
|||||||
}, [mutation, values]);
|
}, [mutation, values]);
|
||||||
|
|
||||||
const hideMutation = api.scenarios.hide.useMutation();
|
const hideMutation = api.scenarios.hide.useMutation();
|
||||||
const [onHide] = useHandledAsyncCallback(async () => {
|
const [onHide, hidingInProgress] = useHandledAsyncCallback(async () => {
|
||||||
await hideMutation.mutateAsync({
|
await hideMutation.mutateAsync({
|
||||||
id: scenario.id,
|
id: scenario.id,
|
||||||
});
|
});
|
||||||
await utils.scenarios.list.invalidate();
|
await utils.scenarios.list.invalidate();
|
||||||
|
await utils.promptVariants.stats.invalidate();
|
||||||
}, [hideMutation, scenario.id]);
|
}, [hideMutation, scenario.id]);
|
||||||
|
|
||||||
const reorderMutation = api.scenarios.reorder.useMutation();
|
const reorderMutation = api.scenarios.reorder.useMutation();
|
||||||
@@ -106,7 +107,7 @@ export default function ScenarioEditor({
|
|||||||
cursor: "pointer",
|
cursor: "pointer",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Icon as={BsX} boxSize={6} />
|
<Icon as={hidingInProgress ? Spinner :BsX} boxSize={6} />
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Icon
|
<Icon
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
|
|||||||
import { prisma } from "~/server/db";
|
import { prisma } from "~/server/db";
|
||||||
import { autogenerateScenarioValues } from "../autogen";
|
import { autogenerateScenarioValues } from "../autogen";
|
||||||
import { recordExperimentUpdated } from "~/server/utils/recordExperimentUpdated";
|
import { recordExperimentUpdated } from "~/server/utils/recordExperimentUpdated";
|
||||||
|
import { reevaluateAll } from "~/server/utils/evaluations";
|
||||||
|
|
||||||
export const scenariosRouter = createTRPCRouter({
|
export const scenariosRouter = createTRPCRouter({
|
||||||
list: publicProcedure.input(z.object({ experimentId: z.string() })).query(async ({ input }) => {
|
list: publicProcedure.input(z.object({ experimentId: z.string() })).query(async ({ input }) => {
|
||||||
@@ -54,10 +55,15 @@ export const scenariosRouter = createTRPCRouter({
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
hide: publicProcedure.input(z.object({ id: z.string() })).mutation(async ({ input }) => {
|
hide: publicProcedure.input(z.object({ id: z.string() })).mutation(async ({ input }) => {
|
||||||
return await prisma.testScenario.update({
|
const hiddenScenario = await prisma.testScenario.update({
|
||||||
where: { id: input.id },
|
where: { id: input.id },
|
||||||
data: { visible: false, experiment: { update: { updatedAt: new Date() } } },
|
data: { visible: false, experiment: { update: { updatedAt: new Date() } } },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Reevaluate all evaluations now that this scenario is hidden
|
||||||
|
await reevaluateAll(hiddenScenario.experimentId);
|
||||||
|
|
||||||
|
return hiddenScenario;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
reorder: publicProcedure
|
reorder: publicProcedure
|
||||||
|
|||||||
@@ -89,3 +89,11 @@ export const reevaluateEvaluation = async (evaluation: Evaluation) => {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const reevaluateAll = async (experimentId: string) => {
|
||||||
|
const evaluations = await prisma.evaluation.findMany({
|
||||||
|
where: { experimentId },
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(evaluations.map(reevaluateEvaluation));
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user