Skip to content

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

Finalized metrics

Marc Klingen407ccb5ec7f4
diff --git a/prisma/migrations/20230522131516_default_timestamp/migration.sql b/prisma/migrations/20230522131516_default_timestamp/migration.sql
new file mode 100644
index 0000000000..ca10026983
--- /dev/null
+++ b/prisma/migrations/20230522131516_default_timestamp/migration.sql
@@ -0,0 +1,15 @@
+/*
+ Warnings:
+
+ - You are about to drop the column `createdAt` on the `metrics` table. All the data in the column will be lost.
+
+*/
+-- AlterTable
+ALTER TABLE "metrics" DROP COLUMN "createdAt",
+ADD COLUMN "timestamp" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP;
+
+-- AlterTable
+ALTER TABLE "observations" ALTER COLUMN "start_time" SET DEFAULT CURRENT_TIMESTAMP;
+
+-- AlterTable
+ALTER TABLE "traces" ALTER COLUMN "timestamp" SET DEFAULT CURRENT_TIMESTAMP;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 0f9898386e..308ed95854 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -65,7 +65,7 @@ model VerificationToken {
model Trace {
id String @id @default(cuid())
- timestamp DateTime
+ timestamp DateTime @default(now())
name String
attributes Json
status String
@@ -82,7 +82,7 @@ model Observation {
trace Trace @relation(fields: [traceId], references: [id], onDelete: Cascade)
type ObservationType
name String
- startTime DateTime @map("start_time")
+ startTime DateTime @default(now()) @map("start_time")
endTime DateTime? @map("end_time")
attributes Json
parentObservationId String? @map("parent_observation_id")
@@ -101,7 +101,7 @@ enum ObservationType {
model Metric {
id String @id @default(cuid())
- createdAt DateTime @default(now())
+ timestamp DateTime @default(now())
name String
value Int
traceId String
diff --git a/src/pages/metrics.tsx b/src/pages/metrics.tsx
index a9b9e5dae8..1129e42422 100644
--- a/src/pages/metrics.tsx
+++ b/src/pages/metrics.tsx
@@ -11,7 +11,7 @@ import { api } from "~/utils/api";
import { useRouter } from "next/router";
export default function MetricsPage() {
- const llmCalls = api.llmCalls.all.useQuery();
+ const metrics = api.metrics.all.useQuery();
const router = useRouter();
const columns: GridColDef[] = [
@@ -21,15 +21,7 @@ export default function MetricsPage() {
headerName: "ID",
width: 100,
getActions: (params: GridRowParams) => [
- <button
- key="openLlmCall"
- className="rounded bg-indigo-50 px-2 py-1 text-xs font-semibold text-indigo-600 shadow-sm hover:bg-indigo-100"
- onClick={() =>
- void router.push(`/llm-calls/${params.row.id as string}`)
- }
- >
- ...{lastCharacters(params.row.id as string, 7)}
- </button>,
+ <div key=".">...{lastCharacters(params.row.id as string, 7)}</div>,
],
},
{
@@ -50,49 +42,34 @@ export default function MetricsPage() {
],
},
{
- field: "startTime",
+ field: "timestamp",
type: "dateTime",
- headerName: "Start time",
+ headerName: "Timestamp",
width: 170,
},
{ field: "name", headerName: "Name", minWidth: 200 },
- {
- field: "prompt",
- headerName: "Prompt",
- flex: 1,
- },
- {
- field: "completion",
- headerName: "Completion",
- flex: 1,
- },
- {
- field: "model",
- headerName: "Model",
- flex: 1,
- },
+ { field: "value", headerName: "Value", minWidth: 200 },
];
- const rows: GridRowsProp = llmCalls.isSuccess
- ? llmCalls.data.map((llmCall) => ({
- id: llmCall.id,
- traceId: llmCall.traceId,
- startTime: llmCall.startTime,
- name: llmCall.name,
- prompt: llmCall.attributes.prompt,
- completion: llmCall.attributes.completion,
- model: JSON.stringify(llmCall.attributes.model),
+ const rows: GridRowsProp = metrics.isSuccess
+ ? metrics.data.map((metric) => ({
+ id: metric.id,
+ timestamp: metric.timestamp,
+ name: metric.name,
+ value: metric.value,
+ observationId: metric.observationId,
+ traceId: metric.traceId,
}))
: [];
return (
<>
- <Header title="LLM Calls" />
+ <Header title="Metrics" />
<DataGrid
rows={rows}
columns={columns}
slots={{ toolbar: GridToolbar }}
- loading={llmCalls.isLoading}
+ loading={metrics.isLoading}
/>
</>
);
diff --git a/src/server/api/root.ts b/src/server/api/root.ts
index f4bfee1e5d..37c40002c1 100644
--- a/src/server/api/root.ts
+++ b/src/server/api/root.ts
@@ -2,6 +2,7 @@ import { createTRPCRouter } from "~/server/api/trpc";
import { exampleRouter } from "~/server/api/routers/example";
import { traceRouter } from "./routers/traces";
import { llmCallRouter } from "./routers/llmCalls";
+import { metricsRouter } from "./routers/metrics";
/**
* This is the primary router for your server.
@@ -12,6 +13,7 @@ export const appRouter = createTRPCRouter({
example: exampleRouter,
traces: traceRouter,
llmCalls: llmCallRouter,
+ metrics: metricsRouter,
});
// export type definition of API
diff --git a/src/server/api/routers/metrics.ts b/src/server/api/routers/metrics.ts
new file mode 100644
index 0000000000..617295cc3f
--- /dev/null
+++ b/src/server/api/routers/metrics.ts
@@ -0,0 +1,21 @@
+import { z } from "zod";
+
+import { createTRPCRouter, publicProcedure } from "~/server/api/trpc";
+import { prisma } from "~/server/db";
+
+export const metricsRouter = createTRPCRouter({
+ all: publicProcedure.query(() =>
+ prisma.metric.findMany({
+ orderBy: {
+ timestamp: "desc",
+ },
+ })
+ ),
+ byId: publicProcedure.input(z.string()).query(({ input }) =>
+ prisma.metric.findUniqueOrThrow({
+ where: {
+ id: input,
+ },
+ })
+ ),
+});