Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(datasets): show linked evaluators on dataset (#4277)

marliessophie087f4a526b9a
diff --git a/web/src/ee/features/evals/components/template-form.tsx b/web/src/ee/features/evals/components/template-form.tsx
index 96464b17ae..dd0227ee60 100644
--- a/web/src/ee/features/evals/components/template-form.tsx
+++ b/web/src/ee/features/evals/components/template-form.tsx
@@ -293,7 +293,7 @@ export const InnerEvalTemplateForm = (props: {
});
const evaluatorsByTemplateNameQuery =
- api.evals.evaluatorsByTemplateName.useQuery(
+ api.evals.jobConfigsByTemplateName.useQuery(
{
projectId: props.projectId,
evalTemplateName: props.existingEvalTemplateName as string,
diff --git a/web/src/ee/features/evals/server/router.ts b/web/src/ee/features/evals/server/router.ts
index 662c0daf4c..22630c3ca6 100644
--- a/web/src/ee/features/evals/server/router.ts
+++ b/web/src/ee/features/evals/server/router.ts
@@ -12,6 +12,7 @@ import {
singleFilter,
variableMapping,
ChatMessageRole,
+ Prisma,
} from "@langfuse/shared";
import { decrypt } from "@langfuse/shared/encryption";
import { throwIfNoEntitlement } from "@/src/features/entitlements/server/hasEntitlement";
@@ -266,6 +267,8 @@ export const evalRouter = createTRPCRouter({
totalCount: count,
};
}),
+
+ // to be deprecated, only kept for cases of client side caching of routes
evaluatorsByTemplateName: protectedProjectProcedure
.input(z.object({ projectId: z.string(), evalTemplateName: z.string() }))
.query(async ({ input, ctx }) => {
@@ -311,6 +314,51 @@ export const evalRouter = createTRPCRouter({
}
}),
+ jobConfigsByTemplateName: protectedProjectProcedure
+ .input(z.object({ projectId: z.string(), evalTemplateName: z.string() }))
+ .query(async ({ input, ctx }) => {
+ try {
+ throwIfNoEntitlement({
+ entitlement: "model-based-evaluations",
+ projectId: input.projectId,
+ sessionUser: ctx.session.user,
+ });
+ throwIfNoProjectAccess({
+ session: ctx.session,
+ projectId: input.projectId,
+ scope: "evalJob:read",
+ });
+
+ const templates = await ctx.prisma.evalTemplate.findMany({
+ where: {
+ projectId: input.projectId,
+ name: input.evalTemplateName,
+ },
+ select: {
+ id: true,
+ },
+ });
+
+ return {
+ evaluators: await ctx.prisma.jobConfiguration.findMany({
+ where: {
+ projectId: input.projectId,
+ evalTemplateId: { in: templates.map((t) => t.id) },
+ },
+ }),
+ };
+ } catch (error) {
+ logger.error(error);
+ if (error instanceof TRPCError) {
+ throw error;
+ }
+ throw new TRPCError({
+ code: "INTERNAL_SERVER_ERROR",
+ message: "Fetching eval jobs for template failed.",
+ });
+ }
+ }),
+
createJob: protectedProjectProcedure
.input(
z.object({
@@ -600,4 +648,55 @@ export const evalRouter = createTRPCRouter({
totalCount: count,
};
}),
+
+ jobConfigsByDatasetId: protectedProjectProcedure
+ .input(z.object({ projectId: z.string(), datasetId: z.string() }))
+ .query(async ({ input, ctx }) => {
+ throwIfNoEntitlement({
+ entitlement: "model-based-evaluations",
+ projectId: input.projectId,
+ sessionUser: ctx.session.user,
+ });
+ throwIfNoProjectAccess({
+ session: ctx.session,
+ projectId: input.projectId,
+ scope: "evalJob:read",
+ });
+
+ // Get all evaluators (jobConfigs) for the project, refactor to reuse filter builder pattern in lfe-2887
+ const evaluators = await ctx.prisma.$queryRaw<
+ Array<{
+ id: string;
+ scoreName: string;
+ }>
+ >(Prisma.sql`
+ SELECT DISTINCT
+ jc.id,
+ jc.score_name as "scoreName"
+ FROM
+ "job_configurations" as jc
+ WHERE
+ jc.project_id = ${input.projectId}
+ AND jc.job_type = 'EVAL'
+ AND jc.target_object = 'dataset'
+ AND jc.status = 'ACTIVE'
+ AND (
+ jc.filter IS NULL
+ OR jsonb_array_length(jc.filter) = 0
+ OR EXISTS (
+ SELECT 1
+ FROM jsonb_array_elements(jc.filter) as f
+ WHERE f->>'column' = 'Dataset'
+ AND f->>'type' = 'stringOptions'
+ AND (
+ (f->>'operator' = 'any of' AND ${Prisma.sql`${input.datasetId}`}::text = ANY(SELECT jsonb_array_elements_text(f->'value')))
+ OR
+ (f->>'operator' = 'none of' AND NOT (${Prisma.sql`${input.datasetId}`}::text = ANY(SELECT jsonb_array_elements_text(f->'value'))))
+ )
+ )
+ )
+ `);
+
+ return evaluators;
+ }),
});
diff --git a/web/src/features/scores/components/multi-select-key-values.tsx b/web/src/features/scores/components/multi-select-key-values.tsx
index 5c4d8b9a5d..b3cd8df49f 100644
--- a/web/src/features/scores/components/multi-select-key-values.tsx
+++ b/web/src/features/scores/components/multi-select-key-values.tsx
@@ -41,6 +41,7 @@ export function MultiSelectKeyValues<
items = "items",
align = "center",
controlButtons,
+ hideClearButton = false,
}: {
title?: string;
placeholder?: string;
@@ -56,11 +57,12 @@ export function MultiSelectKeyValues<
items?: string;
align?: "center" | "end" | "start";
controlButtons?: React.ReactNode;
+ hideClearButton?: boolean;
}) {
const selectedValueKeys = new Set(
values.map((value) => (typeof value === "string" ? value : value.key)),
);
- const showClearItems = selectedValueKeys.size > 0;
+ const showClearItems = selectedValueKeys.size > 0 && !hideClearButton;
function formatFilterValues(): T[] {
if (values.length > 0 && typeof values[0] === "string") {
@@ -114,7 +116,7 @@ export function MultiSelectKeyValues<
<Badge
variant="secondary"
key={option.key}
- className="rounded-sm px-1 font-normal"
+ className="rounded-sm px-1 font-normal capitalize"
>
{option.value}
</Badge>
@@ -131,63 +133,67 @@ export function MultiSelectKeyValues<
<CommandList>
<CommandEmpty>No results found.</CommandEmpty>
<CommandGroup>
- {options.map((option) => {
- const isSelected = selectedValueKeys.has(
- option.key ?? option.value,
- );
- return (
- <CommandItem
- key={option.key ?? option.value}
- value={option.key ?? option.value}
- keywords={[option.value]}
- onSelect={(value) => {
- if (isSelected) {
- selectedValueKeys.delete(value);
- } else {
- selectedValueKeys.add(value);
- }
- const filterValues = formatFilterValues();
+ {Boolean(options.length) ? (
+ options.map((option) => {
+ const isSelected = selectedValueKeys.has(
+ option.key ?? option.value,
+ );
+ return (
+ <CommandItem
+ key={option.key ?? option.value}
+ value={option.key ?? option.value}
+ keywords={[option.value]}
+ onSelect={(value) => {
+ if (isSelected) {
+ selectedValueKeys.delete(value);
+ } else {
+ selectedValueKeys.add(value);
+ }
+ const filterValues = formatFilterValues();
- onValueChange(
- filterValues.length ? filterValues : [],
- value,
- selectedValueKeys,
- );
- }}
- disabled={option.disabled}
- >
- <div
- className={cn(
- "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
- isSelected
- ? "bg-primary text-primary-foreground"
- : "opacity-50 [&_svg]:invisible",
- option.disabled ? "opacity-50" : null,
- )}
- >
- <Check className="h-4 w-4" />
- </div>
- <span
- className={cn(
- "overflow-x-scroll",
- option.isArchived ? "text-foreground/50" : "",
- )}
+ onValueChange(
+ filterValues.length ? filterValues : [],
+ value,
+ selectedValueKeys,
+ );
+ }}
+ disabled={option.disabled}
>
- {option.value}
- </span>
- {option.isArchived ? (
- <div className="ml-1 mt-1 flex h-4 w-4">
- <Archive className="h-4 w-4 text-foreground/50"></Archive>
+ <div
+ className={cn(
+ "mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary",
+ isSelected
+ ? "bg-primary text-primary-foreground"
+ : "opacity-50 [&_svg]:invisible",
+ option.disabled ? "opacity-50" : null,
+ )}
+ >
+ <Check className="h-4 w-4" />
</div>
- ) : null}
- {option.count !== undefined ? (
- <span className="ml-auto flex h-4 w-4 items-center justify-center pl-1 font-mono text-xs">
- {option.count}
+ <span
+ className={cn(
+ "overflow-x-scroll capitalize",
+ option.isArchived ? "text-foreground/50" : "",
+ )}
+ >
+ {option.value}
</span>
- ) : null}
- </CommandItem>
- );
- })}
+ {option.isArchived ? (
+ <div className="ml-1 mt-1 flex h-4 w-4">
+ <Archive className="h-4 w-4 text-foreground/50"></Archive>
+ </div>
+ ) : null}
+ {option.count !== undefined ? (
+ <span className="ml-auto flex h-4 w-4 items-center justify-center pl-1 font-mono text-xs">
+ {option.count}
+ </span>
+ ) : null}
+ </CommandItem>
+ );
+ })
+ ) : (
+ <CommandItem disabled>No options found.</CommandItem>
+ )}
</CommandGroup>
{controlButtons || showClearItems ? (
<>
diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx
index 3757b47fda..8727842959 100644
--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx
+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx
@@ -11,17 +11,48 @@ import { JSONView } from "@/src/components/ui/CodeJsonViewer";
import { FullScreenPage } from "@/src/components/layouts/full-screen-page";
import { DuplicateDatasetButton } from "@/src/features/datasets/components/DuplicateDatasetButton";
+import { MultiSelectKeyValues } from "@/src/features/scores/components/multi-select-key-values";
+import { CommandItem } from "@/src/components/ui/command";
+import { ExternalLink } from "lucide-react";
+import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
+import { useMemo } from "react";
+import { useHasOrgEntitlement } from "@/src/features/entitlements/hooks";
+
export default function Dataset() {
const router = useRouter();
const projectId = router.query.projectId as string;
const datasetId = router.query.datasetId as string;
const utils = api.useUtils();
+ const hasEntitlement = useHasOrgEntitlement("model-based-evaluations");
const dataset = api.datasets.byId.useQuery({
datasetId,
projectId,
});
+ const hasReadAccess = useHasProjectAccess({
+ projectId,
+ scope: "evalJobExecution:read",
+ });
+
+ const evaluators = api.evals.jobConfigsByDatasetId.useQuery(
+ {
+ projectId,
+ datasetId,
+ },
+ {
+ enabled: hasReadAccess && hasEntitlement && dataset.isSuccess,
+ },
+ );
+
+ const evaluatorsOptions = useMemo(() => {
+ if (!evaluators.data) return [];
+ return evaluators.data?.map((evaluator) => ({
+ key: evaluator.id,
+ value: evaluator.scoreName,
+ }));
+ }, [evaluators.data]);
+
return (
<FullScreenPage>
<Header
@@ -39,6 +70,33 @@ export default function Dataset() {
}
actionButtons={
<>
+ {hasReadAccess && hasEntitlement && evaluators.isSuccess && (
+ <MultiSelectKeyValues
+ className="max-w-fit"
+ placeholder="Search..."
+ title="Evaluators"
+ hideClearButton
+ onValueChange={(_values, changedValue) => {
+ if (changedValue)
+ window.open(
+ `/project/${projectId}/evals/${changedValue}`,
+ "_blank",
+ );
+ }}
+ values={evaluatorsOptions}
+ options={evaluatorsOptions}
+ controlButtons={
+ <CommandItem
+ onSelect={() => {
+ window.open(`/project/${projectId}/evals`, "_blank");
+ }}
+ >
+ Manage evaluators
+ <ExternalLink className="ml-auto h-4 w-4" />
+ </CommandItem>
+ }
+ />
+ )}
<DetailPageNav
currentId={datasetId}
path={(entry) => `/project/${projectId}/datasets/${entry.id}`}