Skip to content

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

fix: rbac UI for eval templates (#1869)

Max Deichmann9ae0708cca44
diff --git a/web/src/ee/features/evals/components/eval-template-detail.tsx b/web/src/ee/features/evals/components/eval-template-detail.tsx
index 5c22b4310e..e15eb28dd6 100644
--- a/web/src/ee/features/evals/components/eval-template-detail.tsx
+++ b/web/src/ee/features/evals/components/eval-template-detail.tsx
@@ -44,10 +44,6 @@ export const EvalTemplateDetail = () => {
},
);
- const llmApiKeys = api.llmApiKey.all.useQuery({
- projectId: projectId,
- });
-
return (
<div className="md:container">
<Header
@@ -76,16 +72,12 @@ export const EvalTemplateDetail = () => {
)
}
/>
- {allTemplates.isLoading ||
- !allTemplates.data ||
- llmApiKeys.isLoading ||
- !llmApiKeys.data ? (
+ {allTemplates.isLoading || !allTemplates.data ? (
<div>Loading...</div>
) : (
<EvalTemplateForm
projectId={projectId}
existingEvalTemplate={template.data ?? undefined}
- apiKeys={llmApiKeys.data?.data ?? []}
isEditing={isEditing}
setIsEditing={setIsEditing}
/>
diff --git a/web/src/ee/features/evals/components/template-form.tsx b/web/src/ee/features/evals/components/template-form.tsx
index 9ddf77a363..a33566dafa 100644
--- a/web/src/ee/features/evals/components/template-form.tsx
+++ b/web/src/ee/features/evals/components/template-form.tsx
@@ -44,11 +44,11 @@ import {
} from "@/src/components/ui/select";
import { TEMPLATES } from "@/src/ee/features/evals/components/templates";
import { Label } from "@/src/components/ui/label";
+import { useHasAccess } from "@/src/features/rbac/utils/checkAccess";
export const EvalTemplateForm = (props: {
projectId: string;
existingEvalTemplate?: EvalTemplate;
- apiKeys: RouterOutputs["llmApiKey"]["all"]["data"];
onFormSuccess?: () => void;
isEditing?: boolean;
setIsEditing?: (isEditing: boolean) => void;
@@ -177,7 +177,6 @@ export type EvalTemplateFormPreFill = {
export const InnerEvalTemplateForm = (props: {
projectId: string;
- apiKeys: RouterOutputs["llmApiKey"]["all"]["data"];
// pre-filled values from langfuse-defined template or template from db
preFilledFormValues?: EvalTemplateFormPreFill;
// template to be updated
@@ -212,15 +211,6 @@ export const InnerEvalTemplateForm = (props: {
setModelParams((prev) => ({ ...prev, [key]: value }));
};
- const getModelProvider = (model: string) => {
- return evalLLMModels.find((m) => m.model === model)?.provider;
- };
-
- const getApiKeyForModel = (model: string) => {
- const modelProvider = getModelProvider(model);
- return props.apiKeys.find((k) => k.provider === modelProvider);
- };
-
// updates the form based on the pre-filled data
// either form update or from langfuse-generated template
const form = useForm<z.infer<typeof formSchema>>({
@@ -436,31 +426,10 @@ export const InnerEvalTemplateForm = (props: {
availableModels={[...evalLLMModels]}
disabled={!props.isEditing}
/>
-
- <Label>API key</Label>
- <div>
- {getApiKeyForModel(modelParams.model) ? (
- <span className="mr-2 rounded-sm bg-gray-200 p-1 text-xs">
- {getApiKeyForModel(modelParams.model)?.displaySecretKey}
- </span>
- ) : undefined}
- </div>
- {/* Custom form message to include a link to the already existing prompt */}
- {!getApiKeyForModel(modelParams.model) ? (
- <div className="flex flex-col text-sm font-medium text-destructive">
- {"No LLM API key found."}
-
- <Link
- href={`/project/${props.projectId}/settings`}
- className="flex flex-row"
- >
- Create a new API key here. <ArrowTopRightIcon />
- </Link>
- </div>
- ) : undefined}
- <FormDescription>
- The API key is used for each evaluation and will incur costs.
- </FormDescription>
+ <LLMApiKeyComponent
+ projectId={props.projectId}
+ modelParams={modelParams}
+ />
</div>
</div>
@@ -482,3 +451,75 @@ export const InnerEvalTemplateForm = (props: {
</Form>
);
};
+
+export const LLMApiKeyComponent = (p: {
+ projectId: string;
+ modelParams: UIModelParams;
+}) => {
+ const hasAccess = useHasAccess({
+ projectId: p.projectId,
+ scope: "llmApiKeys:read",
+ });
+
+ if (!hasAccess) {
+ return (
+ <div>
+ <Label>API key</Label>
+ <p className="text-sm text-muted-foreground">
+ LLM API Key only visible to Owner and Admin roles.
+ </p>
+ </div>
+ );
+ }
+
+ const apiKeys = api.llmApiKey.all.useQuery({
+ projectId: p.projectId,
+ });
+
+ if (apiKeys.isLoading) {
+ return (
+ <div>
+ <Label>API key</Label>
+ <p className="text-sm text-muted-foreground">Loading...</p>
+ </div>
+ );
+ }
+
+ const getModelProvider = (model: string) => {
+ return evalLLMModels.find((m) => m.model === model)?.provider;
+ };
+
+ const getApiKeyForModel = (model: string) => {
+ const modelProvider = getModelProvider(model);
+ return apiKeys.data?.data.find((k) => k.provider === modelProvider);
+ };
+
+ return (
+ <div>
+ <Label>API key</Label>
+ <div>
+ {getApiKeyForModel(p.modelParams.model) ? (
+ <span className="mr-2 rounded-sm bg-gray-200 p-1 text-xs">
+ {getApiKeyForModel(p.modelParams.model)?.displaySecretKey}
+ </span>
+ ) : undefined}
+ </div>
+ {/* Custom form message to include a link to the already existing prompt */}
+ {!getApiKeyForModel(p.modelParams.model) ? (
+ <div className="flex flex-col text-sm font-medium text-destructive">
+ {"No LLM API key found."}
+
+ <Link
+ href={`/project/${p.projectId}/settings`}
+ className="flex flex-row"
+ >
+ Create a new API key here. <ArrowTopRightIcon />
+ </Link>
+ </div>
+ ) : undefined}
+ <p className="text-sm text-muted-foreground">
+ The API key is used for each evaluation and will incur costs.
+ </p>
+ </div>
+ );
+};
diff --git a/web/src/ee/features/evals/pages/new-template.tsx b/web/src/ee/features/evals/pages/new-template.tsx
index 88a83004a0..919b0958b7 100644
--- a/web/src/ee/features/evals/pages/new-template.tsx
+++ b/web/src/ee/features/evals/pages/new-template.tsx
@@ -1,7 +1,6 @@
import Header from "@/src/components/layouts/header";
import { EvalTemplateForm } from "@/src/ee/features/evals/components/template-form";
import { useHasAccess } from "@/src/features/rbac/utils/checkAccess";
-import { api } from "@/src/utils/api";
import { useRouter } from "next/router";
@@ -15,20 +14,10 @@ export default function NewTemplatesPage() {
return null;
}
- const llmApiKeys = api.llmApiKey.all.useQuery({
- projectId: projectId,
- });
-
- return llmApiKeys.isLoading || !llmApiKeys.data ? (
- <div>Loading...</div>
- ) : (
+ return (
<div className="md:container">
<Header title="Create eval template" />
- <EvalTemplateForm
- projectId={projectId}
- isEditing={true}
- apiKeys={llmApiKeys.data?.data ?? []}
- />
+ <EvalTemplateForm projectId={projectId} isEditing={true} />
</div>
);
}