Skip to content

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

fix(ui-jump-to-playground): look up llm api keys when model parsing (#6957)

Hassieb Pakzad1bdaed431464
diff --git a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
index 0986411a0c..ff85d10d5c 100644
--- a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
+++ b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
@@ -1,5 +1,5 @@
import { Terminal } from "lucide-react";
-import { useEffect, useState } from "react";
+import { useEffect, useState, useMemo } from "react";
import { useRouter } from "next/router";
import { z } from "zod";
@@ -29,6 +29,7 @@ import {
OpenAIResponseFormatSchema,
} from "@langfuse/shared";
import { useHasEntitlement } from "@/src/features/entitlements/hooks";
+import { api } from "@/src/utils/api";
import { cn } from "@/src/utils/tailwind";
type JumpToPlaygroundButtonProps = (
@@ -62,13 +63,40 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (
const [isAvailable, setIsAvailable] = useState<boolean>(false);
const isEntitled = useHasEntitlement("playground");
+ const apiKeys = api.llmApiKey.all.useQuery(
+ {
+ projectId: projectId as string,
+ },
+ { enabled: Boolean(projectId) },
+ );
+
+ const modelToProviderMap = useMemo(() => {
+ const modelProviderMap: Record<string, string> = {};
+
+ (apiKeys.data?.data ?? []).forEach((apiKey) => {
+ const { provider, customModels, withDefaultModels, adapter } = apiKey;
+ // add default models if enabled
+ if (withDefaultModels) {
+ (playgroundSupportedModels[adapter] ?? []).forEach((model) => {
+ modelProviderMap[model] = provider;
+ });
+ }
+
+ // add custom models if set
+ customModels.forEach((customModel) => {
+ modelProviderMap[customModel] = provider;
+ });
+ });
+ return modelProviderMap;
+ }, [apiKeys.data]);
+
useEffect(() => {
if (props.source === "prompt") {
setCapturedState(parsePrompt(props.prompt));
} else if (props.source === "generation") {
- setCapturedState(parseGeneration(props.generation));
+ setCapturedState(parseGeneration(props.generation, modelToProviderMap));
}
- }, [props]);
+ }, [props, modelToProviderMap]);
useEffect(() => {
if (capturedState) {
@@ -231,10 +259,11 @@ const parseGeneration = (
output: string | null;
metadata: string | null;
},
+ modelToProviderMap: Record<string, string>,
): PlaygroundCache => {
if (generation.type !== "GENERATION") return null;
- const modelParams = parseModelParams(generation);
+ const modelParams = parseModelParams(generation, modelToProviderMap);
const tools = parseTools(generation);
const structuredOutputSchema = parseStructuredOutputSchema(generation);
@@ -311,6 +340,7 @@ const parseGeneration = (
function parseModelParams(
generation: Omit<Observation, "input" | "output" | "metadata">,
+ modelToProviderMap: Record<string, string>,
):
| (Partial<UIModelParams> & Pick<UIModelParams, "provider" | "model">)
| undefined {
@@ -320,10 +350,7 @@ function parseModelParams(
| undefined = undefined;
if (generationModel) {
- const provider = Object.entries(playgroundSupportedModels).find(
- ([_, models]) =>
- generationModel ? models.some((m) => m === generationModel) : false,
- )?.[0];
+ const provider = modelToProviderMap[generationModel];
if (!provider) return;