Skip to content

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

fix: parse object type message content (#2239)

Hassieb Pakzad669167002a53
diff --git a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
index 9d64ea2d7d..39e8b84652 100644
--- a/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
+++ b/web/src/ee/features/playground/page/components/JumpToPlaygroundButton.tsx
@@ -1,24 +1,24 @@
import { Terminal } from "lucide-react";
import Link from "next/link";
+import { useEffect, useState } from "react";
+import { z } from "zod";
+import { createEmptyMessage } from "@/src/components/ChatMessages/utils/createEmptyMessage";
import { Button } from "@/src/components/ui/button";
import usePlaygroundCache from "@/src/ee/features/playground/page/hooks/usePlaygroundCache";
import { type PlaygroundCache } from "@/src/ee/features/playground/page/types";
+import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
+import { PromptType } from "@/src/features/prompts/server/utils/validation";
import useProjectIdFromURL from "@/src/hooks/useProjectIdFromURL";
import {
ChatMessageRole,
- supportedModels as playgroundSupportedModels,
type Observation,
type Prompt,
+ supportedModels as playgroundSupportedModels,
type UIModelParams,
ZodModelConfig,
} from "@langfuse/shared";
-import { useEffect, useState } from "react";
-import { PromptType } from "@/src/features/prompts/server/utils/validation";
-import { ChatMessageListSchema } from "@/src/features/prompts/components/NewPromptForm/validation";
-import { createEmptyMessage } from "@/src/components/ChatMessages/utils/createEmptyMessage";
-import { getIsCloudEnvironment } from "@/src/ee/utils/getIsCloudEnvironment";
type JumpToPlaygroundButtonProps = (
| {
@@ -76,9 +76,19 @@ export const JumpToPlaygroundButton: React.FC<JumpToPlaygroundButtonProps> = (
);
};
+const ParsedChatMessageListSchema = z.array(
+ z.object({
+ role: z.nativeEnum(ChatMessageRole),
+ content: z.union([
+ z.string(),
+ z.any().transform((v) => JSON.stringify(v, null, 2)),
+ ]),
+ }),
+);
+
const parsePrompt = (prompt: Prompt): PlaygroundCache => {
if (prompt.type === PromptType.Chat) {
- const parsedMessages = ChatMessageListSchema.safeParse(prompt.prompt);
+ const parsedMessages = ParsedChatMessageListSchema.safeParse(prompt.prompt);
return parsedMessages.success ? { messages: parsedMessages.data } : null;
} else {
@@ -109,14 +119,16 @@ const parseGeneration = (generation: Observation): PlaygroundCache => {
}
if (typeof input === "object") {
- const parsedMessages = ChatMessageListSchema.safeParse(input);
+ const parsedMessages = ParsedChatMessageListSchema.safeParse(input);
if (parsedMessages.success)
return { messages: parsedMessages.data, modelParams };
}
if (typeof input === "object" && "messages" in input) {
- const parsedMessages = ChatMessageListSchema.safeParse(input["messages"]);
+ const parsedMessages = ParsedChatMessageListSchema.safeParse(
+ input["messages"],
+ );
if (parsedMessages.success)
return { messages: parsedMessages.data, modelParams };