import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess"; import { ModelParameters } from "@/src/components/ModelParameters"; import { CardContent } from "@/src/components/ui/card"; import { Card } from "@/src/components/ui/card"; import { useModelParams } from "@/src/features/playground/page/hooks/useModelParams"; import { Button } from "@/src/components/ui/button"; import { api } from "@/src/utils/api"; import { showSuccessToast } from "@/src/features/notifications/showSuccessToast"; import { Skeleton } from "@/src/components/ui/skeleton"; import { useEvaluationModel } from "@/src/features/evals/hooks/useEvaluationModel"; import { DeleteEvaluationModelButton } from "@/src/components/deleteButton"; import { ManageDefaultEvalModel } from "@/src/features/evals/components/manage-default-eval-model"; import { useState } from "react"; import { DialogContent, DialogTrigger } from "@/src/components/ui/dialog"; import { getFinalModelParams } from "@/src/utils/getFinalModelParams"; import { Dialog } from "@/src/components/ui/dialog"; import { Pencil } from "lucide-react"; import { Popover, PopoverContent, PopoverTrigger, } from "@/src/components/ui/popover"; import { Label } from "@/src/components/ui/label"; import { Input } from "@/src/components/ui/input"; export function DefaultEvalModelSetup({ projectId }: { projectId: string }) { const utils = api.useUtils(); const [isEditing, setIsEditing] = useState(false); const [formError, setFormError] = useState(null); const hasWriteAccess = useHasProjectAccess({ projectId, scope: "evalDefaultModel:CUD", }); const { modelParams, setModelParams, updateModelParamValue, setModelParamEnabled, availableModels, providerModelCombinations, availableProviders, } = useModelParams(); const { selectedModel, isDefaultModelLoading } = useEvaluationModel( projectId, setModelParams, ); const { mutateAsync: upsertDefaultModel, isPending: isUpsertLoading } = api.defaultLlmModel.upsertDefaultModel.useMutation({ onSuccess: () => { showSuccessToast({ title: "Default evaluation model updated", description: "All running evaluators will use the new model.", }); utils.defaultLlmModel.fetchDefaultModel.invalidate({ projectId }); setFormError(null); setIsEditing(false); }, onError: (error) => { setFormError(error.message as string); }, }); const executeUpsertMutation = async () => { await upsertDefaultModel({ projectId, provider: modelParams.provider.value, adapter: modelParams.adapter.value, model: modelParams.model.value, modelParams: getFinalModelParams(modelParams), }); }; if (isDefaultModelLoading) { return ; } return ( <>

Default model

{selectedModel && ( )} { setIsEditing(open); if (!open) { setFormError(null); } }} > Default model configuration

} {...{ modelParams, availableModels, providerModelCombinations, availableProviders, updateModelParamValue, setModelParamEnabled, }} formDisabled={!hasWriteAccess} />
Select a model which supports function calling.
{selectedModel ? ( ) : ( )}
{formError ? (

Error: {formError}

) : null}
); } function UpdateButton({ projectId, isLoading, executeUpsertMutation, }: { projectId: string; isLoading: boolean; executeUpsertMutation: () => void; }) { const [confirmationInput, setConfirmationInput] = useState(""); const hasWriteAccess = useHasProjectAccess({ projectId, scope: "evalDefaultModel:CUD", }); const CONFIRMATION = "update"; return ( e.stopPropagation()} className="w-fit max-w-[500px]" >

Please confirm

Updating the default model will impact any currently running evaluators that use it. Please confirm that you want to proceed with this change.

setConfirmationInput(e.target.value)} />
); }