Skip to content

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

fix: load traces IO individually (#1426)

Max Deichmann286a9592324d
diff --git a/packages/shared/src/server/llm/fetchLLMCompletion.ts b/packages/shared/src/server/llm/fetchLLMCompletion.ts
index df120d5b62..a21a8f9547 100644
--- a/packages/shared/src/server/llm/fetchLLMCompletion.ts
+++ b/packages/shared/src/server/llm/fetchLLMCompletion.ts
@@ -16,7 +16,6 @@ import {
} from "@langchain/core/output_parsers";
import { ChatOpenAI } from "@langchain/openai";
-console.log("fetchLLMCompletion.ts");
type LLMCompletionParams = {
messages: ChatMessage[];
modelParams: ModelParams;
diff --git a/web/src/components/table/use-cases/IOCell.tsx b/web/src/components/table/use-cases/IOCell.tsx
new file mode 100644
index 0000000000..95482547ca
--- /dev/null
+++ b/web/src/components/table/use-cases/IOCell.tsx
@@ -0,0 +1,54 @@
+import { JSONView } from "@/src/components/ui/code";
+import { cn } from "@/src/utils/tailwind";
+import { randomIntFromInterval } from "@/src/utils/numbers";
+import { Skeleton } from "@/src/components/ui/skeleton";
+import React from "react";
+
+export const IOCell = ({
+ isLoading,
+ data,
+}: {
+ isLoading: boolean;
+ data: unknown;
+}) => {
+ return (
+ <>
+ {isLoading ? (
+ <JsonSkeleton className="h-[250px] w-[500px] px-3 py-1" />
+ ) : (
+ <JSONView json={data} 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/components/table/use-cases/generations.tsx b/web/src/components/table/use-cases/generations.tsx
index 8375188238..c30d78b4e8 100644
--- a/web/src/components/table/use-cases/generations.tsx
+++ b/web/src/components/table/use-cases/generations.tsx
@@ -29,12 +29,11 @@ import {
utcDateOffsetByDays,
} from "@/src/utils/dates";
import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";
-import { JSONView } from "@/src/components/ui/code";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { type ObservationLevel } from "@langfuse/shared/src/db";
import { cn } from "@/src/utils/tailwind";
import { LevelColors } from "@/src/components/level-colors";
-import { randomIntFromInterval, usdFormatter } from "@/src/utils/numbers";
+import { usdFormatter } from "@/src/utils/numbers";
import {
exportOptions,
type ExportFileFormats,
@@ -42,8 +41,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";
+import { IOCell } from "./IOCell";
+import { setSmallPaginationIfColumnsVisible } from "../../../features/column-visibility/hooks/setSmallPaginationIfColumnsVisible";
export type GenerationsTableRow = {
id: string;
@@ -415,7 +414,11 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
const observationId: string = row.getValue("id");
const traceId: string = row.getValue("traceId");
return (
- <IOCell observationId={observationId} traceId={traceId} io="input" />
+ <GenerationsIOCell
+ observationId={observationId}
+ traceId={traceId}
+ io="input"
+ />
);
},
enableHiding: true,
@@ -428,7 +431,11 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
const observationId: string = row.getValue("id");
const traceId: string = row.getValue("traceId");
return (
- <IOCell observationId={observationId} traceId={traceId} io="output" />
+ <GenerationsIOCell
+ observationId={observationId}
+ traceId={traceId}
+ io="output"
+ />
);
},
enableHiding: true,
@@ -480,17 +487,12 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
columns,
);
- const smallTableRequired =
- columnVisibility["input"] === true || columnVisibility["output"] === true;
-
- if (smallTableRequired && paginationState.pageSize !== 10) {
- setPaginationState((prev) => {
- const currentPage = prev.pageIndex;
- const currentPageSize = prev.pageSize;
- const newPageIndex = Math.floor((currentPage * currentPageSize) / 10);
- return { pageIndex: newPageIndex, pageSize: 10 };
- });
- }
+ const smallTableRequired = setSmallPaginationIfColumnsVisible(
+ columnVisibility,
+ ["input", "output"],
+ paginationState,
+ setPaginationState,
+ );
const rows: GenerationsTableRow[] = generations.isSuccess
? generations.data.generations.map((generation) => {
@@ -609,7 +611,7 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
);
}
-const IOCell = ({
+const GenerationsIOCell = ({
traceId,
observationId,
io,
@@ -633,48 +635,11 @@ const IOCell = ({
},
);
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>
+ <IOCell
+ isLoading={observation.isLoading}
+ data={
+ io === "output" ? observation.data?.output : observation.data?.input
+ }
+ />
);
};
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index 3812eb63c1..0af08f8924 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -8,7 +8,6 @@ import { type LangfuseColumnDef } from "@/src/components/table/types";
import { TagTracePopver } from "@/src/features/tag/components/TagTracePopver";
import { TokenUsageBadge } from "@/src/components/token-usage-badge";
import { Checkbox } from "@/src/components/ui/checkbox";
-import { JSONView } from "@/src/components/ui/code";
import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";
import { useQueryFilterState } from "@/src/features/filters/hooks/useFilterState";
import { type FilterState } from "@/src/features/filters/types";
@@ -33,6 +32,8 @@ import { usdFormatter } from "@/src/utils/numbers";
import { DeleteButton } from "@/src/components/deleteButton";
import { LevelColors } from "@/src/components/level-colors";
import { cn } from "@/src/utils/tailwind";
+import { IOCell } from "./IOCell";
+import { setSmallPaginationIfColumnsVisible } from "@/src/features/column-visibility/hooks/setSmallPaginationIfColumnsVisible";
export type TracesTableRow = {
bookmarked: boolean;
@@ -438,8 +439,10 @@ export default function TracesTable({
accessorKey: "input",
header: "Input",
cell: ({ row }) => {
- const value: unknown = row.getValue("input");
- return <JSONView json={value} className="w-[500px]" />;
+ const traceId: string = row.getValue("id");
+ return (
+ <TracesIOCell traceId={traceId} projectId={projectId} io="input" />
+ );
},
enableHiding: true,
defaultHidden: true,
@@ -448,8 +451,10 @@ export default function TracesTable({
accessorKey: "output",
header: "Output",
cell: ({ row }) => {
- const value: unknown = row.getValue("output");
- return <JSONView json={value} className="w-[500px] bg-green-50" />;
+ const traceId: string = row.getValue("id");
+ return (
+ <TracesIOCell traceId={traceId} projectId={projectId} io="output" />
+ );
},
enableHiding: true,
defaultHidden: true,
@@ -540,6 +545,13 @@ export default function TracesTable({
const [columnVisibility, setColumnVisibility] =
useColumnVisibility<TracesTableRow>("tracesColumnVisibility", columns);
+ const smallTableRequired = setSmallPaginationIfColumnsVisible(
+ columnVisibility,
+ ["input", "output"],
+ paginationState,
+ setPaginationState,
+ );
+
return (
<div>
<DataTableToolbar
@@ -590,6 +602,7 @@ export default function TracesTable({
pageCount: Math.ceil(Number(totalCount) / paginationState.pageSize),
onChange: setPaginationState,
state: paginationState,
+ options: smallTableRequired ? [10] : undefined,
}}
setOrderBy={setOrderByState}
orderBy={orderByState}
@@ -601,3 +614,49 @@ export default function TracesTable({
</div>
);
}
+
+const TracesIOCell = ({
+ projectId,
+ traceId,
+ io,
+}: {
+ projectId: string;
+ traceId: string;
+ io: "input" | "output";
+}) => {
+ const trace = api.traces.all.useQuery(
+ {
+ projectId: projectId,
+ filter: [
+ {
+ column: "id",
+ type: "string",
+ operator: "=",
+ value: traceId,
+ },
+ ],
+ searchQuery: null,
+ orderBy: null,
+ page: 0,
+ limit: 1,
+ },
+ {
+ enabled: typeof traceId === "string",
+ trpc: {
+ context: {
+ skipBatch: true,
+ },
+ },
+ },
+ );
+ return (
+ <IOCell
+ isLoading={trace.isLoading}
+ data={
+ io === "output"
+ ? trace.data?.traces[0]?.output
+ : trace.data?.traces[0]?.input
+ }
+ />
+ );
+};
diff --git a/web/src/features/column-visibility/hooks/setSmallPaginationIfColumnsVisible.tsx b/web/src/features/column-visibility/hooks/setSmallPaginationIfColumnsVisible.tsx
new file mode 100644
index 0000000000..15aabdfc24
--- /dev/null
+++ b/web/src/features/column-visibility/hooks/setSmallPaginationIfColumnsVisible.tsx
@@ -0,0 +1,32 @@
+import { type LangfuseColumnDef } from "@/src/components/table/types";
+import React from "react";
+import { TracesTableRow } from "@/src/components/table/use-cases/traces";
+import { GenerationsTableRow } from "../../../components/table/use-cases/generations";
+
+export type TableColumn =
+ | (keyof GenerationsTableRow)[]
+ | (keyof TracesTableRow)[];
+
+export function setSmallPaginationIfColumnsVisible(
+ columnVisibility: Record<string, boolean>,
+ columnsRequiringSmallTable: TableColumn,
+
+ paginationState: { pageIndex: number; pageSize: number },
+ setPaginationState: React.Dispatch<
+ React.SetStateAction<{ pageIndex: number; pageSize: number }>
+ >,
+) {
+ const smallTableRequired = columnsRequiringSmallTable.some(
+ (column) => columnVisibility[column] === true,
+ );
+
+ if (smallTableRequired && paginationState.pageSize !== 10) {
+ setPaginationState((prev) => {
+ const currentPage = prev.pageIndex;
+ const currentPageSize = prev.pageSize;
+ const newPageIndex = Math.floor((currentPage * currentPageSize) / 10);
+ return { pageIndex: newPageIndex, pageSize: 10 };
+ });
+ }
+ return smallTableRequired;
+}