Skip to content

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

feat(generation): extend generations table (#1216)

Richard Krümmele7438c05b82c
diff --git a/web/prisma/generated/types.ts b/web/prisma/generated/types.ts
index 8feb5246e5..34b0193ff5 100644
--- a/web/prisma/generated/types.ts
+++ b/web/prisma/generated/types.ts
@@ -225,7 +225,7 @@ export type ObservationView = {
calculated_input_cost: string | null;
calculated_output_cost: string | null;
calculated_total_cost: string | null;
- latency: string | null;
+ latency: number | null;
};
export type Pricing = {
id: string;
diff --git a/web/prisma/migrations/20240227112101_index_prompt_id_in_observations/migration.sql b/web/prisma/migrations/20240227112101_index_prompt_id_in_observations/migration.sql
new file mode 100644
index 0000000000..988a52ca12
--- /dev/null
+++ b/web/prisma/migrations/20240227112101_index_prompt_id_in_observations/migration.sql
@@ -0,0 +1,2 @@
+-- CreateIndex
+CREATE INDEX "observations_prompt_id_idx" ON "observations"("prompt_id");
diff --git a/web/prisma/schema.prisma b/web/prisma/schema.prisma
index 229fd92cc1..5a58eb2d17 100644
--- a/web/prisma/schema.prisma
+++ b/web/prisma/schema.prisma
@@ -271,6 +271,7 @@ model Observation {
@@index(projectId)
@@index(parentObservationId)
@@index(model)
+ @@index(promptId)
@@index([projectId, startTime, type])
@@map("observations")
}
@@ -510,7 +511,7 @@ view ObservationView {
calculatedInputCost Decimal? @map("calculated_input_cost")
calculatedOutputCost Decimal? @map("calculated_output_cost")
calculatedTotalCost Decimal? @map("calculated_total_cost")
- latency Decimal? @map("latency")
+ latency Float? @map("latency")
@@map("observations_view")
}
diff --git a/web/src/components/table/use-cases/generations.tsx b/web/src/components/table/use-cases/generations.tsx
index aa5a6241ba..a37643b60f 100644
--- a/web/src/components/table/use-cases/generations.tsx
+++ b/web/src/components/table/use-cases/generations.tsx
@@ -23,7 +23,7 @@ import {
} from "use-query-params";
import { useQueryFilterState } from "@/src/features/filters/hooks/useFilterState";
import { observationsTableColsWithOptions } from "@/src/server/api/definitions/observationsTable";
-import { formatInterval, utcDateOffsetByDays } from "@/src/utils/dates";
+import { formatIntervalSeconds, 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";
@@ -36,6 +36,7 @@ import {
type ExportFileFormats,
} from "@/src/server/api/interfaces/exportTypes";
import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";
+import type Decimal from "decimal.js";
export type GenerationsTableRow = {
id: string;
@@ -44,11 +45,15 @@ export type GenerationsTableRow = {
level?: ObservationLevel;
statusMessage?: string;
endTime?: string;
+ timeToFirstToken?: string;
latency?: number;
name?: string;
model?: string;
input?: unknown;
output?: unknown;
+ inputCost?: Decimal;
+ outputCost?: Decimal;
+ totalCost?: Decimal;
traceName?: string;
metadata?: string;
scores: Score[];
@@ -57,6 +62,9 @@ export type GenerationsTableRow = {
completionTokens: number;
totalTokens: number;
};
+ promptId?: string;
+ promptName?: string;
+ promptVersion?: string;
};
export type GenerationsTableProps = {
@@ -185,7 +193,7 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
{
accessorKey: "name",
id: "name",
- header: "name",
+ header: "Name",
enableSorting: true,
},
{
@@ -217,6 +225,34 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
enableHiding: true,
enableSorting: true,
},
+ {
+ accessorKey: "endTime",
+ id: "endTime",
+ header: "End Time",
+ enableHiding: true,
+ enableSorting: true,
+ },
+ {
+ accessorKey: "timeToFirstToken",
+ id: "timeToFirstToken",
+ header: "Time to First Token",
+ enableHiding: true,
+ cell: ({ row }) => {
+ const startTime: string = row.getValue("startTime");
+ const timeToFirstToken: string | undefined =
+ row.getValue("timeToFirstToken");
+
+ if (!timeToFirstToken) {
+ return undefined;
+ }
+
+ const latencyInMs =
+ new Date(timeToFirstToken).getTime() - new Date(startTime).getTime();
+ const latencyInSeconds = latencyInMs / 1000;
+
+ return <span>{formatIntervalSeconds(latencyInSeconds)}</span>;
+ },
+ },
{
accessorKey: "scores",
id: "scores",
@@ -232,22 +268,71 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
id: "latency",
header: "Latency",
cell: ({ row }) => {
- const value: number | undefined = row.getValue("latency");
- return value !== undefined ? (
- <span>{formatInterval(value)}</span>
+ const latency: number | undefined = row.getValue("latency");
+ return latency !== undefined ? (
+ <span>{formatIntervalSeconds(latency)}</span>
) : undefined;
},
enableHiding: true,
enableSorting: true,
},
{
- accessorKey: "cost",
- header: "Cost",
+ accessorKey: "timePerOutputToken",
+ id: "timePerOutputToken",
+ header: "Time per Output Token",
+ cell: ({ row }) => {
+ const latency: number | undefined = row.getValue("latency");
+ const usage: {
+ promptTokens: number;
+ completionTokens: number;
+ totalTokens: number;
+ } = row.getValue("usage");
+ return latency !== undefined &&
+ (usage.completionTokens !== 0 || usage.totalTokens !== 0) ? (
+ <span>
+ {usage.completionTokens
+ ? formatIntervalSeconds(latency / usage.completionTokens)
+ : formatIntervalSeconds(latency / usage.totalTokens)}
+ </span>
+ ) : undefined;
+ },
+ defaultHidden: true,
+ enableHiding: true,
+ },
+ {
+ accessorKey: "inputCost",
+ header: "Input Cost",
cell: ({ row }) => {
- const value: number | undefined = row.getValue("cost");
+ const value: Decimal | undefined = row.getValue("inputCost");
return value !== undefined ? (
- <span>{usdFormatter(value)}</span>
+ <span>{usdFormatter(value.toNumber())}</span>
+ ) : undefined;
+ },
+ enableHiding: true,
+ defaultHidden: true,
+ },
+ {
+ accessorKey: "outputCost",
+ header: "Output Cost",
+ cell: ({ row }) => {
+ const value: Decimal | undefined = row.getValue("outputCost");
+
+ return value !== undefined ? (
+ <span>{usdFormatter(value.toNumber())}</span>
+ ) : undefined;
+ },
+ enableHiding: true,
+ defaultHidden: true,
+ },
+ {
+ accessorKey: "totalCost",
+ header: "Total Cost",
+ cell: ({ row }) => {
+ const value: Decimal | undefined = row.getValue("totalCost");
+
+ return value !== undefined ? (
+ <span>{usdFormatter(value.toNumber())}</span>
) : undefined;
},
enableHiding: true,
@@ -343,6 +428,28 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
enableHiding: true,
enableSorting: true,
},
+ {
+ accessorKey: "prompt",
+ id: "prompt",
+ header: "Prompt",
+ enableHiding: true,
+ enableSorting: true,
+ cell: ({ row }) => {
+ const promptName = row.original.promptName;
+ const promptVersion = row.original.promptVersion;
+ const value = `${promptName} (v${promptVersion})`;
+ return (
+ promptName &&
+ promptVersion && (
+ <TableLink
+ path={`/project/${projectId}/prompts/${encodeURIComponent(promptName)}?version=${promptVersion}`}
+ value={value}
+ truncateAt={40}
+ />
+ )
+ );
+ },
+ },
];
const [columnVisibility, setColumnVisibility] =
useColumnVisibility<GenerationsTableRow>(
@@ -358,8 +465,12 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
traceName: generation.traceName,
startTime: generation.startTime.toLocaleString(),
endTime: generation.endTime?.toLocaleString() ?? undefined,
- latency: generation.latency === null ? undefined : generation.latency,
- cost: generation.calculatedTotalCost,
+ timeToFirstToken:
+ generation.completionStartTime?.toLocaleString() ?? undefined,
+ latency: generation.latency ?? undefined,
+ totalCost: generation.calculatedTotalCost ?? undefined,
+ inputCost: generation.calculatedInputCost ?? undefined,
+ outputCost: generation.calculatedOutputCost ?? undefined,
name: generation.name ?? undefined,
version: generation.version ?? "",
model: generation.model ?? "",
@@ -376,6 +487,9 @@ export default function GenerationsTable({ projectId }: GenerationsTableProps) {
completionTokens: generation.completionTokens,
totalTokens: generation.totalTokens,
},
+ promptId: generation.promptId ?? undefined,
+ promptName: generation.promptName ?? undefined,
+ promptVersion: generation.promptVersion ?? undefined,
};
})
: [];
diff --git a/web/src/components/table/use-cases/sessions.tsx b/web/src/components/table/use-cases/sessions.tsx
index 828b0c96d7..6ec3333f4a 100644
--- a/web/src/components/table/use-cases/sessions.tsx
+++ b/web/src/components/table/use-cases/sessions.tsx
@@ -10,7 +10,7 @@ import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context
import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";
import { sessionsViewCols } from "@/src/server/api/definitions/sessionsView";
import { api } from "@/src/utils/api";
-import { formatInterval, utcDateOffsetByDays } from "@/src/utils/dates";
+import { formatIntervalSeconds, utcDateOffsetByDays } from "@/src/utils/dates";
import { usdFormatter } from "@/src/utils/numbers";
import { type RouterOutput } from "@/src/utils/types";
import { useEffect } from "react";
@@ -156,7 +156,7 @@ export default function SessionsTable({
cell: ({ row }) => {
const value = row.getValue("sessionDuration");
return value && typeof value === "number"
- ? formatInterval(value)
+ ? formatIntervalSeconds(value)
: undefined;
},
enableSorting: true,
diff --git a/web/src/components/table/use-cases/traces.tsx b/web/src/components/table/use-cases/traces.tsx
index bb2c14c5dc..b821f8477e 100644
--- a/web/src/components/table/use-cases/traces.tsx
+++ b/web/src/components/table/use-cases/traces.tsx
@@ -17,7 +17,7 @@ import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context
import { useOrderByState } from "@/src/features/orderBy/hooks/useOrderByState";
import { tracesTableColsWithOptions } from "@/src/server/api/definitions/tracesTable";
import { api } from "@/src/utils/api";
-import { formatInterval, utcDateOffsetByDays } from "@/src/utils/dates";
+import { formatIntervalSeconds, utcDateOffsetByDays } from "@/src/utils/dates";
import { type RouterInput, type RouterOutput } from "@/src/utils/types";
import { type Score } from "@prisma/client";
import { type RowSelectionState } from "@tanstack/react-table";
@@ -285,7 +285,7 @@ export default function TracesTable({
// add seconds to the end of the latency
cell: ({ row }) => {
const value: number | undefined = row.getValue("latency");
- return value !== undefined ? formatInterval(value) : undefined;
+ return value !== undefined ? formatIntervalSeconds(value) : undefined;
},
enableHiding: true,
enableSorting: true,
diff --git a/web/src/components/trace/ObservationPreview.tsx b/web/src/components/trace/ObservationPreview.tsx
index 0255a6a2b8..597ac76175 100644
--- a/web/src/components/trace/ObservationPreview.tsx
+++ b/web/src/components/trace/ObservationPreview.tsx
@@ -21,7 +21,7 @@ import { NewDatasetItemFromObservationButton } from "@/src/features/datasets/com
import { type ObservationReturnType } from "@/src/server/api/routers/traces";
import { api } from "@/src/utils/api";
import { IOPreview } from "@/src/components/trace/IOPreview";
-import { formatInterval } from "@/src/utils/dates";
+import { formatIntervalSeconds } from "@/src/utils/dates";
import Link from "next/link";
import { usdFormatter } from "@/src/utils/numbers";
import { calculateDisplayTotalCost } from "@/src/components/trace";
@@ -70,7 +70,7 @@ export const ObservationPreview = (props: {
{preloadedObservation.completionStartTime ? (
<Badge variant="outline">
Time to first token:{" "}
- {formatInterval(
+ {formatIntervalSeconds(
(preloadedObservation.completionStartTime.getTime() -
preloadedObservation.startTime.getTime()) /
1000,
@@ -80,7 +80,7 @@ export const ObservationPreview = (props: {
{preloadedObservation.endTime ? (
<Badge variant="outline">
Latency:{" "}
- {formatInterval(
+ {formatIntervalSeconds(
(preloadedObservation.endTime.getTime() -
preloadedObservation.startTime.getTime()) /
1000,
diff --git a/web/src/components/trace/ObservationTree.tsx b/web/src/components/trace/ObservationTree.tsx
index 425aa1f307..762ca7cf36 100644
--- a/web/src/components/trace/ObservationTree.tsx
+++ b/web/src/components/trace/ObservationTree.tsx
@@ -5,7 +5,7 @@ import { GroupedScoreBadges } from "@/src/components/grouped-score-badge";
import { Fragment } from "react";
import { type ObservationReturnType } from "@/src/server/api/routers/traces";
import { LevelColors } from "@/src/components/level-colors";
-import { formatInterval } from "@/src/utils/dates";
+import { formatIntervalSeconds } from "@/src/utils/dates";
import { MinusCircle, MinusIcon, PlusCircleIcon, PlusIcon } from "lucide-react";
import { Toggle } from "@/src/components/ui/toggle";
import { Button } from "@/src/components/ui/button";
@@ -96,7 +96,7 @@ const ObservationTreeTraceNode = (props: {
{props.showMetrics && props.trace.latency ? (
<div className="flex gap-2">
<span className="text-xs text-gray-500">
- {formatInterval(props.trace.latency)}
+ {formatIntervalSeconds(props.trace.latency)}
</span>
</div>
) : null}
@@ -179,7 +179,7 @@ const ObservationTreeNode = (props: {
<div className="flex gap-2">
{observation.endTime ? (
<span className="text-xs text-gray-500">
- {formatInterval(
+ {formatIntervalSeconds(
(observation.endTime.getTime() -
observation.startTime.getTime()) /
1000,
diff --git a/web/src/components/trace/TracePreview.tsx b/web/src/components/trace/TracePreview.tsx
index dc88cb7c18..339e41fe36 100644
--- a/web/src/components/trace/TracePreview.tsx
+++ b/web/src/components/trace/TracePreview.tsx
@@ -21,7 +21,7 @@ import { ManualScoreButton } from "@/src/features/manual-scoring/components/Manu
import { Badge } from "@/src/components/ui/badge";
import { type ObservationReturnType } from "@/src/server/api/routers/traces";
import { IOPreview } from "@/src/components/trace/IOPreview";
-import { formatInterval } from "@/src/utils/dates";
+import { formatIntervalSeconds } from "@/src/utils/dates";
export const TracePreview = ({
trace,
@@ -45,7 +45,9 @@ export const TracePreview = ({
<CardDescription>{trace.timestamp.toLocaleString()}</CardDescription>
<div className="flex flex-wrap gap-2">
{!!trace.latency && (
- <Badge variant="outline">{formatInterval(trace.latency)}</Badge>
+ <Badge variant="outline">
+ {formatIntervalSeconds(trace.latency)}
+ </Badge>
)}
<TraceAggUsageBadge observations={observations} />
{!!trace.release && (
diff --git a/web/src/features/datasets/components/DatasetRunItemsTable.tsx b/web/src/features/datasets/components/DatasetRunItemsTable.tsx
index 2e64d7f533..ea376f5bee 100644
--- a/web/src/features/datasets/components/DatasetRunItemsTable.tsx
+++ b/web/src/features/datasets/components/DatasetRunItemsTable.tsx
@@ -3,7 +3,7 @@ import { DataTable } from "@/src/components/table/data-table";
import TableLink from "@/src/components/table/table-link";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { api } from "@/src/utils/api";
-import { formatInterval, intervalInSeconds } from "@/src/utils/dates";
+import { formatIntervalSeconds, intervalInSeconds } from "@/src/utils/dates";
import { type RouterOutput } from "@/src/utils/types";
import { type Score } from "@prisma/client";
@@ -69,7 +69,7 @@ export function DatasetRunItemsTable(
header: "Latency",
cell: ({ row }) => {
const latency: RowData["latency"] = row.getValue("latency");
- return <>{formatInterval(latency)}</>;
+ return <>{formatIntervalSeconds(latency)}</>;
},
},
{
diff --git a/web/src/features/datasets/components/DatasetRunsTable.tsx b/web/src/features/datasets/components/DatasetRunsTable.tsx
index 244277c66e..2d9c3fa66f 100644
--- a/web/src/features/datasets/components/DatasetRunsTable.tsx
+++ b/web/src/features/datasets/components/DatasetRunsTable.tsx
@@ -4,7 +4,7 @@ import TableLink from "@/src/components/table/table-link";
import { type LangfuseColumnDef } from "@/src/components/table/types";
import { useDetailPageLists } from "@/src/features/navigate-detail-pages/context";
import { api } from "@/src/utils/api";
-import { formatInterval } from "@/src/utils/dates";
+import { formatIntervalSeconds } from "@/src/utils/dates";
import { type RouterOutput } from "@/src/utils/types";
import { useEffect } from "react";
@@ -65,7 +65,7 @@ export function DatasetRunsTable(props: {
header: "Latency (avg)",
cell: ({ row }) => {
const avgLatency: RowData["avgLatency"] = row.getValue("avgLatency");
- return <>{formatInterval(avgLatency)}</>;
+ return <>{formatIntervalSeconds(avgLatency)}</>;
},
},
{
diff --git a/web/src/features/prompts/components/new-prompt-button.tsx b/web/src/features/prompts/components/new-prompt-button.tsx
index b3ff9ffdfb..4cf927f26a 100644
--- a/web/src/features/prompts/components/new-prompt-button.tsx
+++ b/web/src/features/prompts/components/new-prompt-button.tsx
@@ -178,7 +178,7 @@ export const NewPromptForm = (props: {
form.reset();
// go to the following page after creating the prompt
void router.push(
- `/project/${props.projectId}/prompts/${newPrompt.name}`,
+ `/project/${props.projectId}/prompts/${encodeURIComponent(newPrompt.name)}`,
);
})
.catch((error) => {
diff --git a/web/src/features/prompts/components/prompt-detail.tsx b/web/src/features/prompts/components/prompt-detail.tsx
index a5e90114fe..cab9c04224 100644
--- a/web/src/features/prompts/components/prompt-detail.tsx
+++ b/web/src/features/prompts/components/prompt-detail.tsx
@@ -56,7 +56,7 @@ export const PromptDetail = (props: PromptDetailProps) => {
},
{
name: prompt.name,
- href: `/project/${props.projectId}/prompts/${prompt.name}`,
+ href: `/project/${props.projectId}/prompts/${props.promptName}`,
},
{ name: `Version ${prompt.version}` },
]}
@@ -89,7 +89,7 @@ export const PromptDetail = (props: PromptDetailProps) => {
/>
<DetailPageNav
key="nav"
- currentId={prompt.name}
+ currentId={props.promptName}
path={(name) => `/project/${props.projectId}/prompts/${name}`}
listKey="prompts"
/>
diff --git a/web/src/features/prompts/components/prompts-table.tsx b/web/src/features/prompts/components/prompts-table.tsx
index 3f1415a091..d0a3c9cd0c 100644
--- a/web/src/features/prompts/components/prompts-table.tsx
+++ b/web/src/features/prompts/components/prompts-table.tsx
@@ -35,7 +35,7 @@ export function PromptTable(props: { projectId: string }) {
if (prompts.isSuccess) {
setDetailPageList(
"prompts",
- prompts.data.map((t) => t.name),
+ prompts.data.map((t) => encodeURIComponent(t.name)),
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
@@ -49,7 +49,7 @@ export function PromptTable(props: { projectId: string }) {
const name: string = row.getValue("name");
return name && typeof name === "string" ? (
<TableLink
- path={`/project/${props.projectId}/prompts/${name}`}
+ path={`/project/${props.projectId}/prompts/${encodeURIComponent(name)}`}
value={name}
truncateAt={30}
/>
diff --git a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
index 1bad3ecdf3..f92f6520a5 100644
--- a/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
+++ b/web/src/server/api/routers/generations/db/getAllGenerationsSqlQuery.ts
@@ -114,10 +114,14 @@ export function getAllGenerationsSqlQuery({
o.calculated_input_cost as "calculatedInputCost",
o.calculated_output_cost as "calculatedOutputCost",
o.calculated_total_cost as "calculatedTotalCost",
- o."latency"
+ o."latency",
+ o.prompt_id as "promptId",
+ p.name as "promptName",
+ p.version as "promptVersion"
FROM observations_view o
JOIN traces t ON t.id = o.trace_id AND t.project_id = o.project_id
LEFT JOIN scores_avg AS s_avg ON s_avg.trace_id = t.id and s_avg.observation_id = o.id
+ LEFT JOIN prompts p ON p.id = o.prompt_id
WHERE
o.project_id = ${input.projectId}
AND t.project_id = ${input.projectId}
diff --git a/web/src/server/api/routers/generations/getAllQuery.ts b/web/src/server/api/routers/generations/getAllQuery.ts
index 72236b99b8..c499fdac56 100644
--- a/web/src/server/api/routers/generations/getAllQuery.ts
+++ b/web/src/server/api/routers/generations/getAllQuery.ts
@@ -22,7 +22,8 @@ export const getAllQuery = protectedProjectProcedure
(ObservationView & {
traceId: string;
traceName: string;
- latency: number | null;
+ promptName: string | null;
+ promptVersion: string | null;
})[]
>(rawSqlQuery);
diff --git a/web/src/utils/dates.ts b/web/src/utils/dates.ts
index 03372cf4b9..74401a6424 100644
--- a/web/src/utils/dates.ts
+++ b/web/src/utils/dates.ts
@@ -18,7 +18,7 @@ export const setEndOfDay = (date: Date) => {
export const intervalInSeconds = (start: Date, end: Date | null) =>
end ? (end.getTime() - start.getTime()) / 1000 : 0;
-export const formatInterval = (seconds: number) => {
+export const formatIntervalSeconds = (seconds: number) => {
const hrs = Math.floor(seconds / 3600);
const mins = Math.floor((seconds % 3600) / 60);
const secs = Math.floor(seconds % 60);
diff --git a/worker/generated/types.ts b/worker/generated/types.ts
index cb53274122..34b0193ff5 100644
--- a/worker/generated/types.ts
+++ b/worker/generated/types.ts
@@ -1,343 +1,339 @@
import type { ColumnType } from "kysely";
-export type Generated<T> =
- T extends ColumnType<infer S, infer I, infer U>
- ? ColumnType<S, I | undefined, U>
- : ColumnType<T, T | undefined, T>;
+export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
+ ? ColumnType<S, I | undefined, U>
+ : ColumnType<T, T | undefined, T>;
export type Timestamp = ColumnType<Date, Date | string, Date | string>;
export const MembershipRole = {
- OWNER: "OWNER",
- ADMIN: "ADMIN",
- MEMBER: "MEMBER",
- VIEWER: "VIEWER",
+ OWNER: "OWNER",
+ ADMIN: "ADMIN",
+ MEMBER: "MEMBER",
+ VIEWER: "VIEWER"
} as const;
-export type MembershipRole =
- (typeof MembershipRole)[keyof typeof MembershipRole];
+export type MembershipRole = (typeof MembershipRole)[keyof typeof MembershipRole];
export const ObservationType = {
- SPAN: "SPAN",
- EVENT: "EVENT",
- GENERATION: "GENERATION",
+ SPAN: "SPAN",
+ EVENT: "EVENT",
+ GENERATION: "GENERATION"
} as const;
-export type ObservationType =
- (typeof ObservationType)[keyof typeof ObservationType];
+export type ObservationType = (typeof ObservationType)[keyof typeof ObservationType];
export const ObservationLevel = {
- DEBUG: "DEBUG",
- DEFAULT: "DEFAULT",
- WARNING: "WARNING",
- ERROR: "ERROR",
+ DEBUG: "DEBUG",
+ DEFAULT: "DEFAULT",
+ WARNING: "WARNING",
+ ERROR: "ERROR"
} as const;
-export type ObservationLevel =
- (typeof ObservationLevel)[keyof typeof ObservationLevel];
+export type ObservationLevel = (typeof ObservationLevel)[keyof typeof ObservationLevel];
export const PricingUnit = {
- PER_1000_TOKENS: "PER_1000_TOKENS",
- PER_1000_CHARS: "PER_1000_CHARS",
+ PER_1000_TOKENS: "PER_1000_TOKENS",
+ PER_1000_CHARS: "PER_1000_CHARS"
} as const;
export type PricingUnit = (typeof PricingUnit)[keyof typeof PricingUnit];
export const TokenType = {
- PROMPT: "PROMPT",
- COMPLETION: "COMPLETION",
- TOTAL: "TOTAL",
+ PROMPT: "PROMPT",
+ COMPLETION: "COMPLETION",
+ TOTAL: "TOTAL"
} as const;
export type TokenType = (typeof TokenType)[keyof typeof TokenType];
export const DatasetStatus = {
- ACTIVE: "ACTIVE",
- ARCHIVED: "ARCHIVED",
+ ACTIVE: "ACTIVE",
+ ARCHIVED: "ARCHIVED"
} as const;
export type DatasetStatus = (typeof DatasetStatus)[keyof typeof DatasetStatus];
export type Account = {
- id: string;
- user_id: string;
- type: string;
- provider: string;
- providerAccountId: string;
- refresh_token: string | null;
- access_token: string | null;
- expires_at: number | null;
- expires_in: number | null;
- ext_expires_in: number | null;
- token_type: string | null;
- scope: string | null;
- id_token: string | null;
- session_state: string | null;
+ id: string;
+ user_id: string;
+ type: string;
+ provider: string;
+ providerAccountId: string;
+ refresh_token: string | null;
+ access_token: string | null;
+ expires_at: number | null;
+ expires_in: number | null;
+ ext_expires_in: number | null;
+ token_type: string | null;
+ scope: string | null;
+ id_token: string | null;
+ session_state: string | null;
};
export type ApiKey = {
- id: string;
- created_at: Generated<Timestamp>;
- note: string | null;
- public_key: string;
- hashed_secret_key: string;
- fast_hashed_secret_key: string | null;
- display_secret_key: string;
- last_used_at: Timestamp | null;
- expires_at: Timestamp | null;
- project_id: string;
+ id: string;
+ created_at: Generated<Timestamp>;
+ note: string | null;
+ public_key: string;
+ hashed_secret_key: string;
+ fast_hashed_secret_key: string | null;
+ display_secret_key: string;
+ last_used_at: Timestamp | null;
+ expires_at: Timestamp | null;
+ project_id: string;
};
export type AuditLog = {
- id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
- user_id: string;
- project_id: string;
- user_project_role: MembershipRole;
- resource_type: string;
- resource_id: string;
- action: string;
- before: string | null;
- after: string | null;
+ id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
+ user_id: string;
+ project_id: string;
+ user_project_role: MembershipRole;
+ resource_type: string;
+ resource_id: string;
+ action: string;
+ before: string | null;
+ after: string | null;
};
export type CronJobs = {
- name: string;
- last_run: Timestamp | null;
- job_started_at: Timestamp | null;
- state: string | null;
+ name: string;
+ last_run: Timestamp | null;
+ job_started_at: Timestamp | null;
+ state: string | null;
};
export type Dataset = {
- id: string;
- name: string;
- project_id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
+ id: string;
+ name: string;
+ project_id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
};
export type DatasetItem = {
- id: string;
- status: Generated<DatasetStatus>;
- input: unknown;
- expected_output: unknown | null;
- source_observation_id: string | null;
- dataset_id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
+ id: string;
+ status: Generated<DatasetStatus>;
+ input: unknown;
+ expected_output: unknown | null;
+ source_observation_id: string | null;
+ dataset_id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
};
export type DatasetRunItems = {
- id: string;
- dataset_run_id: string;
- dataset_item_id: string;
- observation_id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
+ id: string;
+ dataset_run_id: string;
+ dataset_item_id: string;
+ observation_id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
};
export type DatasetRuns = {
- id: string;
- name: string;
- dataset_id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
+ id: string;
+ name: string;
+ dataset_id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
};
export type Events = {
- id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
- project_id: string;
- data: unknown;
- headers: Generated<unknown>;
- url: string | null;
- method: string | null;
+ id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
+ project_id: string;
+ data: unknown;
+ headers: Generated<unknown>;
+ url: string | null;
+ method: string | null;
};
export type Example = {
- id: string;
- created_at: Generated<Timestamp>;
- updated_at: Timestamp;
+ id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Timestamp;
};
export type Membership = {
- project_id: string;
- user_id: string;
- role: MembershipRole;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
+ project_id: string;
+ user_id: string;
+ role: MembershipRole;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
};
export type MembershipInvitation = {
- id: string;
- email: string;
- role: MembershipRole;
- project_id: string;
- sender_id: string | null;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
+ id: string;
+ email: string;
+ role: MembershipRole;
+ project_id: string;
+ sender_id: string | null;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
};
export type Model = {
- id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
- project_id: string | null;
- model_name: string;
- match_pattern: string;
- start_date: Timestamp | null;
- input_price: string | null;
- output_price: string | null;
- total_price: string | null;
- unit: string;
- tokenizer_id: string | null;
- tokenizer_config: unknown | null;
+ id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
+ project_id: string | null;
+ model_name: string;
+ match_pattern: string;
+ start_date: Timestamp | null;
+ input_price: string | null;
+ output_price: string | null;
+ total_price: string | null;
+ unit: string;
+ tokenizer_id: string | null;
+ tokenizer_config: unknown | null;
};
export type Observation = {
- id: string;
- trace_id: string | null;
- project_id: string;
- type: ObservationType;
- start_time: Generated<Timestamp>;
- end_time: Timestamp | null;
- name: string | null;
- metadata: unknown | null;
- parent_observation_id: string | null;
- level: Generated<ObservationLevel>;
- status_message: string | null;
- version: string | null;
- created_at: Generated<Timestamp>;
- model: string | null;
- internal_model: string | null;
- modelParameters: unknown | null;
- input: unknown | null;
- output: unknown | null;
- prompt_tokens: Generated<number>;
- completion_tokens: Generated<number>;
- total_tokens: Generated<number>;
- unit: string | null;
- input_cost: string | null;
- output_cost: string | null;
- total_cost: string | null;
- completion_start_time: Timestamp | null;
- prompt_id: string | null;
+ id: string;
+ trace_id: string | null;
+ project_id: string;
+ type: ObservationType;
+ start_time: Generated<Timestamp>;
+ end_time: Timestamp | null;
+ name: string | null;
+ metadata: unknown | null;
+ parent_observation_id: string | null;
+ level: Generated<ObservationLevel>;
+ status_message: string | null;
+ version: string | null;
+ created_at: Generated<Timestamp>;
+ model: string | null;
+ internal_model: string | null;
+ modelParameters: unknown | null;
+ input: unknown | null;
+ output: unknown | null;
+ prompt_tokens: Generated<number>;
+ completion_tokens: Generated<number>;
+ total_tokens: Generated<number>;
+ unit: string | null;
+ input_cost: string | null;
+ output_cost: string | null;
+ total_cost: string | null;
+ completion_start_time: Timestamp | null;
+ prompt_id: string | null;
};
export type ObservationView = {
- id: string;
- trace_id: string | null;
- project_id: string;
- type: ObservationType;
- start_time: Generated<Timestamp>;
- end_time: Timestamp | null;
- name: string | null;
- metadata: unknown | null;
- parent_observation_id: string | null;
- level: Generated<ObservationLevel>;
- status_message: string | null;
- version: string | null;
- created_at: Generated<Timestamp>;
- model: string | null;
- modelParameters: unknown | null;
- input: unknown | null;
- output: unknown | null;
- prompt_tokens: Generated<number>;
- completion_tokens: Generated<number>;
- total_tokens: Generated<number>;
- unit: string | null;
- completion_start_time: Timestamp | null;
- prompt_id: string | null;
- model_id: string | null;
- input_price: string | null;
- output_price: string | null;
- total_price: string | null;
- calculated_input_cost: string | null;
- calculated_output_cost: string | null;
- calculated_total_cost: string | null;
- latency: string | null;
+ id: string;
+ trace_id: string | null;
+ project_id: string;
+ type: ObservationType;
+ start_time: Generated<Timestamp>;
+ end_time: Timestamp | null;
+ name: string | null;
+ metadata: unknown | null;
+ parent_observation_id: string | null;
+ level: Generated<ObservationLevel>;
+ status_message: string | null;
+ version: string | null;
+ created_at: Generated<Timestamp>;
+ model: string | null;
+ modelParameters: unknown | null;
+ input: unknown | null;
+ output: unknown | null;
+ prompt_tokens: Generated<number>;
+ completion_tokens: Generated<number>;
+ total_tokens: Generated<number>;
+ unit: string | null;
+ completion_start_time: Timestamp | null;
+ prompt_id: string | null;
+ model_id: string | null;
+ input_price: string | null;
+ output_price: string | null;
+ total_price: string | null;
+ calculated_input_cost: string | null;
+ calculated_output_cost: string | null;
+ calculated_total_cost: string | null;
+ latency: number | null;
};
export type Pricing = {
- id: string;
- model_name: string;
- pricing_unit: Generated<PricingUnit>;
- price: string;
- currency: Generated<string>;
- token_type: TokenType;
+ id: string;
+ model_name: string;
+ pricing_unit: Generated<PricingUnit>;
+ price: string;
+ currency: Generated<string>;
+ token_type: TokenType;
};
export type Project = {
- id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
- name: string;
- cloud_config: unknown | null;
+ id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
+ name: string;
+ cloud_config: unknown | null;
};
export type Prompt = {
- id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
- project_id: string;
- created_by: string;
- prompt: string;
- name: string;
- version: number;
- is_active: boolean;
- config: Generated<unknown>;
+ id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
+ project_id: string;
+ created_by: string;
+ prompt: string;
+ name: string;
+ version: number;
+ is_active: boolean;
+ config: Generated<unknown>;
};
export type Score = {
- id: string;
- timestamp: Generated<Timestamp>;
- name: string;
- value: number;
- comment: string | null;
- trace_id: string;
- observation_id: string | null;
+ id: string;
+ timestamp: Generated<Timestamp>;
+ name: string;
+ value: number;
+ comment: string | null;
+ trace_id: string;
+ observation_id: string | null;
};
export type Session = {
- id: string;
- session_token: string;
- user_id: string;
- expires: Timestamp;
+ id: string;
+ session_token: string;
+ user_id: string;
+ expires: Timestamp;
};
export type Trace = {
- id: string;
- external_id: string | null;
- timestamp: Generated<Timestamp>;
- name: string | null;
- user_id: string | null;
- metadata: unknown | null;
- release: string | null;
- version: string | null;
- project_id: string;
- public: Generated<boolean>;
- bookmarked: Generated<boolean>;
- tags: Generated<string[]>;
- input: unknown | null;
- output: unknown | null;
- session_id: string | null;
+ id: string;
+ external_id: string | null;
+ timestamp: Generated<Timestamp>;
+ name: string | null;
+ user_id: string | null;
+ metadata: unknown | null;
+ release: string | null;
+ version: string | null;
+ project_id: string;
+ public: Generated<boolean>;
+ bookmarked: Generated<boolean>;
+ tags: Generated<string[]>;
+ input: unknown | null;
+ output: unknown | null;
+ session_id: string | null;
};
export type TraceSession = {
- id: string;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
- project_id: string;
- bookmarked: Generated<boolean>;
- public: Generated<boolean>;
+ id: string;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
+ project_id: string;
+ bookmarked: Generated<boolean>;
+ public: Generated<boolean>;
};
export type User = {
- id: string;
- name: string | null;
- email: string | null;
- email_verified: Timestamp | null;
- password: string | null;
- image: string | null;
- admin: Generated<boolean>;
- created_at: Generated<Timestamp>;
- updated_at: Generated<Timestamp>;
- feature_flags: Generated<string[]>;
+ id: string;
+ name: string | null;
+ email: string | null;
+ email_verified: Timestamp | null;
+ password: string | null;
+ image: string | null;
+ admin: Generated<boolean>;
+ created_at: Generated<Timestamp>;
+ updated_at: Generated<Timestamp>;
+ feature_flags: Generated<string[]>;
};
export type VerificationToken = {
- identifier: string;
- token: string;
- expires: Timestamp;
+ identifier: string;
+ token: string;
+ expires: Timestamp;
};
export type DB = {
- Account: Account;
- api_keys: ApiKey;
- audit_logs: AuditLog;
- cron_jobs: CronJobs;
- dataset_items: DatasetItem;
- dataset_run_items: DatasetRunItems;
- dataset_runs: DatasetRuns;
- datasets: Dataset;
- events: Events;
- Example: Example;
- membership_invitations: MembershipInvitation;
- memberships: Membership;
- models: Model;
- observations: Observation;
- observations_view: ObservationView;
- pricings: Pricing;
- projects: Project;
- prompts: Prompt;
- scores: Score;
- Session: Session;
- trace_sessions: TraceSession;
- traces: Trace;
- users: User;
- verification_tokens: VerificationToken;
+ Account: Account;
+ api_keys: ApiKey;
+ audit_logs: AuditLog;
+ cron_jobs: CronJobs;
+ dataset_items: DatasetItem;
+ dataset_run_items: DatasetRunItems;
+ dataset_runs: DatasetRuns;
+ datasets: Dataset;
+ events: Events;
+ Example: Example;
+ membership_invitations: MembershipInvitation;
+ memberships: Membership;
+ models: Model;
+ observations: Observation;
+ observations_view: ObservationView;
+ pricings: Pricing;
+ projects: Project;
+ prompts: Prompt;
+ scores: Score;
+ Session: Session;
+ trace_sessions: TraceSession;
+ traces: Trace;
+ users: User;
+ verification_tokens: VerificationToken;
};