🪢 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
fix(prompt-experiments): show form error if name is duplicated (#6189)
marliessophie4e4fbb510101
diff --git a/web/src/ee/features/experiments/components/CreateExperimentsForm.tsx b/web/src/ee/features/experiments/components/CreateExperimentsForm.tsxindex e68af86927..5d1c055a52 100644--- a/web/src/ee/features/experiments/components/CreateExperimentsForm.tsx+++ b/web/src/ee/features/experiments/components/CreateExperimentsForm.tsx@@ -79,6 +79,7 @@ import Link from "next/link";import { useHasEntitlement } from "@/src/features/entitlements/hooks";import { DropdownMenuItem } from "@/src/components/ui/dropdown-menu";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";+import { useExperimentNameValidation } from "@/src/ee/features/experiments/hooks/useExperimentNameValidation";const CreateExperimentData = z.object({name: z@@ -311,6 +312,17 @@ export const CreateExperimentsForm = ({const archiveEvaluatorMutation = api.evals.updateEvalJob.useMutation();+ const runNamesByDatasetId = api.datasets.baseRunDataByDatasetId.useQuery(+ { projectId, datasetId },+ { enabled: Boolean(datasetId) },+ );++ const allExperimentNames = useMemo(() => {+ return runNamesByDatasetId.data?.map((experiment) => ({+ value: experiment.name,+ }));+ }, [runNamesByDatasetId.data]);+// Watch model config changes and update formuseEffect(() => {form.setValue("modelConfig", {@@ -320,6 +332,12 @@ export const CreateExperimentsForm = ({});}, [modelParams, form]);+ useExperimentNameValidation({+ currentName: form.watch("name"),+ allExperimentNames,+ form,+ });+const onSubmit = async (data: CreateExperiment) => {capture("dataset_run:new_form_submit");const experiment = {@@ -895,8 +913,9 @@ export const CreateExperimentsForm = ({<Buttontype="submit"disabled={- Boolean(promptId && datasetId) &&- !validationResult.data?.isValid+ (Boolean(promptId && datasetId) &&+ !validationResult.data?.isValid) ||+ !!form.formState.errors.name}loading={form.formState.isSubmitting}>diff --git a/web/src/ee/features/experiments/hooks/useExperimentNameValidation.tsx b/web/src/ee/features/experiments/hooks/useExperimentNameValidation.tsxnew file mode 100644index 0000000000..398f21f209--- /dev/null+++ b/web/src/ee/features/experiments/hooks/useExperimentNameValidation.tsx@@ -0,0 +1,33 @@+import { useEffect } from "react";+import { type UseFormReturn } from "react-hook-form";++interface UseExperimentNameValidationProps {+ currentName: string | undefined;+ allExperimentNames: { value: string }[] | undefined;+ form: UseFormReturn<any>;+}++export const useExperimentNameValidation = ({+ currentName,+ allExperimentNames,+ form,+}: UseExperimentNameValidationProps) => {+ useEffect(() => {+ if (!currentName) {+ form.clearErrors("name");+ return;+ }++ const isNewExperiment = !allExperimentNames+ ?.map((experiment) => experiment.value)+ .includes(currentName);++ if (!isNewExperiment) {+ form.setError("name", {+ message: "Experiment name already exists for this dataset.",+ });+ } else {+ form.clearErrors("name");+ }+ }, [currentName, allExperimentNames, form]);+};diff --git a/web/src/features/prompts/hooks/usePromptNameValidation.tsx b/web/src/features/prompts/hooks/usePromptNameValidation.tsxindex affaf07386..0bc3ec027a 100644--- a/web/src/features/prompts/hooks/usePromptNameValidation.tsx+++ b/web/src/features/prompts/hooks/usePromptNameValidation.tsx@@ -20,7 +20,7 @@ export const usePromptNameValidation = ({.includes(currentName);if (!isNewPrompt) {- form.setError("name", { message: "Prompt name already exist." });+ form.setError("name", { message: "Prompt name already exists." });} else if (currentName === "new") {form.setError("name", { message: "Prompt name cannot be 'new'" });} else if (!/^[a-zA-Z0-9_\-.]+$/.test(currentName)) {