Skip to content

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

feat(datasets): add metadata to dataset and datasetItems (#1756)

Marc Klingena70f1d58a59a
diff --git a/fern/apis/server/definition/commons.yml b/fern/apis/server/definition/commons.yml
index a9181f3df1..dc5e0ae9bf 100644
--- a/fern/apis/server/definition/commons.yml
+++ b/fern/apis/server/definition/commons.yml
@@ -127,6 +127,7 @@ types:
id: string
name: string
description: optional<string>
+ metadata: optional<unknown>
projectId: string
createdAt: datetime
updatedAt: datetime
@@ -151,6 +152,7 @@ types:
status: DatasetStatus
input: optional<unknown>
expectedOutput: optional<unknown>
+ metadata: optional<unknown>
sourceTraceId: optional<string>
sourceObservationId: optional<string>
datasetId: string
diff --git a/fern/apis/server/definition/dataset-items.yml b/fern/apis/server/definition/dataset-items.yml
index e7333d5962..e96b4f9758 100644
--- a/fern/apis/server/definition/dataset-items.yml
+++ b/fern/apis/server/definition/dataset-items.yml
@@ -26,6 +26,9 @@ types:
datasetName: string
input: optional<unknown>
expectedOutput: optional<unknown>
+ metadata: optional<unknown>
+ sourceTraceId: optional<string>
+ sourceObservationId: optional<string>
id:
type: optional<string>
docs: Dataset items are upserted on their id
diff --git a/fern/apis/server/definition/datasets.yml b/fern/apis/server/definition/datasets.yml
index 599d6c3103..e1499bda6b 100644
--- a/fern/apis/server/definition/datasets.yml
+++ b/fern/apis/server/definition/datasets.yml
@@ -47,3 +47,4 @@ types:
properties:
name: string
description: optional<string>
+ metadata: optional<unknown>
diff --git a/generated/postman/collection.json b/generated/postman/collection.json
index dca08b7a75..91d6dd6713 100644
--- a/generated/postman/collection.json
+++ b/generated/postman/collection.json
@@ -65,7 +65,7 @@
"auth": null,
"body": {
"mode": "raw",
- "raw": "{\n \"datasetName\": \"example\",\n \"input\": \"UNKNOWN\",\n \"expectedOutput\": \"UNKNOWN\",\n \"id\": \"example\"\n}",
+ "raw": "{\n \"datasetName\": \"example\",\n \"input\": \"UNKNOWN\",\n \"expectedOutput\": \"UNKNOWN\",\n \"metadata\": \"UNKNOWN\",\n \"sourceTraceId\": \"example\",\n \"sourceObservationId\": \"example\",\n \"id\": \"example\"\n}",
"options": {
"raw": {
"language": "json"
@@ -245,7 +245,7 @@
"auth": null,
"body": {
"mode": "raw",
- "raw": "{\n \"name\": \"example\",\n \"description\": \"example\"\n}",
+ "raw": "{\n \"name\": \"example\",\n \"description\": \"example\",\n \"metadata\": \"UNKNOWN\"\n}",
"options": {
"raw": {
"language": "json"
diff --git a/packages/shared/prisma/generated/types.ts b/packages/shared/prisma/generated/types.ts
index 89ad09ad46..716318834b 100644
--- a/packages/shared/prisma/generated/types.ts
+++ b/packages/shared/prisma/generated/types.ts
@@ -113,6 +113,7 @@ export type Dataset = {
id: string;
name: string;
description: string | null;
+ metadata: unknown | null;
project_id: string;
created_at: Generated<Timestamp>;
updated_at: Generated<Timestamp>;
@@ -122,6 +123,7 @@ export type DatasetItem = {
status: Generated<DatasetStatus>;
input: unknown | null;
expected_output: unknown | null;
+ metadata: unknown | null;
source_trace_id: string | null;
source_observation_id: string | null;
dataset_id: string;
diff --git a/packages/shared/prisma/migrations/20240417102742_metadata_on_dataset_and_dataset_item/migration.sql b/packages/shared/prisma/migrations/20240417102742_metadata_on_dataset_and_dataset_item/migration.sql
new file mode 100644
index 0000000000..cf01b1f184
--- /dev/null
+++ b/packages/shared/prisma/migrations/20240417102742_metadata_on_dataset_and_dataset_item/migration.sql
@@ -0,0 +1,5 @@
+-- AlterTable
+ALTER TABLE "dataset_items" ADD COLUMN "metadata" JSONB;
+
+-- AlterTable
+ALTER TABLE "datasets" ADD COLUMN "metadata" JSONB;
diff --git a/packages/shared/prisma/schema.prisma b/packages/shared/prisma/schema.prisma
index 162c129a13..e583807593 100644
--- a/packages/shared/prisma/schema.prisma
+++ b/packages/shared/prisma/schema.prisma
@@ -430,6 +430,7 @@ model Dataset {
id String @id @default(cuid())
name String
description String?
+ metadata Json?
projectId String @map("project_id")
project Project @relation(fields: [projectId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now()) @map("created_at")
@@ -447,6 +448,7 @@ model DatasetItem {
status DatasetStatus @default(ACTIVE)
input Json?
expectedOutput Json? @map("expected_output")
+ metadata Json?
sourceTraceId String? @map("source_trace_id")
sourceTrace Trace? @relation(fields: [sourceTraceId], references: [id], onDelete: SetNull)
sourceObservationId String? @map("source_observation_id")
diff --git a/packages/shared/prisma/seed.ts b/packages/shared/prisma/seed.ts
index e9609a9fb7..ad04570e65 100644
--- a/packages/shared/prisma/seed.ts
+++ b/packages/shared/prisma/seed.ts
@@ -240,6 +240,7 @@ async function main() {
description:
datasetNumber === 0 ? "Dataset test description" : undefined,
projectId: project2.id,
+ metadata: datasetNumber === 0 ? { key: "value" } : undefined,
},
});
@@ -268,6 +269,7 @@ async function main() {
Math.random() > 0.3
? "Creating a React component can be done in two ways: as a functional component or as a class component. Let's start with a basic example of both."
: undefined,
+ metadata: Math.random() > 0.5 ? { key: "value" } : undefined,
},
});
datasetItemIds.push(datasetItem.id);
diff --git a/web/generated/openapi-server/openapi.yml b/web/generated/openapi-server/openapi.yml
index 110d13734e..272fd9ad08 100644
--- a/web/generated/openapi-server/openapi.yml
+++ b/web/generated/openapi-server/openapi.yml
@@ -1529,6 +1529,8 @@ components:
description:
type: string
nullable: true
+ metadata:
+ nullable: true
projectId:
type: string
createdAt:
@@ -1592,6 +1594,8 @@ components:
nullable: true
expectedOutput:
nullable: true
+ metadata:
+ nullable: true
sourceTraceId:
type: string
nullable: true
@@ -1735,6 +1739,14 @@ components:
nullable: true
expectedOutput:
nullable: true
+ metadata:
+ nullable: true
+ sourceTraceId:
+ type: string
+ nullable: true
+ sourceObservationId:
+ type: string
+ nullable: true
id:
type: string
nullable: true
@@ -1790,6 +1802,8 @@ components:
description:
type: string
nullable: true
+ metadata:
+ nullable: true
required:
- name
HealthResponse:
diff --git a/web/src/__tests__/datasets.servertest.ts b/web/src/__tests__/datasets.servertest.ts
index ee50d69855..c59c107874 100644
--- a/web/src/__tests__/datasets.servertest.ts
+++ b/web/src/__tests__/datasets.servertest.ts
@@ -5,13 +5,55 @@ import { makeAPICall, pruneDatabase } from "@/src/__tests__/test-utils";
import { v4 } from "uuid";
describe("/api/public/datasets and /api/public/dataset-items API Endpoints", () => {
- beforeEach(async () => await pruneDatabase());
+ const traceId = v4();
+ const observationId = v4();
+ beforeEach(async () => {
+ await pruneDatabase();
+
+ // create sample trace and observation
+ const response = await makeAPICall("POST", "/api/public/ingestion", {
+ batch: [
+ {
+ id: v4(),
+ type: "trace-create",
+ timestamp: new Date().toISOString(),
+ body: {
+ id: traceId,
+ name: "trace-name",
+ userId: "user-1",
+ metadata: { key: "value" },
+ release: "1.0.0",
+ version: "2.0.0",
+ },
+ },
+ {
+ id: v4(),
+ type: "observation-create",
+ timestamp: new Date().toISOString(),
+ body: {
+ id: observationId,
+ traceId: traceId,
+ type: "GENERATION",
+ name: "generation-name",
+ startTime: "2021-01-01T00:00:00.000Z",
+ endTime: "2021-01-01T00:00:00.000Z",
+ modelParameters: { key: "value" },
+ input: { key: "value" },
+ metadata: { key: "value" },
+ version: "2.0.0",
+ },
+ },
+ ],
+ });
+ expect(response.status).toBe(207);
+ });
afterEach(async () => await pruneDatabase());
it("should create and get a dataset", async () => {
await makeAPICall("POST", "/api/public/datasets", {
name: "dataset-name",
description: "dataset-description",
+ metadata: { foo: "bar" },
});
const dbDataset = await prisma.dataset.findMany({
@@ -31,6 +73,7 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
expect(getDataset.body).toMatchObject({
name: "dataset-name",
description: "dataset-description",
+ metadata: { foo: "bar" },
});
});
@@ -51,6 +94,7 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
datasetName: "dataset-name-2",
input: { key: "value" },
expectedOutput: { key: "value" },
+ metadata: { key: "value-dataset-item" },
id: datasetItemId,
});
@@ -59,45 +103,6 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
datasetName: "dataset-name-2", // not included in db table
});
- const traceId = v4();
- const observationId = v4();
-
- const response = await makeAPICall("POST", "/api/public/ingestion", {
- batch: [
- {
- id: v4(),
- type: "trace-create",
- timestamp: new Date().toISOString(),
- body: {
- id: traceId,
- name: "trace-name",
- userId: "user-1",
- metadata: { key: "value" },
- release: "1.0.0",
- version: "2.0.0",
- },
- },
- {
- id: v4(),
- type: "observation-create",
- timestamp: new Date().toISOString(),
- body: {
- id: observationId,
- traceId: traceId,
- type: "GENERATION",
- name: "generation-name",
- startTime: "2021-01-01T00:00:00.000Z",
- endTime: "2021-01-01T00:00:00.000Z",
- modelParameters: { key: "value" },
- input: { key: "value" },
- metadata: { key: "value" },
- version: "2.0.0",
- },
- },
- ],
- });
- expect(response.status).toBe(207);
-
await makeAPICall("POST", "/api/public/dataset-run-items", {
datasetItemId: datasetItemId,
observationId: observationId,
@@ -136,6 +141,9 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
datasetName: "dataset-name",
input: { key: "value" },
expectedOutput: { key: "value" },
+ metadata: { key: "value-dataset-item" },
+ sourceTraceId: traceId,
+ sourceObservationId: observationId,
});
const dbDatasetItem = await prisma.datasetItem.findFirst({
where: {
@@ -159,6 +167,7 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
id: dbDatasetItem!.id,
input: { key: "value" },
expectedOutput: { key: "value" },
+ metadata: { key: "value-dataset-item" },
datasetName: "dataset-name", // not included in db table
},
],
@@ -173,7 +182,10 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
id: dbDatasetItem!.id,
input: { key: "value" },
expectedOutput: { key: "value" },
+ metadata: { key: "value-dataset-item" },
datasetName: "dataset-name", // not included in db table
+ sourceTraceId: traceId,
+ sourceObservationId: observationId,
});
});
@@ -186,6 +198,7 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
id: "dataset-item-id",
datasetName: "dataset-name",
input: { key: "value" },
+ metadata: { key: "value-dataset-item" },
});
expect(item1.status).toBe(200);
expect(item1.body).toMatchObject({
@@ -196,6 +209,7 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
id: "dataset-item-id",
datasetName: "dataset-name",
input: { key: "value2" },
+ metadata: ["hello-world"],
});
expect(item2.status).toBe(200);
expect(item2.body).toMatchObject({
@@ -208,6 +222,7 @@ describe("/api/public/datasets and /api/public/dataset-items API Endpoints", ()
});
expect(dbDatasetItem).not.toBeNull();
expect(dbDatasetItem?.input).toMatchObject({ key: "value2" });
+ expect(dbDatasetItem?.metadata).toMatchObject(["hello-world"]);
});
it("should create and get a dataset run", async () => {
diff --git a/web/src/components/layouts/header.tsx b/web/src/components/layouts/header.tsx
index b8031dcc9d..46518fc455 100644
--- a/web/src/components/layouts/header.tsx
+++ b/web/src/components/layouts/header.tsx
@@ -126,7 +126,7 @@ export default function Header({
</div>
{props.status && <StatusBadge type={props.status} />}
</div>
- <div className="flex items-center gap-3">
+ <div className="flex flex-wrap items-center gap-3">
{props.actionButtons ?? null}
</div>
</div>
diff --git a/web/src/components/trace/ObservationPreview.tsx b/web/src/components/trace/ObservationPreview.tsx
index bc23918a05..7c14768c26 100644
--- a/web/src/components/trace/ObservationPreview.tsx
+++ b/web/src/components/trace/ObservationPreview.tsx
@@ -134,6 +134,7 @@ export const ObservationPreview = (props: {
projectId={props.projectId}
input={observationWithInputAndOutput.data.input}
output={observationWithInputAndOutput.data.output}
+ metadata={preloadedObservation.metadata}
key={preloadedObservation.id}
/>
) : null}
diff --git a/web/src/components/trace/TracePreview.tsx b/web/src/components/trace/TracePreview.tsx
index e7a36fa5d8..4d73b1bc27 100644
--- a/web/src/components/trace/TracePreview.tsx
+++ b/web/src/components/trace/TracePreview.tsx
@@ -70,6 +70,7 @@ export const TracePreview = ({
projectId={trace.projectId}
input={trace.input}
output={trace.output}
+ metadata={trace.metadata}
key={trace.id}
/>
</div>
diff --git a/web/src/features/datasets/components/DatasetActionButton.tsx b/web/src/features/datasets/components/DatasetActionButton.tsx
index a691ba84cc..e5f5784901 100644
--- a/web/src/features/datasets/components/DatasetActionButton.tsx
+++ b/web/src/features/datasets/components/DatasetActionButton.tsx
@@ -11,6 +11,7 @@ import { useState } from "react";
import { DialogTrigger } from "@radix-ui/react-dialog";
import { DatasetForm } from "@/src/features/datasets/components/DatasetForm";
import { useHasAccess } from "@/src/features/rbac/utils/checkAccess";
+import { type Prisma } from "@langfuse/shared/src/db";
interface BaseDatasetButtonProps {
mode: "create" | "update" | "delete";
@@ -33,6 +34,7 @@ interface UpdateDatasetButtonProps extends BaseDatasetButtonProps {
datasetId: string;
datasetName: string;
datasetDescription?: string;
+ datasetMetadata?: Prisma.JsonValue;
icon?: boolean;
}
@@ -130,6 +132,7 @@ export const DatasetActionButton = (props: DatasetActionButtonProps) => {
datasetId={props.datasetId}
datasetName={props.datasetName}
datasetDescription={props.datasetDescription}
+ datasetMetadata={props.datasetMetadata}
/>
)}
</DialogContent>
diff --git a/web/src/features/datasets/components/DatasetForm.tsx b/web/src/features/datasets/components/DatasetForm.tsx
index 720193254f..5b149fda0a 100644
--- a/web/src/features/datasets/components/DatasetForm.tsx
+++ b/web/src/features/datasets/components/DatasetForm.tsx
@@ -14,6 +14,8 @@ import { api } from "@/src/utils/api";
import { useState } from "react";
import { usePostHog } from "posthog-js/react";
import { Input } from "@/src/components/ui/input";
+import { JsonEditor } from "@/src/components/json-editor";
+import { type Prisma } from "@langfuse/shared/src/db";
interface BaseDatasetFormProps {
mode: "create" | "update" | "delete";
@@ -36,6 +38,7 @@ interface UpdateDatasetFormProps extends BaseDatasetFormProps {
datasetId: string;
datasetName: string;
datasetDescription?: string;
+ datasetMetadata?: Prisma.JsonValue;
}
type DatasetFormProps =
@@ -51,6 +54,21 @@ const formSchema = z.object({
message: "Input should not be only whitespace",
}),
description: z.string(),
+ metadata: z.string().refine(
+ (value) => {
+ if (value === "") return true;
+ try {
+ JSON.parse(value);
+ return true;
+ } catch (error) {
+ return false;
+ }
+ },
+ {
+ message:
+ "Invalid input. Please provide a JSON object or double-quoted string.",
+ },
+ ),
});
export const DatasetForm = (props: DatasetFormProps) => {
@@ -63,10 +81,14 @@ export const DatasetForm = (props: DatasetFormProps) => {
? {
name: props.datasetName,
description: props.datasetDescription ?? "",
+ metadata: props.datasetMetadata
+ ? JSON.stringify(props.datasetMetadata, null, 2)
+ : "",
}
: {
name: "",
description: "",
+ metadata: "",
},
});
@@ -173,6 +195,24 @@ export const DatasetForm = (props: DatasetFormProps) => {
</FormItem>
)}
/>
+ <FormField
+ control={form.control}
+ name="metadata"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Metadata (optional)</FormLabel>
+ <FormControl>
+ <JsonEditor
+ defaultValue={field.value}
+ onChange={(v) => {
+ field.onChange(v);
+ }}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
</div>
)}
<Button
diff --git a/web/src/features/datasets/components/DatasetItemsTable.tsx b/web/src/features/datasets/components/DatasetItemsTable.tsx
index 32795139e4..eb965b6540 100644
--- a/web/src/features/datasets/components/DatasetItemsTable.tsx
+++ b/web/src/features/datasets/components/DatasetItemsTable.tsx
@@ -33,14 +33,17 @@ type RowData = {
createdAt: string;
input: Prisma.JsonValue;
expectedOutput: Prisma.JsonValue;
+ metadata: Prisma.JsonValue;
};
export function DatasetItemsTable({
projectId,
datasetId,
+ menuItems,
}: {
projectId: string;
datasetId: string;
+ menuItems?: React.ReactNode;
}) {
const { setDetailPageList } = useDetailPageLists();
const utils = api.useUtils();
@@ -169,6 +172,16 @@ export function DatasetItemsTable({
) : null;
},
},
+ {
+ accessorKey: "metadata",
+ header: "Metadata",
+ id: "metadata",
+ enableHiding: true,
+ cell: ({ row }) => {
+ const metadata = row.getValue("metadata") as RowData["metadata"];
+ return !!metadata ? <IOTableCell data={metadata} /> : null;
+ },
+ },
{
id: "actions",
accessorKey: "actions",
@@ -224,6 +237,7 @@ export function DatasetItemsTable({
createdAt: item.createdAt.toLocaleString(),
input: item.input,
expectedOutput: item.expectedOutput,
+ metadata: item.metadata,
};
};
@@ -240,6 +254,7 @@ export function DatasetItemsTable({
setColumnVisibility={setColumnVisibility}
rowHeight={rowHeight}
setRowHeight={setRowHeight}
+ actionButtons={menuItems}
/>
<DataTable
columns={columns}
diff --git a/web/src/features/datasets/components/DatasetRunsTable.tsx b/web/src/features/datasets/components/DatasetRunsTable.tsx
index 2ff6b9b853..a9ac5f15c3 100644
--- a/web/src/features/datasets/components/DatasetRunsTable.tsx
+++ b/web/src/features/datasets/components/DatasetRunsTable.tsx
@@ -33,6 +33,7 @@ type RowData = {
export function DatasetRunsTable(props: {
projectId: string;
datasetId: string;
+ menuItems?: React.ReactNode;
}) {
const [paginationState, setPaginationState] = useQueryParams({
pageIndex: withDefault(NumberParam, 0),
@@ -171,6 +172,7 @@ export function DatasetRunsTable(props: {
setColumnVisibility={setColumnVisibility}
rowHeight={rowHeight}
setRowHeight={setRowHeight}
+ actionButtons={props.menuItems}
/>
<DataTable
columns={columns}
diff --git a/web/src/features/datasets/components/DatasetsTable.tsx b/web/src/features/datasets/components/DatasetsTable.tsx
index 78e1d43d51..2901100ff3 100644
--- a/web/src/features/datasets/components/DatasetsTable.tsx
+++ b/web/src/features/datasets/components/DatasetsTable.tsx
@@ -17,6 +17,9 @@ import { MoreVertical } from "lucide-react";
import { useEffect } from "react";
import useColumnVisibility from "@/src/features/column-visibility/hooks/useColumnVisibility";
import { DataTableToolbar } from "@/src/components/table/data-table-toolbar";
+import { type Prisma } from "@langfuse/shared";
+import { IOTableCell } from "@/src/components/ui/CodeJsonViewer";
+import { useRowHeightLocalStorage } from "@/src/components/table/data-table-row-height-switch";
type RowData = {
key: {
@@ -28,11 +31,14 @@ type RowData = {
lastRunAt?: string;
countItems: number;
countRuns: number;
+ metadata: Prisma.JsonValue;
};
export function DatasetsTable(props: { projectId: string }) {
const { setDetailPageList } = useDetailPageLists();
+ const [rowHeight, setRowHeight] = useRowHeightLocalStorage("datasets", "s");
+
const [paginationState, setPaginationState] = useQueryParams({
pageIndex: withDefault(NumberParam, 0),
pageSize: withDefault(NumberParam, 50),
@@ -100,6 +106,16 @@ export function DatasetsTable(props: { projectId: string }) {
id: "lastRunAt",
enableHiding: true,
},
+ {
+ accessorKey: "metadata",
+ header: "Metadata",
+ id: "metadata",
+ enableHiding: true,
+ cell: ({ row }) => {
+ const metadata: RowData["metadata"] = row.getValue("metadata");
+ return !!metadata ? <IOTableCell data={metadata} /> : null;
+ },
+ },
{
id: "actions",
accessorKey: "actions",
@@ -145,6 +161,7 @@ export function DatasetsTable(props: { projectId: string }) {
lastRunAt: item.lastRunAt?.toLocaleString() ?? "",
countItems: item.countDatasetItems,
countRuns: item.countDatasetRuns,
+ metadata: item.metadata,
};
};
@@ -162,6 +179,8 @@ export function DatasetsTable(props: { projectId: string }) {
actionButtons={
<DatasetActionButton projectId={props.projectId} mode="create" />
}
+ rowHeight={rowHeight}
+ setRowHeight={setRowHeight}
/>
<DataTable
columns={columns}
@@ -189,6 +208,7 @@ export function DatasetsTable(props: { projectId: string }) {
}}
columnVisibility={columnVisibility}
onColumnVisibilityChange={setColumnVisibility}
+ rowHeight={rowHeight}
/>
</div>
);
diff --git a/web/src/features/datasets/components/EditDatasetItem.tsx b/web/src/features/datasets/components/EditDatasetItem.tsx
index 4483acd9c9..ad6d37d471 100644
--- a/web/src/features/datasets/components/EditDatasetItem.tsx
+++ b/web/src/features/datasets/components/EditDatasetItem.tsx
@@ -47,6 +47,21 @@ const formSchema = z.object({
"Invalid input. Please provide a JSON object or double-quoted string.",
},
),
+ metadata: z.string().refine(
+ (value) => {
+ if (value === "") return true;
+ try {
+ JSON.parse(value);
+ return true;
+ } catch (error) {
+ return false;
+ }
+ },
+ {
+ message:
+ "Invalid input. Please provide a JSON object or double-quoted string.",
+ },
+ ),
});
export const EditDatasetItem = ({
@@ -75,6 +90,12 @@ export const EditDatasetItem = ({
? JSON.stringify(datasetItem.expectedOutput, null, 2)
: "",
);
+ form.setValue(
+ "metadata",
+ datasetItem?.metadata
+ ? JSON.stringify(datasetItem.metadata, null, 2)
+ : "",
+ );
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [datasetItem]);
@@ -83,6 +104,7 @@ export const EditDatasetItem = ({
defaultValues: {
input: "",
expectedOutput: "",
+ metadata: "",
},
});
@@ -99,6 +121,7 @@ export const EditDatasetItem = ({
datasetItemId: datasetItem.id,
input: values.input,
expectedOutput: values.expectedOutput,
+ metadata: values.metadata,
});
setHasChanges(false);
}
@@ -154,6 +177,26 @@ export const EditDatasetItem = ({
)}
/>
</div>
+ <FormField
+ control={form.control}
+ name="metadata"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Metadata</FormLabel>
+ <FormControl>
+ <JsonEditor
+ defaultValue={field.value}
+ onChange={(v) => {
+ setHasChanges(true);
+ field.onChange(v);
+ }}
+ editable={hasAccess}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
<div className="flex justify-end">
<Button
type="submit"
diff --git a/web/src/features/datasets/components/NewDatasetItemButton.tsx b/web/src/features/datasets/components/NewDatasetItemButton.tsx
index 19c83bae68..0a2aff4cff 100644
--- a/web/src/features/datasets/components/NewDatasetItemButton.tsx
+++ b/web/src/features/datasets/components/NewDatasetItemButton.tsx
@@ -37,10 +37,8 @@ export const NewDatasetItemButton = (props: {
New item
</Button>
</DialogTrigger>
- <DialogContent className="h-[calc(100vh-5rem)] max-h-none w-[calc(100vw-5rem)] max-w-none">
- <DialogHeader>
- <DialogTitle>Create new dataset item</DialogTitle>
- </DialogHeader>
+ <DialogContent className="h-[calc(100vh-5rem)] max-h-none w-[calc(100vw-5rem)] max-w-none items-start">
+ <DialogHeader>Create new dataset item</DialogHeader>
<NewDatasetItemForm
projectId={props.projectId}
datasetId={props.datasetId}
diff --git a/web/src/features/datasets/components/NewDatasetItemForm.tsx b/web/src/features/datasets/components/NewDatasetItemForm.tsx
index f2f5cb40bf..8e1963ec71 100644
--- a/web/src/features/datasets/components/NewDatasetItemForm.tsx
+++ b/web/src/features/datasets/components/NewDatasetItemForm.tsx
@@ -56,6 +56,21 @@ const formSchema = z.object({
"Invalid input. Please provide a JSON object or double-quoted string.",
},
),
+ metadata: z.string().refine(
+ (value) => {
+ if (value === "") return true;
+ try {
+ JSON.parse(value);
+ return true;
+ } catch (error) {
+ return false;
+ }
+ },
+ {
+ message:
+ "Invalid input. Please provide a JSON object or double-quoted string.",
+ },
+ ),
});
export const NewDatasetItemForm = (props: {
@@ -64,6 +79,7 @@ export const NewDatasetItemForm = (props: {
observationId?: string;
input?: Prisma.JsonValue;
output?: Prisma.JsonValue;
+ metadata?: Prisma.JsonValue;
datasetId?: string;
className?: string;
onFormSuccess?: () => void;
@@ -76,6 +92,7 @@ export const NewDatasetItemForm = (props: {
datasetId: props.datasetId ?? "",
input: props.input ? JSON.stringify(props.input, null, 2) : "",
expectedOutput: props.output ? JSON.stringify(props.output, null, 2) : "",
+ metadata: props.metadata ? JSON.stringify(props.metadata, null, 2) : "",
},
});
@@ -141,7 +158,7 @@ export const NewDatasetItemForm = (props: {
</FormItem>
)}
/>
- <div className="grid flex-1 content-stretch gap-4 md:grid-cols-2">
+ <div className="grid gap-4 md:grid-cols-2">
<FormField
control={form.control}
name="input"
@@ -175,10 +192,26 @@ export const NewDatasetItemForm = (props: {
)}
/>
</div>
+ <FormField
+ control={form.control}
+ name="metadata"
+ render={({ field }) => (
+ <FormItem className="flex flex-col gap-2">
+ <FormLabel>Metadata</FormLabel>
+ <FormControl>
+ <JsonEditor
+ defaultValue={field.value}
+ onChange={field.onChange}
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
<Button
type="submit"
loading={createDatasetItemMutation.isLoading}
- className="w-full"
+ className="mt-auto w-full"
>
Add to dataset
</Button>
diff --git a/web/src/features/datasets/components/NewDatasetItemFromObservationButton.tsx b/web/src/features/datasets/components/NewDatasetItemFromObservationButton.tsx
index dc7cf8e790..e9ef1095f5 100644
--- a/web/src/features/datasets/components/NewDatasetItemFromObservationButton.tsx
+++ b/web/src/features/datasets/components/NewDatasetItemFromObservationButton.tsx
@@ -28,6 +28,7 @@ export const NewDatasetItemFromTrace = (props: {
observationId?: string;
input: Prisma.JsonValue;
output: Prisma.JsonValue;
+ metadata: Prisma.JsonValue;
}) => {
const [open, setOpen] = useState(false);
const session = useSession();
@@ -111,6 +112,7 @@ export const NewDatasetItemFromTrace = (props: {
projectId={props.projectId}
input={props.input}
output={props.output}
+ metadata={props.metadata}
onFormSuccess={() => setOpen(false)}
className="h-full overflow-y-auto"
/>
diff --git a/web/src/features/datasets/server/dataset-router.ts b/web/src/features/datasets/server/dataset-router.ts
index ebc7be48b1..85f740619c 100644
--- a/web/src/features/datasets/server/dataset-router.ts
+++ b/web/src/features/datasets/server/dataset-router.ts
@@ -43,6 +43,7 @@ export const datasetRouter = createTRPCRouter({
"datasets.id",
"datasets.name",
"datasets.description",
+ "datasets.metadata",
"datasets.created_at as createdAt",
"datasets.updated_at as updatedAt",
eb.fn.count("dataset_items.id").distinct().as("countDatasetItems"),
@@ -295,6 +296,7 @@ export const datasetRouter = createTRPCRouter({
datasetItemId: z.string(),
input: z.string().optional(),
expectedOutput: z.string().optional(),
+ metadata: z.string().optional(),
sourceTraceId: z.string().optional(),
sourceObservationId: z.string().optional(),
status: z.enum(["ACTIVE", "ARCHIVED"]).optional(),
@@ -327,6 +329,12 @@ export const datasetRouter = createTRPCRouter({
: input.expectedOutput !== undefined
? (JSON.parse(input.expectedOutput) as Prisma.InputJsonObject)
: undefined,
+ metadata:
+ input.metadata === ""
+ ? Prisma.DbNull
+ : input.metadata !== undefined
+ ? (JSON.parse(input.metadata) as Prisma.InputJsonObject)
+ : undefined,
sourceTraceId: input.sourceTraceId,
sourceObservationId: input.sourceObservationId,
status: input.status,
@@ -348,6 +356,7 @@ export const datasetRouter = createTRPCRouter({
projectId: z.string(),
name: z.string(),
description: z.string().nullish(),
+ metadata: z.string().nullish(),
}),
)
.mutation(async ({ input, ctx }) => {
@@ -361,6 +370,12 @@ export const datasetRouter = createTRPCRouter({
name: input.name,
description: input.description ?? undefined,
projectId: input.projectId,
+ metadata:
+ input.metadata === ""
+ ? Prisma.DbNull
+ : !!input.metadata
+ ? (JSON.parse(input.metadata) as Prisma.InputJsonObject)
+ : undefined,
},
});
@@ -382,6 +397,7 @@ export const datasetRouter = createTRPCRouter({
datasetId: z.string(),
name: z.string().nullish(),
description: z.string().nullish(),
+ metadata: z.string().nullish(),
}),
)
.mutation(async ({ input, ctx }) => {
@@ -398,6 +414,12 @@ export const datasetRouter = createTRPCRouter({
data: {
name: input.name ?? undefined,
description: input.description,
+ metadata:
+ input.metadata === ""
+ ? Prisma.DbNull
+ : !!input.metadata
+ ? (JSON.parse(input.metadata) as Prisma.InputJsonObject)
+ : undefined,
},
});
await auditLog({
@@ -442,6 +464,7 @@ export const datasetRouter = createTRPCRouter({
datasetId: z.string(),
input: z.string().nullish(),
expectedOutput: z.string().nullish(),
+ metadata: z.string().nullish(),
sourceTraceId: z.string().optional(),
sourceObservationId: z.string().optional(),
}),
@@ -476,6 +499,12 @@ export const datasetRouter = createTRPCRouter({
: !!input.expectedOutput
? (JSON.parse(input.expectedOutput) as Prisma.InputJsonObject)
: undefined,
+ metadata:
+ input.metadata === ""
+ ? Prisma.DbNull
+ : !!input.metadata
+ ? (JSON.parse(input.metadata) as Prisma.InputJsonObject)
+ : undefined,
datasetId: input.datasetId,
sourceTraceId: input.sourceTraceId,
sourceObservationId: input.sourceObservationId,
diff --git a/web/src/features/navigate-detail-pages/DetailPageNav.tsx b/web/src/features/navigate-detail-pages/DetailPageNav.tsx
index b0529ed2f1..f94ed97223 100644
--- a/web/src/features/navigate-detail-pages/DetailPageNav.tsx
+++ b/web/src/features/navigate-detail-pages/DetailPageNav.tsx
@@ -52,7 +52,7 @@ export const DetailPageNav = (props: {
if (ids.length > 1)
return (
- <div>
+ <div className="flex flex-row gap-2">
<Tooltip>
<TooltipTrigger asChild>
<Button
@@ -69,7 +69,6 @@ export const DetailPageNav = (props: {
);
}
}}
- className="mr-2"
>
<ChevronUp className="h-4 w-4" />
</Button>
diff --git a/web/src/pages/api/public/dataset-items.ts b/web/src/pages/api/public/dataset-items.ts
index 7effcb150e..a4135daf40 100644
--- a/web/src/pages/api/public/dataset-items.ts
+++ b/web/src/pages/api/public/dataset-items.ts
@@ -11,7 +11,10 @@ const CreateDatasetItemSchema = z.object({
datasetName: z.string(),
input: jsonSchema.nullish(),
expectedOutput: jsonSchema.nullish(),
+ metadata: jsonSchema.nullish(),
id: z.string().nullish(),
+ sourceTraceId: z.string().nullish(),
+ sourceObservationId: z.string().nullish(),
});
export default async function handler(
@@ -72,10 +75,16 @@ export default async function handler(
input: itemBody.input ?? undefined,
expectedOutput: itemBody.expectedOutput ?? undefined,
datasetId: dataset.id,
+ metadata: itemBody.metadata ?? undefined,
+ sourceTraceId: itemBody.sourceTraceId ?? undefined,
+ sourceObservationId: itemBody.sourceObservationId ?? undefined,
},
update: {
input: itemBody.input ?? undefined,
expectedOutput: itemBody.expectedOutput ?? undefined,
+ metadata: itemBody.metadata ?? undefined,
+ sourceTraceId: itemBody.sourceTraceId ?? undefined,
+ sourceObservationId: itemBody.sourceObservationId ?? undefined,
},
});
diff --git a/web/src/pages/api/public/datasets.ts b/web/src/pages/api/public/datasets.ts
index 13252cbc2f..ae5472205d 100644
--- a/web/src/pages/api/public/datasets.ts
+++ b/web/src/pages/api/public/datasets.ts
@@ -4,11 +4,12 @@ import { cors, runMiddleware } from "@/src/features/public-api/server/cors";
import { prisma } from "@langfuse/shared/src/db";
import { verifyAuthHeaderAndReturnScope } from "@/src/features/public-api/server/apiAuth";
import { isPrismaException } from "@/src/utils/exceptions";
-import { paginationZod } from "@/src/utils/zod";
+import { jsonSchema, paginationZod } from "@/src/utils/zod";
const CreateDatasetSchema = z.object({
name: z.string(),
description: z.string().nullish(),
+ metadata: jsonSchema.nullish(),
});
const GetDatasetsSchema = z.object({
@@ -40,7 +41,9 @@ export default async function handler(
JSON.stringify(req.body, null, 2),
);
- const { name, description } = CreateDatasetSchema.parse(req.body);
+ const { name, description, metadata } = CreateDatasetSchema.parse(
+ req.body,
+ );
// CHECK ACCESS SCOPE
if (authCheck.scope.accessLevel !== "all") {
@@ -61,9 +64,11 @@ export default async function handler(
name,
description: description ?? undefined,
projectId: authCheck.scope.projectId,
+ metadata: metadata ?? undefined,
},
update: {
description: description ?? null,
+ metadata: metadata ?? undefined,
},
});
@@ -84,6 +89,7 @@ export default async function handler(
select: {
name: true,
description: true,
+ metadata: true,
projectId: true,
createdAt: true,
updatedAt: true,
diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx
index 197c2965f4..5ed27687bc 100644
--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx
+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/index.tsx
@@ -7,6 +7,7 @@ import Link from "next/link";
import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNav";
import { DatasetActionButton } from "@/src/features/datasets/components/DatasetActionButton";
import { DeleteButton } from "@/src/components/deleteButton";
+import { JSONView } from "@/src/components/ui/CodeJsonViewer";
export default function Dataset() {
const router = useRouter();
@@ -47,6 +48,7 @@ export default function Dataset() {
datasetId={datasetId}
datasetName={dataset.data?.name ?? ""}
datasetDescription={dataset.data?.description ?? undefined}
+ datasetMetadata={dataset.data?.metadata}
icon
/>
<DeleteButton
@@ -61,18 +63,28 @@ export default function Dataset() {
</>
}
/>
- <Tabs value="runs" className="mb-3">
- <TabsList>
- <TabsTrigger value="runs">Runs</TabsTrigger>
- <TabsTrigger value="items" asChild>
- <Link href={`/project/${projectId}/datasets/${datasetId}/items`}>
- Items
- </Link>
- </TabsTrigger>
- </TabsList>
- </Tabs>
+ {!!dataset.data?.metadata && (
+ <JSONView json={dataset?.data.metadata} title="Metadata" />
+ )}
- <DatasetRunsTable projectId={projectId} datasetId={datasetId} />
+ <DatasetRunsTable
+ projectId={projectId}
+ datasetId={datasetId}
+ menuItems={
+ <Tabs value="runs">
+ <TabsList>
+ <TabsTrigger value="runs">Runs</TabsTrigger>
+ <TabsTrigger value="items" asChild>
+ <Link
+ href={`/project/${projectId}/datasets/${datasetId}/items`}
+ >
+ Items
+ </Link>
+ </TabsTrigger>
+ </TabsList>
+ </Tabs>
+ }
+ />
<p className="mt-3 text-xs text-gray-600">
Add new runs via Python or JS/TS SDKs. See{" "}
diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/items.tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/items.tsx
index 9f8aece60f..6f3ded1afe 100644
--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/items.tsx
+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/items.tsx
@@ -8,6 +8,7 @@ import { DetailPageNav } from "@/src/features/navigate-detail-pages/DetailPageNa
import { DatasetActionButton } from "@/src/features/datasets/components/DatasetActionButton";
import { DeleteButton } from "@/src/components/deleteButton";
import { NewDatasetItemButton } from "@/src/features/datasets/components/NewDatasetItemButton";
+import { JSONView } from "@/src/components/ui/CodeJsonViewer";
export default function DatasetItems() {
const router = useRouter();
@@ -55,6 +56,7 @@ export default function DatasetItems() {
datasetId={datasetId}
datasetName={dataset.data?.name ?? ""}
datasetDescription={dataset.data?.description ?? undefined}
+ datasetMetadata={dataset.data?.metadata}
icon
/>
<DeleteButton
@@ -69,18 +71,27 @@ export default function DatasetItems() {
</>
}
/>
- <Tabs value="items" className="mb-3">
- <TabsList>
- <TabsTrigger value="runs" asChild>
- <Link href={`/project/${projectId}/datasets/${datasetId}`}>
- Runs
- </Link>
- </TabsTrigger>
- <TabsTrigger value="items">Items</TabsTrigger>
- </TabsList>
- </Tabs>
- <DatasetItemsTable projectId={projectId} datasetId={datasetId} />
+ {!!dataset.data?.metadata && (
+ <JSONView json={dataset?.data.metadata} title="Metadata" />
+ )}
+
+ <DatasetItemsTable
+ projectId={projectId}
+ datasetId={datasetId}
+ menuItems={
+ <Tabs value="items">
+ <TabsList>
+ <TabsTrigger value="runs" asChild>
+ <Link href={`/project/${projectId}/datasets/${datasetId}`}>
+ Runs
+ </Link>
+ </TabsTrigger>
+ <TabsTrigger value="items">Items</TabsTrigger>
+ </TabsList>
+ </Tabs>
+ }
+ />
</div>
);
}
diff --git a/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsx b/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsx
index 4b3b232559..5935fb40cd 100644
--- a/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsx
+++ b/web/src/pages/project/[projectId]/datasets/[datasetId]/runs/[runId].tsx
@@ -44,19 +44,14 @@ export default function Dataset() {
/>
}
/>
- {!!run.data?.description && (
- <>
- <Header title="Description" level="h3" />
- <JSONView json={run.data.description} />
- </>
- )}
- {!!run.data?.metadata && (
- <>
- <Header title="Metadata" level="h3" />
- <JSONView json={run.data.metadata} />
- </>
- )}
- <Header title="Runs" level="h3" />
+ <div className="flex flex-col gap-2">
+ {!!run.data?.description && (
+ <JSONView json={run.data.description} title="Description" />
+ )}
+ {!!run.data?.metadata && (
+ <JSONView json={run.data.metadata} title="Metadata" />
+ )}
+ </div>
<DatasetRunItemsTable
projectId={projectId}
datasetId={datasetId}