🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
style(annotation): small UI/UX improvements (#2359)
marliessophie0396525f1b24
diff --git a/packages/shared/src/features/annotation/types.ts b/packages/shared/src/features/annotation/types.tsnew file mode 100644index 0000000000..c6f290c503--- /dev/null+++ b/packages/shared/src/features/annotation/types.ts@@ -0,0 +1,10 @@+import z from "zod";++const configCategory = z.object({+ label: z.string().min(1),+ value: z.number(),+});++export const categoriesList = z.array(configCategory);++export type ConfigCategory = z.infer<typeof configCategory>;diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.tsindex 3126425ec4..022334df8e 100644--- a/packages/shared/src/index.ts+++ b/packages/shared/src/index.ts@@ -21,6 +21,9 @@ export * from "./server/llm/fetchLLMCompletion";// evalsexport * from "./features/evals/types";+// annotation+export * from "./features/annotation/types";+// export db types onlyexport * from "@prisma/client";export { type DB } from "../prisma/generated/types";diff --git a/web/src/components/table/use-cases/score-configs.tsx b/web/src/components/table/use-cases/score-configs.tsxindex 1b77c35696..bd8ae98749 100644--- a/web/src/components/table/use-cases/score-configs.tsx+++ b/web/src/components/table/use-cases/score-configs.tsx@@ -6,10 +6,18 @@ import { api } from "@/src/utils/api";import { type LangfuseColumnDef } from "@/src/components/table/types";import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";import { DataTable } from "@/src/components/table/data-table";-import { type ScoreDataType, type Prisma } from "@langfuse/shared";+import {+ type ScoreDataType,+ type Prisma,+ type ConfigCategory,+} from "@langfuse/shared";import { IOTableCell } from "@/src/components/ui/CodeJsonViewer";import { NumberParam, useQueryParams, withDefault } from "use-query-params";-import { isNumericDataType } from "@/src/features/manual-scoring/lib/helpers";+import {+ isBooleanDataType,+ isCategoricalDataType,+ isNumericDataType,+} from "@/src/features/manual-scoring/lib/helpers";import { Archive } from "lucide-react";import { Button } from "@/src/components/ui/button";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";@@ -40,12 +48,25 @@ function getConfigRange(originalRow: ScoreConfigTableRow,): Prisma.JsonValue | undefined {const { range, dataType } = originalRow;+if (isNumericDataType(dataType)) {- return [- { minValue: range.minValue ?? "-∞", maxValue: range.maxValue ?? "∞" },- ];+ return {+ Minimum: range.minValue ?? "-∞",+ Maximum: range.maxValue ?? "∞",+ };+ }++ if (isCategoricalDataType(dataType) || isBooleanDataType(dataType)) {+ const configCategories = (range.categories as ConfigCategory[]) ?? [];++ return configCategories.reduce(+ (acc, category) => {+ acc[category.value] = category.label;+ return acc;+ },+ {} as Record<number, string>,+ );}- return range.categories;}export function ScoreConfigsTable({ projectId }: { projectId: string }) {@@ -215,7 +236,7 @@ export function ScoreConfigsTable({ projectId }: { projectId: string }) {rowHeight={rowHeight}setRowHeight={setRowHeight}/>- <Card className="mb-4 flex max-h-[calc(100dvh-40rem)] flex-col overflow-hidden">+ <Card className="mb-4 flex max-h-[calc(100dvh-30rem)] flex-col overflow-hidden"><DataTablecolumns={columns}data={diff --git a/web/src/components/table/use-cases/scores.tsx b/web/src/components/table/use-cases/scores.tsxindex c37aa9f44d..e23544d4ea 100644--- a/web/src/components/table/use-cases/scores.tsx+++ b/web/src/components/table/use-cases/scores.tsx@@ -241,6 +241,7 @@ export default function ScoresTable({accessorKey: "author",id: "author",header: "Author",+ enableHiding: true,cell: ({ row }) => {const { name, image } = row.getValue("author",diff --git a/web/src/components/ui/drawer.tsx b/web/src/components/ui/drawer.tsxindex e677b48b72..7f884faea9 100644--- a/web/src/components/ui/drawer.tsx+++ b/web/src/components/ui/drawer.tsx@@ -55,7 +55,7 @@ const DrawerContent = React.forwardRef<<DrawerPrimitive.Contentref={ref}className={cn(- "fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-[10px] border bg-background md:inset-x-auto md:inset-y-0 md:right-0 md:mt-0 md:h-full md:w-2/5 md:rounded-l-[10px] md:rounded-t-[0px] lg:w-1/3 xl:w-1/4 2xl:w-1/4",+ "fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-lg border bg-background md:inset-x-auto md:inset-y-0 md:right-0 md:mt-0 md:h-full md:w-1/2 md:rounded-l-lg md:rounded-r-none lg:w-2/5 xl:w-1/3 2xl:w-1/4",className,)}{...props}diff --git a/web/src/features/manual-scoring/components/AnnotateDrawer.tsx b/web/src/features/manual-scoring/components/AnnotateDrawer.tsxindex 46badf6555..f4f7b10594 100644--- a/web/src/features/manual-scoring/components/AnnotateDrawer.tsx+++ b/web/src/features/manual-scoring/components/AnnotateDrawer.tsx@@ -13,6 +13,7 @@ import {type ControllerRenderProps,useFieldArray,useForm,+ type ErrorOption,} from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import {@@ -29,7 +30,12 @@ import {DrawerHeader,DrawerTrigger,} from "@/src/components/ui/drawer";-import { ScoreDataType, type Score, type ScoreConfig } from "@langfuse/shared";+import {+ type ConfigCategory,+ ScoreDataType,+ type Score,+ type ScoreConfig,+} from "@langfuse/shared";import { z } from "zod";import { Input } from "@/src/components/ui/input";import {@@ -82,9 +88,40 @@ const AnnotateFormSchema = z.object({type AnnotateFormSchemaType = z.infer<typeof AnnotateFormSchema>;type AnnotationScoreSchemaType = z.infer<typeof AnnotationScoreDataSchema>;-type ConfigCategory = {- label: string;- value: string;++const CHAR_CUTOFF = 6;++const renderSelect = (categories: ConfigCategory[]) => {+ const hasMoreThanThreeCategories = categories.length > 3;+ const hasLongCategoryNames = categories.some(+ ({ label }) => label.length > CHAR_CUTOFF,+ );++ return (+ hasMoreThanThreeCategories ||+ (categories.length > 1 && hasLongCategoryNames)+ );+};++const getFormError = ({+ value,+ minValue,+ maxValue,+}: {+ value?: number | null;+ minValue?: number | null;+ maxValue?: number | null;+}): ErrorOption | null => {+ if (+ (isPresent(maxValue) && Number(value) > maxValue) ||+ (isPresent(minValue) && Number(value) < minValue)+ ) {+ return {+ type: "custom",+ message: `Not in range: [${minValue ?? "-∞"},${maxValue ?? "∞"}]`,+ };+ }+ return null;};export function AnnotateDrawer({@@ -120,7 +157,7 @@ export function AnnotateDrawer({string[]>("emptySelectedConfigIds", []);- const form = useForm<z.infer<typeof AnnotateFormSchema>>({+ const form = useForm<AnnotateFormSchemaType>({resolver: zodResolver(AnnotateFormSchema),defaultValues: {scoreData: getDefaultScoreData({@@ -357,14 +394,13 @@ export function AnnotateDrawer({const { maxValue, minValue, dataType } = config;if (isNumericDataType(dataType)) {- if (- (isPresent(maxValue) && Number(field.value) > maxValue) ||- (isPresent(minValue) && Number(field.value) < minValue)- ) {- form.setError(`scoreData.${index}.value`, {- type: "custom",- message: `Not in range: [${minValue ?? "-∞"},${maxValue ?? "∞"}]`,- });+ const formError = getFormError({+ value: field.value,+ maxValue,+ minValue,+ });+ if (!!formError) {+ form.setError(`scoreData.${index}.value`, formError);return;}}@@ -449,7 +485,7 @@ export function AnnotateDrawer({</DrawerTrigger><DrawerContent className="h-1/3"><div className="mx-auto w-full overflow-y-auto md:max-h-full">- <DrawerHeader className="sticky top-0 z-10 bg-background">+ <DrawerHeader className="sticky top-0 z-10 rounded-sm bg-background"><Headertitle="Annotate"level="h3"@@ -517,6 +553,8 @@ export function AnnotateDrawer({(config) => config.id === score.configId,);if (!config) return null;+ const categories =+ (config.categories as ConfigCategory[]) ?? [];return (<div@@ -540,7 +578,7 @@ export function AnnotateDrawer({{score.name}</span></HoverCardTrigger>- <HoverCardContent>+ <HoverCardContent className="z-20 max-h-[60vh] max-w-64 overflow-y-auto rounded border"><ScoreConfigDetails config={config} /></HoverCardContent></HoverCard>@@ -637,7 +675,7 @@ export function AnnotateDrawer({</Button><PopoverClose asChild><Button- variant="secondary"+ variant="destructive"type="button"size="sm"className="text-xs"@@ -687,7 +725,7 @@ export function AnnotateDrawer({</PopoverContent></Popover></div>- <div className="grid grid-cols-[11fr,1fr] items-center">+ <div className="grid grid-cols-[11fr,1fr] items-center py-1"><FormFieldcontrol={form.control}name={`scoreData.${index}.value`}@@ -708,20 +746,33 @@ export function AnnotateDrawer({score,})}onKeyDown={handleOnKeyDown}+ onKeyUp={() => {+ const formError = getFormError({+ value: field.value,+ maxValue: config.maxValue,+ minValue: config.minValue,+ });+ if (!!formError) {+ form.setError(+ `scoreData.${index}.value`,+ formError,+ );+ } else {+ form.clearErrors(+ `scoreData.${index}.value`,+ );+ }+ }}/>) : config.categories &&- (- (config.categories as ConfigCategory[]) ??- []- ).length > 2 ? (+ renderSelect(categories) ? (<SelectdefaultValue={score.stringValue}disabled={config.isArchived}onValueChange={handleOnValueChange(score,index,- (config.categories as ConfigCategory[]) ??- [],+ categories,)}><SelectTrigger>@@ -730,10 +781,7 @@ export function AnnotateDrawer({</div></SelectTrigger><SelectContent>- {(- (config.categories as ConfigCategory[]) ??- []- ).map(+ {categories.map((category: ConfigCategory) => (<SelectItemkey={category.value}@@ -751,33 +799,31 @@ export function AnnotateDrawer({type="single"defaultValue={score.stringValue}disabled={config.isArchived}- className={`grid grid-cols-${((config.categories as ConfigCategory[]) ?? [])?.length}`}+ className={`grid grid-cols-${categories.length}`}onValueChange={handleOnValueChange(score,index,- (config.categories as ConfigCategory[]) ??- [],+ categories,)}>- {(- (config.categories as ConfigCategory[]) ??- []- ).map((category: ConfigCategory) => (- <ToggleGroupItem- key={category.value}- value={category.label}- variant="outline"- className="grid grid-flow-col gap-1 text-nowrap px-1 text-xs font-normal"- >- <span- className="truncate"- title={category.label}+ {categories.map(+ (category: ConfigCategory) => (+ <ToggleGroupItem+ key={category.value}+ value={category.label}+ variant="outline"+ className="grid grid-flow-col gap-1 text-nowrap px-1 text-xs font-normal">- {category.label}- </span>- <span className="text-primary/60">{`(${category.value})`}</span>- </ToggleGroupItem>- ))}+ <span+ className="truncate"+ title={category.label}+ >+ {category.label}+ </span>+ <span className="text-primary/60">{`(${category.value})`}</span>+ </ToggleGroupItem>+ ),+ )}</ToggleGroup>)}</FormControl>diff --git a/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsx b/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsxindex 6af776e9db..e4f97f1a6c 100644--- a/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsx+++ b/web/src/features/manual-scoring/components/CreateScoreConfigButton.tsx@@ -130,7 +130,7 @@ export function CreateScoreConfigButton({ projectId }: { projectId: string }) {Add new score config</Button></DialogTrigger>- <DialogContent>+ <DialogContent className="max-h-[90vh] overflow-y-auto"><DialogHeader><DialogTitle>Add new score config</DialogTitle></DialogHeader>diff --git a/web/src/features/manual-scoring/components/ScoreConfigDetails.tsx b/web/src/features/manual-scoring/components/ScoreConfigDetails.tsxindex d216c3db1e..3087db2164 100644--- a/web/src/features/manual-scoring/components/ScoreConfigDetails.tsx+++ b/web/src/features/manual-scoring/components/ScoreConfigDetails.tsx@@ -7,11 +7,11 @@ import React from "react";export function ScoreConfigDetails({ config }: { config: ScoreConfig }) {const { name, description, minValue, maxValue, dataType } = config;- if (!description && !minValue && !maxValue) return null;+ if (!description && !isPresent(minValue) && !isPresent(maxValue)) return null;const isNameTruncated = name.length > 20;return (- <div className="max-w-48 overflow-hidden text-wrap rounded border bg-background p-2 text-xs font-light">+ <div className="text-wrap bg-background p-2 text-xs font-light">{!!description && <p>{`Description: ${description}`}</p>}{isNumericDataType(dataType) &&(isPresent(minValue) || isPresent(maxValue)) ? (diff --git a/web/src/server/api/routers/scoreConfigs.ts b/web/src/server/api/routers/scoreConfigs.tsindex 94c5e913b0..64b8c76944 100644--- a/web/src/server/api/routers/scoreConfigs.ts+++ b/web/src/server/api/routers/scoreConfigs.ts@@ -7,16 +7,12 @@ import { optionalPaginationZod } from "@langfuse/shared";import { ScoreDataType } from "@langfuse/shared/src/db";import { z } from "zod";+import { categoriesList } from "@langfuse/shared";const ScoreConfigAllInput = z.object({projectId: z.string(), // Required for protectedProjectProcedure});-const category = z.object({- label: z.string().min(1),- value: z.number(),-});-const ScoreConfigAllInputPaginated = ScoreConfigAllInput.extend({...optionalPaginationZod,});@@ -66,7 +62,7 @@ export const scoreConfigsRouter = createTRPCRouter({dataType: z.nativeEnum(ScoreDataType),minValue: z.number().optional(),maxValue: z.number().optional(),- categories: z.array(category).optional(),+ categories: categoriesList.optional(),description: z.string().optional(),}),)