🪢 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(playground): make including output optional (#10463)
Nimara1141b90b74d
diff --git a/web/src/features/playground/page/components/JumpToPlaygroundButton.tsx b/web/src/features/playground/page/components/JumpToPlaygroundButton.tsxindex dcb7b95c18..1cefa0d25b 100644--- a/web/src/features/playground/page/components/JumpToPlaygroundButton.tsx+++ b/web/src/features/playground/page/components/JumpToPlaygroundButton.tsx@@ -9,8 +9,10 @@ import {DropdownMenu,DropdownMenuContent,DropdownMenuItem,+ DropdownMenuSeparator,DropdownMenuTrigger,} from "@/src/components/ui/dropdown-menu";+import { Switch } from "@/src/components/ui/switch";import { usePersistedWindowIds } from "@/src/features/playground/page/hooks/usePersistedWindowIds";import {type PlaygroundCache,@@ -76,6 +78,7 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (const { addWindowWithId, clearAllCache } = usePersistedWindowIds();const [capturedState, setCapturedState] = useState<PlaygroundCache>(null);const [isAvailable, setIsAvailable] = useState<boolean>(false);+ const [includeOutput, setIncludeOutput] = useState<boolean>(false);// Generate a stable window ID based on the source dataconst stableWindowId = useMemo(() => {@@ -123,9 +126,11 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (if (promptData) {setCapturedState(parsePrompt(promptData));} else if (generationData) {- setCapturedState(parseGeneration(generationData, modelToProviderMap));+ setCapturedState(+ parseGeneration(generationData, modelToProviderMap, includeOutput),+ );}- }, [promptData, generationData, modelToProviderMap]);+ }, [promptData, generationData, modelToProviderMap, includeOutput]);useEffect(() => {if (capturedState) {@@ -211,6 +216,18 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (<Terminal className="mr-2 h-4 w-4" />Add to existing</DropdownMenuItem>+ {props.source === "generation" && (+ <>+ <DropdownMenuSeparator />+ <div className="flex items-center justify-between px-2 py-1.5">+ <span className="text-sm">Include output</span>+ <Switch+ checked={includeOutput}+ onCheckedChange={setIncludeOutput}+ />+ </div>+ </>+ )}</DropdownMenuContent></DropdownMenu>);@@ -259,6 +276,7 @@ const parseGeneration = (output: string | null;},modelToProviderMap: Record<string, string>,+ includeOutput: boolean = false,): PlaygroundCache => {if (!isGenerationLike(generation.type)) return null;@@ -352,41 +370,45 @@ const parseGeneration = (): [];- // process output for final assistant message- // this doesn't make that much sense, because the output is already the LLM result- // but some people wanted to have the entire thing, so that they can then iterate- // on the final result (e.g. ask it questions).- // NOTE: will probably remove later at some point on next playground release- let output = generation.output?.valueOf();- if (output && typeof output === "string") {- try {- output = JSON.parse(output);- } catch {- // ignore parse errors+ if (includeOutput) {+ // process output for final assistant message+ // this doesn't make that much sense, because the output is already the LLM result+ // but some people wanted to have the entire thing, so that they can then iterate+ // on the final result (e.g. ask it questions).+ // NOTE: will probably remove later at some point on next playground release+ let output = generation.output?.valueOf();+ if (output && typeof output === "string") {+ try {+ output = JSON.parse(output);+ } catch {+ // ignore parse errors+ }}- }- if (output && typeof output === "object") {- try {- const outResult = normalizeOutput(output, ctx);- const outputMessages = outResult.success- ? outResult.data- .map(convertChatMlToPlayground)- .filter(- (msg): msg is ChatMessage | PlaceholderMessage =>- msg !== null,- )- // Filter tool calls without results (i.e. assistant messages with tool_calls but no results)- // here, a tool was just selected by an LLM but not called yet.- // we don't want this in the playground, because we a) cannot run the playground- // and b) if we jump to the playground, we exactly want to test if the LLM selects the tool- .filter((msg) => msg.type !== ChatMessageType.AssistantToolCall)- : [];-- // Append output messages to input messages- messages = [...messages, ...outputMessages];- } catch {- // ignore output processing errors+ if (output && typeof output === "object") {+ try {+ const outResult = normalizeOutput(output, ctx);+ const outputMessages = outResult.success+ ? outResult.data+ .map(convertChatMlToPlayground)+ .filter(+ (msg): msg is ChatMessage | PlaceholderMessage =>+ msg !== null,+ )+ // Filter tool calls without results (i.e. assistant messages with tool_calls but no results)+ // here, a tool was just selected by an LLM but not called yet.+ // we don't want this in the playground, because we a) cannot run the playground+ // and b) if we jump to the playground, we exactly want to test if the LLM selects the tool+ .filter(+ (msg) => msg.type !== ChatMessageType.AssistantToolCall,+ )+ : [];++ // Append output messages to input messages+ messages = [...messages, ...outputMessages];+ } catch {+ // ignore output processing errors+ }}}diff --git a/web/src/utils/chatml/jumptoplayground.clienttest.ts b/web/src/utils/chatml/jumptoplayground.clienttest.tsindex d3f1501a0b..8d8eb7f3f0 100644--- a/web/src/utils/chatml/jumptoplayground.clienttest.ts+++ b/web/src/utils/chatml/jumptoplayground.clienttest.ts@@ -70,7 +70,7 @@ jest.mock("@langfuse/shared", () => {};});-import { normalizeInput } from "./adapters";+import { normalizeInput, normalizeOutput } from "./adapters";import { convertChatMlToPlayground } from "./playgroundConverter";import { extractTools } from "./extractTools";@@ -876,4 +876,45 @@ describe("Playground Jump Full Pipeline", () => {expect(firstMessage.tools![0].name).toBe("get_weather");expect(firstMessage.tools![1].name).toBe("search_web");});++ it("should respect includeOutput flag when jumping to playground, default to no output added", () => {+ // kinda a bad test mocking UI behavior and not really testing the UI.+ // but it should illustrate that the default behavior is to not include output! and document that.+ const input = {+ messages: [+ { role: "system", content: "You are a helpful assistant." },+ { role: "user", content: "What can you help me with?" },+ ],+ };+ const output = {+ role: "assistant",+ content: "I can help with many tasks!",+ };+ const ctx = {};++ // Process input (always happens)+ const inputMessages = normalizeInput(input, ctx)+ .data!.map(convertChatMlToPlayground)+ .filter((msg) => msg !== null);++ // Test 1: Default behavior (includeOutput=false) - only input passed to the playground+ expect(inputMessages.length).toBe(2);+ const secondMsg = inputMessages[1];+ if (secondMsg && "role" in secondMsg) {+ expect(secondMsg.role).toBe("user");+ }++ // Test 2: With includeOutput=true - input + output+ const outputMessages = normalizeOutput(output, ctx)+ .data!.map(convertChatMlToPlayground)+ .filter((msg) => msg !== null && msg.type !== "assistant-tool-call");++ const withOutput = [...inputMessages, ...outputMessages];+ expect(withOutput.length).toBe(3);+ const thirdMsg = withOutput[2];+ if (thirdMsg && "role" in thirdMsg) {+ expect(thirdMsg.role).toBe("assistant");+ expect(thirdMsg.content).toBe("I can help with many tasks!");+ }+ });});