From 7fe594cf1e2119241c6612775b9e788a771c655e Mon Sep 17 00:00:00 2001 From: Mikyo King Date: Mon, 27 Nov 2023 15:08:16 -0700 Subject: [PATCH 1/2] feat(evals): display span evaluations --- app/package-lock.json | 2 +- app/package.json | 2 +- app/src/components/table/styles.ts | 4 +- app/src/pages/trace/SpanEvaluationsTable.tsx | 116 +++++ app/src/pages/trace/TracePage.tsx | 24 +- .../SpanEvaluationsTable_evals.graphql.ts | 79 ++++ .../__generated__/TracePageQuery.graphql.ts | 435 +++++++++++------- app/src/pages/tracing/SpansTable.tsx | 1 - 8 files changed, 488 insertions(+), 175 deletions(-) create mode 100644 app/src/pages/trace/SpanEvaluationsTable.tsx create mode 100644 app/src/pages/trace/__generated__/SpanEvaluationsTable_evals.graphql.ts diff --git a/app/package-lock.json b/app/package-lock.json index 929e15de61..10e4671d33 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -17,7 +17,7 @@ "@codemirror/view": "^6.16.0", "@react-three/drei": "9.5.7", "@react-three/fiber": "8.0.12", - "@tanstack/react-table": "^8.9.3", + "@tanstack/react-table": "^8.10.7", "@uiw/codemirror-theme-nord": "^4.21.9", "@uiw/react-codemirror": "^4.21.9", "d3-format": "^3.1.0", diff --git a/app/package.json b/app/package.json index 1ef1bc1c77..a42466a21a 100644 --- a/app/package.json +++ b/app/package.json @@ -14,7 +14,7 @@ "@codemirror/view": "^6.16.0", "@react-three/drei": "9.5.7", "@react-three/fiber": "8.0.12", - "@tanstack/react-table": "^8.9.3", + "@tanstack/react-table": "^8.10.7", "@uiw/codemirror-theme-nord": "^4.21.9", "@uiw/react-codemirror": "^4.21.9", "d3-format": "^3.1.0", diff --git a/app/src/components/table/styles.ts b/app/src/components/table/styles.ts index 237c4d5d4d..27add98ace 100644 --- a/app/src/components/table/styles.ts +++ b/app/src/components/table/styles.ts @@ -47,10 +47,10 @@ export const tableCSS = (theme: Theme) => css` tbody:not(.is-empty) { tr { &:nth-of-type(even) { - background-color: var(--ac-global-color-grey-100); + background-color: var(--ac-global-color-grey-200); } &:hover { - background-color: var(--ac-global-color-grey-200); + background-color: var(--ac-global-color-grey-300); } & > td { padding: ${theme.spacing.margin8}px ${theme.spacing.margin16}px; diff --git a/app/src/pages/trace/SpanEvaluationsTable.tsx b/app/src/pages/trace/SpanEvaluationsTable.tsx new file mode 100644 index 0000000000..e08ed8a2d2 --- /dev/null +++ b/app/src/pages/trace/SpanEvaluationsTable.tsx @@ -0,0 +1,116 @@ +import React, { useMemo } from "react"; +import { graphql, useFragment } from "react-relay"; +import { + flexRender, + getCoreRowModel, + useReactTable, +} from "@tanstack/react-table"; + +import { TextCell } from "@phoenix/components/table"; +import { tableCSS } from "@phoenix/components/table/styles"; +import { TableEmpty } from "@phoenix/components/table/TableEmpty"; + +import { SpanEvaluationsTable_evals$key } from "./__generated__/SpanEvaluationsTable_evals.graphql"; + +const columns = [ + { + header: "name", + accessorKey: "name", + size: 100, + }, + { + header: "label", + accessorKey: "label", + size: 100, + }, + { + header: "score", + accessorKey: "score", + size: 100, + }, + { + header: "explanation", + accessorKey: "explanation", + Cell: TextCell, + size: 500, + }, +]; + +export function SpanEvaluationsTable(props: { + span: SpanEvaluationsTable_evals$key; +}) { + const data = useFragment( + graphql` + fragment SpanEvaluationsTable_evals on Span { + spanEvaluations { + name + label + score + explanation + } + } + `, + props.span + ); + const evaluations = useMemo(() => { + return [...data.spanEvaluations]; + }, [data.spanEvaluations]); + + const table = useReactTable({ + columns, + data: evaluations, + getCoreRowModel: getCoreRowModel(), + }); + const rows = table.getRowModel().rows; + const isEmpty = rows.length === 0; + + return ( + + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => ( + + ))} + + ))} + + {isEmpty ? ( + + ) : ( + + {table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + ))} + + ))} + + )} +
+ {header.isPlaceholder ? null : ( +
+ {flexRender( + header.column.columnDef.header, + header.getContext() + )} +
+ )} +
+ {flexRender(cell.column.columnDef.cell, cell.getContext())} +
+ ); +} diff --git a/app/src/pages/trace/TracePage.tsx b/app/src/pages/trace/TracePage.tsx index 628d7bca37..302040edee 100644 --- a/app/src/pages/trace/TracePage.tsx +++ b/app/src/pages/trace/TracePage.tsx @@ -75,6 +75,7 @@ import { TracePageQuery, TracePageQuery$data, } from "./__generated__/TracePageQuery.graphql"; +import { SpanEvaluationsTable } from "./SpanEvaluationsTable"; type Span = TracePageQuery$data["spans"]["edges"][number]["span"]; /** @@ -162,6 +163,7 @@ export function TracePage() { message timestamp } + ...SpanEvaluationsTable_evals } } } @@ -284,6 +286,11 @@ function SelectedSpanDetails({ selectedSpan }: { selectedSpan: Span }) { + - {evalsEnabled ? Evals Tab : null} ); @@ -447,8 +453,16 @@ function LLMSpanInfo(props: { span: Span; spanAttributes: AttributeObject }) { return ( - {/* @ts-expect-error force putting the title in as a string */} - + {hasInputMessages ? ( -
Date: Mon, 27 Nov 2023 16:00:58 -0700 Subject: [PATCH 2/2] show a counter --- app/src/pages/trace/SpanEvaluationsTable.tsx | 13 +---- app/src/pages/trace/TracePage.tsx | 15 ++++- .../__generated__/TracePageQuery.graphql.ts | 57 +++++++++++++------ 3 files changed, 56 insertions(+), 29 deletions(-) diff --git a/app/src/pages/trace/SpanEvaluationsTable.tsx b/app/src/pages/trace/SpanEvaluationsTable.tsx index e08ed8a2d2..b57da87ae9 100644 --- a/app/src/pages/trace/SpanEvaluationsTable.tsx +++ b/app/src/pages/trace/SpanEvaluationsTable.tsx @@ -32,7 +32,7 @@ const columns = [ header: "explanation", accessorKey: "explanation", Cell: TextCell, - size: 500, + size: 400, }, ]; @@ -72,19 +72,12 @@ export function SpanEvaluationsTable(props: { {headerGroup.headers.map((header) => ( {header.isPlaceholder ? null : ( -
+ <> {flexRender( header.column.columnDef.header, header.getContext() )} -
+ )} ))} diff --git a/app/src/pages/trace/TracePage.tsx b/app/src/pages/trace/TracePage.tsx index 302040edee..e483a6a642 100644 --- a/app/src/pages/trace/TracePage.tsx +++ b/app/src/pages/trace/TracePage.tsx @@ -163,6 +163,11 @@ export function TracePage() { message timestamp } + spanEvaluations { + name + label + score + } ...SpanEvaluationsTable_evals } } @@ -286,7 +291,15 @@ function SelectedSpanDetails({ selectedSpan }: { selectedSpan: Span }) { -