diff --git a/pdl-live-react/src/view/detail/kind/Model.tsx b/pdl-live-react/src/view/detail/kind/Model.tsx index bd09df4a5..c3c929a66 100644 --- a/pdl-live-react/src/view/detail/kind/Model.tsx +++ b/pdl-live-react/src/view/detail/kind/Model.tsx @@ -1,11 +1,50 @@ +import { stringify } from "yaml" + import Group from "../Group" import Result from "../../Result" +function tryJson(s: unknown) { + if (typeof s === "string") { + try { + return JSON.parse(s) + } catch (_err) { + // intentional fall-through + } + } + return s +} + export default function ModelItems({ block: { platform, model, input, result, parser }, }: { block: import("../../../pdl_ast").LitellmModelBlock }) { + const json = tryJson(result) + const resultForDisplay = Array.isArray(json) + ? json.map(({ sentence }) => sentence).join("\n") + : result + + const lang = Array.isArray(json) + ? undefined + : parser === "jsonl" || parser === "json" + ? "json" + : parser === "yaml" + ? "yaml" + : "plaintext" + + const meta = Array.isArray(json) + ? json.flatMap(({ meta }, idx) => + Object.entries(meta).map(([k, v]) => ( + + )), + ) + : undefined + return ( <> {typeof platform === "string" && ( @@ -13,16 +52,8 @@ export default function ModelItems({ )} {typeof model === "string" && } {typeof input === "string" && } - + + {meta} ) }