Skip to content

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

fix: only openai adapter for evals (#2960)

Max Deichmanneea1e8d0540b
diff --git a/web/src/components/ModelParameters/index.tsx b/web/src/components/ModelParameters/index.tsx
index ded3d396bb..ea3207e325 100644
--- a/web/src/components/ModelParameters/index.tsx
+++ b/web/src/components/ModelParameters/index.tsx
@@ -48,8 +48,11 @@ export const ModelParameters: React.FC<ModelParamsContext> = ({
<p className="font-semibold">Model</p>
{availableProviders.length === 0 ? (
<>
- <p className="text-sm">No LLM API key set in project.</p>
- <CreateLLMApiKeyDialog />
+ <p className="text-sm">
+ No LLM API key set in project. For evals, we only support OpenAI so
+ far.
+ </p>
+ <CreateLLMApiKeyDialog evalModelsOnly={true} />
</>
) : (
<div className="space-y-4">
diff --git a/web/src/ee/features/evals/server/router.ts b/web/src/ee/features/evals/server/router.ts
index dcdb3c073a..e14326c852 100644
--- a/web/src/ee/features/evals/server/router.ts
+++ b/web/src/ee/features/evals/server/router.ts
@@ -6,7 +6,11 @@ import {
} from "@/src/server/api/trpc";
import { throwIfNoProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";
import { auditLog } from "@/src/features/audit-logs/auditLog";
-import { DEFAULT_TRACE_JOB_DELAY, EvalTargetObject } from "@langfuse/shared";
+import {
+ DEFAULT_TRACE_JOB_DELAY,
+ EvalTargetObject,
+ LLMAdapter,
+} from "@langfuse/shared";
import {
ZodModelConfig,
singleFilter,
@@ -333,6 +337,22 @@ export const evalRouter = createTRPCRouter({
scope: "evalTemplate:create",
});
+ const matchingLLMKey = await ctx.prisma.llmApiKeys.findFirst({
+ where: {
+ projectId: input.projectId,
+ provider: input.provider,
+ },
+ });
+
+ if (!matchingLLMKey) {
+ throw new Error("No matching LLM key found for provider");
+ }
+
+ // check that the adapter on the api key is openai for evals
+ if (matchingLLMKey.adapter !== LLMAdapter.OpenAI) {
+ throw new Error("Only OpenAI models are supported for evals");
+ }
+
const latestTemplate = await ctx.prisma.evalTemplate.findFirst({
where: {
projectId: input.projectId,
diff --git a/web/src/ee/features/playground/page/hooks/useModelParams.ts b/web/src/ee/features/playground/page/hooks/useModelParams.ts
index 9250ff5729..de5f2b54ec 100644
--- a/web/src/ee/features/playground/page/hooks/useModelParams.ts
+++ b/web/src/ee/features/playground/page/hooks/useModelParams.ts
@@ -31,8 +31,15 @@ export const useModelParams = ({
);
const availableProviders = useMemo(() => {
- return availableLLMApiKeys.data?.data.map((key) => key.provider) ?? [];
- }, [availableLLMApiKeys]);
+ const adapter =
+ (evalModelsOnly
+ ? availableLLMApiKeys.data?.data.filter(
+ (p) => p.adapter === LLMAdapter.OpenAI,
+ ) // for evals, we only support OpenAI
+ : availableLLMApiKeys.data?.data) ?? [];
+
+ return adapter.map((key) => key.provider) ?? [];
+ }, [availableLLMApiKeys.data?.data, evalModelsOnly]);
const selectedProviderApiKey = availableLLMApiKeys.data?.data.find(
(key) => key.provider === modelParams.provider.value,
diff --git a/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx b/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx
index ef041dc663..f07e8bc3f7 100644
--- a/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx
+++ b/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx
@@ -54,7 +54,11 @@ const formSchema = z
path: ["withDefaultModels"],
});
-export function CreateLLMApiKeyDialog() {
+export function CreateLLMApiKeyDialog({
+ evalModelsOnly,
+}: {
+ evalModelsOnly?: boolean;
+}) {
const projectId = useProjectIdFromURL();
const capture = usePostHogClientCapture();
const utils = api.useUtils();
@@ -216,11 +220,16 @@ export function CreateLLMApiKeyDialog() {
</SelectTrigger>
</FormControl>
<SelectContent>
- {Object.values(LLMAdapter).map((provider) => (
- <SelectItem value={provider} key={provider}>
- {provider}
- </SelectItem>
- ))}
+ {Object.values(LLMAdapter)
+ .filter(
+ (provider) =>
+ !evalModelsOnly || provider === LLMAdapter.OpenAI,
+ )
+ .map((provider) => (
+ <SelectItem value={provider} key={provider}>
+ {provider}
+ </SelectItem>
+ ))}
</SelectContent>
</Select>
<FormMessage />