🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
import React from "react";
import {
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
FormDescription,
} from "@/src/components/ui/form";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/src/components/ui/select";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/src/components/ui/popover";
import {
Card,
CardDescription,
CardHeader,
CardTitle,
} from "@/src/components/ui/card";
import { Button } from "@/src/components/ui/button";
import { Info, CircleCheck } from "@langfuse/icons";
import { type DatasetStepProps } from "@/src/features/experiments/types/stepProps";
import { StepHeader } from "@/src/features/experiments/components/shared/StepHeader";
import { api } from "@/src/utils/api";
import { format } from "date-fns";
import { DatasetPicker } from "@/src/features/experiments/components/steps/DatasetPicker";
export const DatasetStep: React.FC<DatasetStepProps> = ({
projectId,
formState,
datasetState,
promptInfo,
}) => {
const { form } = formState;
const {
datasets,
selectedDatasetId,
expectedColumnsForDataset: expectedColumns,
validationResult,
} = datasetState;
const { selectedPromptName, selectedPromptVersion } = promptInfo;
// Fetch dataset versions when a dataset is selected
const { data: datasetVersions } = api.datasets.listDatasetVersions.useQuery(
{
projectId,
datasetId: selectedDatasetId || "",
},
{
enabled: !!selectedDatasetId,
},
);
return (
<div className="space-y-6">
<StepHeader
title="Dataset Selection"
description="Choose the dataset to run your experiment on. The dataset structure must match the prompt template variables."
/>
<FormField
control={form.control}
name="datasetId"
render={({ field }) => (
<FormItem>
<FormLabel>Dataset</FormLabel>
<div className="flex items-center gap-2">
<DatasetPicker
datasets={datasets ?? []}
selectedDatasetId={field.value}
onSelect={(datasetId) => {
field.onChange(datasetId);
form.clearErrors("datasetId");
}}
/>
{selectedPromptName && selectedPromptVersion !== null && (
<Popover>
<PopoverTrigger asChild>
<Button variant="outline" className="h-8">
Expected columns
</Button>
</PopoverTrigger>
<PopoverContent className="w-80">
<div className="space-y-2">
<h4 className="leading-none font-bold">
Expected Dataset Structure
</h4>
<p className="text-muted-foreground text-sm">
Based on prompt {selectedPromptName} v
{selectedPromptVersion}
</p>
<div className="space-y-1 pt-2">
<p className="text-sm font-bold">Input variables:</p>
<ul className="list-inside list-disc text-sm">
{expectedColumns.inputVariables.map((variable) => (
<li key={variable}>{variable}</li>
))}
</ul>
<p className="text-sm font-bold">Expected output:</p>
<ul className="list-inside list-disc text-sm">
<li>
{expectedColumns.outputVariableName} (
{expectedColumns.outputVariableType})
</li>
</ul>
</div>
</div>
</PopoverContent>
</Popover>
)}
</div>
<FormMessage />
</FormItem>
)}
/>
{selectedDatasetId && datasetVersions && datasetVersions.length > 0 && (
<FormField
control={form.control}
name="datasetVersion"
render={({ field }) => (
<FormItem>
<FormLabel>Dataset Version (Optional)</FormLabel>
<Select
onValueChange={(value) => {
if (value === "latest") {
field.onChange(undefined);
} else {
field.onChange(new Date(value));
}
}}
value={field.value ? field.value.toISOString() : "latest"}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Latest version" />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="latest">
Latest version (default)
</SelectItem>
{datasetVersions.map((version) => (
<SelectItem
key={version.toISOString()}
value={version.toISOString()}
>
{format(version, "MMM d, yyyy 'at' h:mm a")} (UTC)
</SelectItem>
))}
</SelectContent>
</Select>
<FormDescription>
Run the experiment using the dataset state at a specific point
in time. Defaults to the latest version.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
)}
{selectedDatasetId && (
<>
{validationResult?.isValid === false && (
<Card className="border-dark-yellow bg-light-yellow relative overflow-hidden rounded-md shadow-none group-data-[collapsible=icon]:hidden">
<CardHeader className="p-2">
<CardTitle className="text-dark-yellow flex items-center justify-between text-sm">
<span>Invalid configuration</span>
<Info size="base" />
</CardTitle>
<CardDescription className="text-foreground">
{validationResult?.message}
</CardDescription>
</CardHeader>
</Card>
)}
{validationResult?.isValid === true && (
<Card className="border-dark-green bg-light-green relative overflow-hidden rounded-md shadow-none group-data-[collapsible=icon]:hidden">
<CardHeader className="p-2">
<CardTitle className="text-dark-green flex items-center justify-between text-sm">
<span>Valid configuration</span>
<CircleCheck size="base" />
</CardTitle>
<div className="text-sm">
Matches between dataset items and prompt
variables/placeholders
<ul className="my-2 ml-2 list-inside list-disc">
{Object.entries(validationResult.variablesMap ?? {}).map(
([variable, count]) => (
<li key={variable}>
<strong>{variable}:</strong> {count} /{" "}
{validationResult?.isValid
? validationResult.totalItems
: "unknown"}
</li>
),
)}
</ul>
Items missing all required variables and placeholders will be
excluded from the dataset run.
</div>
</CardHeader>
</Card>
)}
</>
)}
</div>
);
};