Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions pdl-live-react/src/view/detail/kind/Model.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
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]) => (
<Result
key={k + "." + idx}
term={k}
result={typeof v === "object" ? stringify(v) : v}
lang={typeof v === "object" ? "yaml" : undefined}
/>
)),
)
: undefined

return (
<>
{typeof platform === "string" && (
<Group term="Platform" description={platform} />
)}
{typeof model === "string" && <Group term="Model" description={model} />}
{typeof input === "string" && <Group term="Input" description={input} />}
<Result
result={result}
lang={
parser === "jsonl" || parser === "json"
? "json"
: parser === "yaml"
? "yaml"
: "plaintext"
}
/>
<Result result={resultForDisplay} lang={lang} />
{meta}
</>
)
}
Loading