Skip to content

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

feat: load generations table i/o individually (#1364)

Max Deichmann87e04a3482cd
diff --git a/web/src/components/table/use-cases/generations.tsx b/web/src/components/table/use-cases/generations.tsx
index 528f79fd8b..f179828d14 100644
--- a/web/src/components/table/use-cases/generations.tsx
+++ b/web/src/components/table/use-cases/generations.tsx
@@ -34,7 +34,7 @@ import { type LangfuseColumnDef } from "@/src/components/table/types";
import { type ObservationLevel } from "@prisma/client";
import { cn } from "@/src/utils/tailwind";
import { LevelColors } from "@/src/components/level-colors";
-import { usdFormatter } from "@/src/utils/numbers";
+import { randomIntFromInterval, usdFormatter } from "@/src/utils/numbers";
import {
exportOptions,
type ExportFileFormats,
@@ -42,6 +42,8 @@ import {
import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";
import type Decimal from "decimal.js";
import { type ScoreSimplified } from "@/src/server/api/routers/generations/getAllQuery";
+import { Skeleton } from "@/src/components/ui/skeleton";
+import React from "react";
export type GenerationsTableRow = {
id: string;
@@ -410,8 +412,11 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
accessorKey: "input",
header: "Input",
cell: ({ row }) => {
- const value: unknown = row.getValue("input");
- return <JSONView json={value} className="w-[500px]" />;
+ const observationId: string = row.getValue("id");
+ const traceId: string = row.getValue("traceId");
+ return (
+ <IOCell observationId={observationId} traceId={traceId} io="input" />
+ );
},
enableHiding: true,
defaultHidden: true,
@@ -420,8 +425,11 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
accessorKey: "output",
header: "Output",
cell: ({ row }) => {
- const value: unknown = row.getValue("output");
- return <JSONView json={value} className="w-[500px] bg-green-50" />;
+ const observationId: string = row.getValue("id");
+ const traceId: string = row.getValue("traceId");
+ return (
+ <IOCell observationId={observationId} traceId={traceId} io="output" />
+ );
},
enableHiding: true,
defaultHidden: true,
@@ -600,3 +608,73 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
</div>
);
}
+
+const IOCell = ({
+ traceId,
+ observationId,
+ io,
+}: {
+ traceId: string;
+ observationId: string;
+ io: "input" | "output";
+}) => {
+ const observation = api.observations.byId.useQuery(
+ {
+ observationId: observationId,
+ traceId: traceId,
+ },
+ {
+ enabled: typeof traceId === "string" && typeof observationId === "string",
+ trpc: {
+ context: {
+ skipBatch: true,
+ },
+ },
+ },
+ );
+ return (
+ <>
+ {observation.isLoading || !observation.data ? (
+ <JsonSkeleton className="h-[250px] w-[500px] px-3 py-1" />
+ ) : (
+ <JSONView
+ json={
+ io === "output" ? observation.data.output : observation.data.input
+ }
+ className="h-[250px] w-[500px] overflow-y-auto"
+ />
+ )}
+ </>
+ );
+};
+
+export const JsonSkeleton = ({
+ className,
+ numRows = 10,
+}: {
+ numRows?: number;
+ className?: string;
+}) => {
+ const sizingOptions = [
+ "h-5 w-full",
+ "h-5 w-[400px]",
+ "h-5 w-[450px]",
+ "h-5 w-[475px]",
+ ];
+
+ const generateRandomSize = () =>
+ sizingOptions[randomIntFromInterval(0, sizingOptions.length - 1)];
+
+ return (
+ <div className={cn("w-[500px] rounded-md border", className)}>
+ <div className="flex flex-col gap-1">
+ {[...Array<number>(numRows)].map((_) => (
+ <>
+ <Skeleton className={generateRandomSize()} />
+ </>
+ ))}
+ <br />
+ </div>
+ </div>
+ );
+};
diff --git a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
index 1d0c508961..e8aca0b5c4 100644
--- a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
+++ b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
@@ -96,8 +96,7 @@ export function getAllGenerationsSqlQuery({
o."modelParameters",
o.start_time as "startTime",
o.end_time as "endTime",
- o.input,
- o.output,
+ ${type === "export" ? Prisma.sql`o.input, o.output,` : Prisma.empty}
o.metadata,
o.trace_id as "traceId",
t.name as "traceName",
@@ -157,8 +156,7 @@ export function getAllGenerationsSqlQuery({
o. "modelParameters",
o. "startTime",
o. "endTime",
- o.input,
- o.output,
+ ${type === "export" ? Prisma.sql`o.input, o.output,` : Prisma.empty}
o.metadata,
o."traceId",
o."traceName",
diff --git a/web/src/utils/numbers.ts b/web/src/utils/numbers.ts
index 4795cf95cb..46927798e7 100644
--- a/web/src/utils/numbers.ts
+++ b/web/src/utils/numbers.ts
@@ -29,3 +29,7 @@ export const usdFormatter = (
maximumFractionDigits,
}).format(number);
};
+
+export function randomIntFromInterval(min: number, max: number) {
+ return Math.floor(Math.random() * (max - min + 1) + min);
+}