Skip to content

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

fix

Marc Klingend5d783fb0178
diff --git a/src/components/ui/code.tsx b/src/components/ui/code.tsx
index ab9506ff22..175528671b 100644
--- a/src/components/ui/code.tsx
+++ b/src/components/ui/code.tsx
@@ -40,6 +40,7 @@ const parseJsonInput = (jsonIn: string | unknown): string => {
if (
Array.isArray(jsonIn) &&
jsonIn.length > 0 &&
+ typeof jsonIn[0] === "object" &&
"role" in jsonIn[0] &&
"content" in jsonIn[0]
) {
@@ -47,6 +48,27 @@ const parseJsonInput = (jsonIn: string | unknown): string => {
.map((message) => `${message.role.toUpperCase()}\n\n${message.content}`)
.join("\n\n------\n\n");
}
+
+ // If it is an array with a single string, return the string
+ // [ "<string>" ] -> "<string>"
+ if (
+ Array.isArray(jsonIn) &&
+ jsonIn.length === 1 &&
+ typeof jsonIn[0] === "string"
+ ) {
+ return jsonIn[0];
+ }
+
+ // If it is an Object with a single key, listed in the list of keys, return the value if it is a string
+ // { "<key>": "<string>" } -> "<string>"
+ const keys = ["input", "output", "text"];
+ if (
+ Object.keys(jsonIn).length === 1 &&
+ keys.includes(Object.keys(jsonIn)[0] as string) &&
+ typeof Object.values(jsonIn)[0] === "string"
+ ) {
+ return Object.values(jsonIn)[0] as string;
+ }
}
if (typeof jsonIn === "string") return jsonIn;