Skip to content

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

filter table

Max Deichmann262d106ba091
diff --git a/package-lock.json b/package-lock.json
index e77a7e6b57..fec314540c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,9 @@
"dependencies": {
"@emotion/react": "^11.11.0",
"@emotion/styled": "^11.11.0",
+ "@fortawesome/fontawesome-svg-core": "^6.4.0",
+ "@fortawesome/free-solid-svg-icons": "^6.4.0",
+ "@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.14",
"@heroicons/react": "^2.0.18",
"@mui/material": "^5.13.2",
@@ -23,13 +26,13 @@
"@t3-oss/env-nextjs": "^0.3.1",
"@tailwindcss/forms": "^0.5.3",
"@tanstack/react-query": "^4.29.7",
- "@trpc/client": "^10.27.1",
- "@trpc/next": "^10.27.1",
- "@trpc/react-query": "^10.27.1",
- "@trpc/server": "^10.27.1",
+ "@trpc/client": "^10.28.0",
+ "@trpc/next": "^10.28.0",
+ "@trpc/react-query": "^10.28.0",
+ "@trpc/server": "^10.28.0",
"@types/cors": "^2.8.13",
"@types/js-yaml": "^4.0.5",
- "@types/lodash": "^4.14.194",
+ "@types/lodash": "^4.14.195",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"cors": "^2.8.5",
@@ -489,6 +492,51 @@
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
}
},
+ "node_modules/@fortawesome/fontawesome-common-types": {
+ "version": "6.4.0",
+ "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-common-types/-/fontawesome-common-types-6.4.0.tgz",
+ "integrity": "sha512-HNii132xfomg5QVZw0HwXXpN22s7VBHQBv9CeOu9tfJnhsWQNd2lmTNi8CSrnw5B+5YOmzu1UoPAyxaXsJ6RgQ==",
+ "hasInstallScript": true,
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/@fortawesome/fontawesome-svg-core": {
+ "version": "6.4.0",
+ "resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-svg-core/-/fontawesome-svg-core-6.4.0.tgz",
+ "integrity": "sha512-Bertv8xOiVELz5raB2FlXDPKt+m94MQ3JgDfsVbrqNpLU9+UE2E18GKjLKw+d3XbeYPqg1pzyQKGsrzbw+pPaw==",
+ "hasInstallScript": true,
+ "dependencies": {
+ "@fortawesome/fontawesome-common-types": "6.4.0"
+ },
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/@fortawesome/free-solid-svg-icons": {
+ "version": "6.4.0",
+ "resolved": "https://registry.npmjs.org/@fortawesome/free-solid-svg-icons/-/free-solid-svg-icons-6.4.0.tgz",
+ "integrity": "sha512-kutPeRGWm8V5dltFP1zGjQOEAzaLZj4StdQhWVZnfGFCvAPVvHh8qk5bRrU4KXnRRRNni5tKQI9PBAdI6MP8nQ==",
+ "hasInstallScript": true,
+ "dependencies": {
+ "@fortawesome/fontawesome-common-types": "6.4.0"
+ },
+ "engines": {
+ "node": ">=6"
+ }
+ },
+ "node_modules/@fortawesome/react-fontawesome": {
+ "version": "0.2.0",
+ "resolved": "https://registry.npmjs.org/@fortawesome/react-fontawesome/-/react-fontawesome-0.2.0.tgz",
+ "integrity": "sha512-uHg75Rb/XORTtVt7OS9WoK8uM276Ufi7gCzshVWkUJbHhh3svsUUeqXerrM96Wm7fRiDzfKRwSoahhMIkGAYHw==",
+ "dependencies": {
+ "prop-types": "^15.8.1"
+ },
+ "peerDependencies": {
+ "@fortawesome/fontawesome-svg-core": "~1 || ~6",
+ "react": ">=16.3"
+ }
+ },
"node_modules/@headlessui/react": {
"version": "1.7.14",
"resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.14.tgz",
diff --git a/package.json b/package.json
index 324db62133..84dd82fcea 100644
--- a/package.json
+++ b/package.json
@@ -16,6 +16,9 @@
"dependencies": {
"@emotion/react": "^11.11.0",
"@emotion/styled": "^11.11.0",
+ "@fortawesome/fontawesome-svg-core": "^6.4.0",
+ "@fortawesome/free-solid-svg-icons": "^6.4.0",
+ "@fortawesome/react-fontawesome": "^0.2.0",
"@headlessui/react": "^1.7.14",
"@heroicons/react": "^2.0.18",
"@mui/material": "^5.13.2",
@@ -28,13 +31,13 @@
"@t3-oss/env-nextjs": "^0.3.1",
"@tailwindcss/forms": "^0.5.3",
"@tanstack/react-query": "^4.29.7",
- "@trpc/client": "^10.27.1",
- "@trpc/next": "^10.27.1",
- "@trpc/react-query": "^10.27.1",
- "@trpc/server": "^10.27.1",
+ "@trpc/client": "^10.28.0",
+ "@trpc/next": "^10.28.0",
+ "@trpc/react-query": "^10.28.0",
+ "@trpc/server": "^10.28.0",
"@types/cors": "^2.8.13",
"@types/js-yaml": "^4.0.5",
- "@types/lodash": "^4.14.194",
+ "@types/lodash": "^4.14.195",
"class-variance-authority": "^0.6.0",
"clsx": "^1.2.1",
"cors": "^2.8.5",
diff --git a/prisma/seed.ts b/prisma/seed.ts
index 02074c5376..5902e5e3ef 100755
--- a/prisma/seed.ts
+++ b/prisma/seed.ts
@@ -9,7 +9,7 @@ async function main() {
timestamp: new Date(),
name: "sales-pilot",
attributes: {
},
status: "success",
},
@@ -22,7 +22,7 @@ async function main() {
type: "SPAN",
name: "sales-pilot-retrieval",
attributes: {
},
startTime: new Date(new Date().setMinutes(new Date().getMinutes() - 1)),
endTime: new Date(),
@@ -54,7 +54,7 @@ async function main() {
type: "LLMCALL",
name: "sales-pilot-retrieval-llm",
attributes: {
prompt: "Hello world",
completion: "Completion",
tokens: {
diff --git a/src/pages/traces.tsx b/src/pages/traces.tsx
index 7222f77b04..3d21b6a3dc 100644
--- a/src/pages/traces.tsx
+++ b/src/pages/traces.tsx
@@ -6,19 +6,158 @@ import {
type GridColDef,
type GridRowParams,
GridToolbar,
+ type GridFilterItem,
+ type GridFilterOperator,
+ type GridFilterInputValueProps,
+ SUBMIT_FILTER_STROKE_TIME,
+ type GridFilterModel,
} from "@mui/x-data-grid";
import { api } from "~/utils/api";
import { useRouter } from "next/router";
+import { type TextFieldProps, TextField, Box } from "@mui/material";
+import React from "react";
+import { type inferRouterInputs } from "@trpc/server";
+import { type AppRouter } from "../server/api/root";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+import { faSpinner } from "@fortawesome/free-solid-svg-icons";
+
+function InputKeyValue(props: GridFilterInputValueProps) {
+ const { item, applyValue, focusElementRef = null } = props;
+
+ const filterTimeout = React.useRef<any>();
+ const [filterValueState, setFilterValueState] = React.useState<
+ [string, string]
+ >(item.value ?? "");
+
+ const [applying, setIsApplying] = React.useState(false);
+
+ React.useEffect(() => {
+ return () => {
+ clearTimeout(filterTimeout.current);
+ };
+ }, []);
+
+ React.useEffect(() => {
+ const itemValue = item.value ?? [undefined, undefined];
+ setFilterValueState(itemValue);
+ }, [item.value]);
+
+ const updateFilterValue = (key: string, value: string) => {
+ clearTimeout(filterTimeout.current);
+ setFilterValueState([key, value]);
+
+ setIsApplying(true);
+ filterTimeout.current = setTimeout(() => {
+ setIsApplying(false);
+ applyValue({ ...item, value: [key, value] });
+ }, SUBMIT_FILTER_STROKE_TIME);
+ };
+
+ const handleUpperFilterChange: TextFieldProps["onChange"] = (event) => {
+ const newUpperBound = event.target.value;
+ updateFilterValue(filterValueState[0], newUpperBound);
+ };
+ const handleLowerFilterChange: TextFieldProps["onChange"] = (event) => {
+ const newLowerBound = event.target.value;
+ updateFilterValue(newLowerBound, filterValueState[1]);
+ };
+
+ return (
+ <Box
+ sx={{
+ display: "inline-flex",
+ flexDirection: "row",
+ alignItems: "end",
+ height: 48,
+ pl: "20px",
+ }}
+ >
+ <TextField
+ name="lower-bound-input"
+ placeholder="Key"
+ label="key"
+ variant="standard"
+ value={String(filterValueState[0])}
+ onChange={handleLowerFilterChange}
+ type="string"
+ inputRef={focusElementRef}
+ sx={{ mr: 2 }}
+ />
+ <TextField
+ name="upper-bound-input"
+ placeholder="Value"
+ label="value"
+ variant="standard"
+ value={String(filterValueState[1])}
+ onChange={handleUpperFilterChange}
+ type="string"
+ InputProps={
+ applying
+ ? {
+ endAdornment: <FontAwesomeIcon icon={faSpinner} />,
+ }
+ : {}
+ }
+ />
+ </Box>
+ );
+}
interface TraceRowData {
id: string;
}
+type RouterInput = inferRouterInputs<AppRouter>;
+
+type TraceFilterInput = RouterInput["traces"]["all"];
export default function Traces() {
- const traces = api.traces.all.useQuery(undefined, { refetchInterval: 1000 });
+ const [queryOptions, setQueryOptions] = React.useState<TraceFilterInput>({
+ attributes: {},
+ });
+
+ const traces = api.traces.all.useQuery(queryOptions, {
+ refetchInterval: 2000,
+ });
const router = useRouter();
+ const quantityOnlyOperators: GridFilterOperator[] = [
+ {
+ label: "Key-Value",
+ value: "key-value",
+ getApplyFilterFn: (filterItem: GridFilterItem) => {
+ if (!Array.isArray(filterItem.value) || filterItem.value.length !== 2) {
+ return null;
+ }
+ if (filterItem.value[0] == null || filterItem.value[1] == null) {
+ return null;
+ }
+
+ return ({ value }) => {
+ const jsonObj = JSON.parse(value);
+
+ return (
+ value !== null &&
+ jsonObj[filterItem.value[0]] !== undefined &&
+ jsonObj[filterItem.value[0]] === filterItem.value[1]
+ );
+ };
+ },
+ InputComponent: InputKeyValue,
+ },
+ ];
+
+ const [filterModel, setFilterModel] = React.useState<GridFilterModel>({
+ items: [
+ {
+ id: 1,
+ field: "attributes",
+ value: ["id", "abcd"],
+ operator: "key-value",
+ },
+ ],
+ });
+
const columns: GridColDef[] = [
{
field: "id",
@@ -52,6 +191,7 @@ export default function Traces() {
field: "attributes",
headerName: "Attributes",
flex: 1,
+ filterOperators: quantityOnlyOperators,
},
{
field: "scores",
@@ -60,6 +200,34 @@ export default function Traces() {
},
];
+ const onFilterChange = React.useCallback((filterModel: GridFilterModel) => {
+ console.log("hello", filterModel);
+
+ let filterOptions: TraceFilterInput = { attributes: {} };
+
+ filterModel.items.forEach((item) => {
+ if (item.operator === "key-value") {
+ if (!Array.isArray(item.value) || item.value.length !== 2) {
+ return null;
+ }
+ if (item.value[0] == null || item.value[1] == null) {
+ return null;
+ }
+
+ filterOptions = {
+ attributes: {
+ path: [item.value[0]],
+ equals: item.value[1] as string,
+ },
+ };
+ }
+ console.log("filterOptions", filterOptions);
+ setFilterModel(filterModel);
+ });
+
+ setQueryOptions(filterOptions);
+ }, []);
+
const rows: GridRowsProp = traces.isSuccess
? traces.data.map((trace) => ({
id: trace.id,
@@ -82,6 +250,9 @@ export default function Traces() {
columns={columns}
slots={{ toolbar: GridToolbar }}
loading={traces.isLoading}
+ filterModel={filterModel}
+ filterMode="server"
+ onFilterModelChange={onFilterChange}
/>
</>
);
diff --git a/src/server/api/root.ts b/src/server/api/root.ts
index cb283551c1..139c88cbd5 100644
--- a/src/server/api/root.ts
+++ b/src/server/api/root.ts
@@ -1,5 +1,4 @@
import { createTRPCRouter } from "~/server/api/trpc";
-import { exampleRouter } from "~/server/api/routers/example";
import { traceRouter } from "./routers/traces";
import { llmCallRouter } from "./routers/llmCalls";
import { scoresRouter } from "./routers/scores";
@@ -10,7 +9,6 @@ import { scoresRouter } from "./routers/scores";
* All routers added in /api/routers should be manually added here.
*/
export const appRouter = createTRPCRouter({
- example: exampleRouter,
traces: traceRouter,
llmCalls: llmCallRouter,
scores: scoresRouter,
diff --git a/src/server/api/routers/example.ts b/src/server/api/routers/example.ts
deleted file mode 100644
index 73de162882..0000000000
--- a/src/server/api/routers/example.ts
+++ /dev/null
@@ -1,25 +0,0 @@
-import { z } from "zod";
-
-import {
- createTRPCRouter,
- publicProcedure,
- protectedProcedure,
-} from "~/server/api/trpc";
-
-export const exampleRouter = createTRPCRouter({
- hello: publicProcedure
- .input(z.object({ text: z.string() }))
- .query(({ input }) => {
- return {
- greeting: `Hello ${input.text}`,
- };
- }),
-
- getAll: publicProcedure.query(({ ctx }) => {
- return ctx.prisma.example.findMany();
- }),
-
- getSecretMessage: protectedProcedure.query(() => {
- return "you can now see this secret message!";
- }),
-});
diff --git a/src/server/api/routers/traces.ts b/src/server/api/routers/traces.ts
index 31ce44c8e2..95b35e9b6d 100644
--- a/src/server/api/routers/traces.ts
+++ b/src/server/api/routers/traces.ts
@@ -6,18 +6,39 @@ import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
import { prisma } from "~/server/db";
export const traceRouter = createTRPCRouter({
- all: publicProcedure.query(async () => {
- const traces = await prisma.trace.findMany({
- orderBy: {
- timestamp: "desc",
- },
- include: {
- scores: true,
- },
- });
+ all: publicProcedure
+ .input(
+ z.object({
+ attributes: z
+ .object({
+ path: z.array(z.string()).optional(),
+ equals: z.string().optional(),
+ string_contains: z.string().optional(),
+ string_starts_with: z.string().optional(),
+ string_ends_with: z.string().optional(),
+ })
+ .nullable(),
+ })
+ )
+ .query(async ({ input }) => {
+ const traces = await prisma.trace.findMany({
+ ...(input.attributes?.path
+ ? {
+ where: {
+ attributes: input.attributes,
+ },
+ }
+ : undefined),
+ orderBy: {
+ timestamp: "desc",
+ },
+ include: {
+ scores: true,
+ },
+ });
- return traces;
- }),
+ return traces;
+ }),
byId: publicProcedure.input(z.string()).query(async ({ input }) => {
const [trace, observations] = await Promise.all([