Skip to content

Commit 1b11bae

Browse files
committed
fix: restore model in model block detail ui
Signed-off-by: Nick Mitchell <[email protected]>
1 parent c3cad16 commit 1b11bae

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

pdl-live-react/src/helpers.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type {
77
ArgsBlock,
88
CodeBlock,
99
PdlModelInput,
10+
LocalizedExpression,
1011
} from "./pdl_ast"
1112

1213
/** Re-export for convenience */
@@ -16,10 +17,7 @@ type MakeNonNullable<T> = {
1617
[K in keyof T]-?: NonNullable<T[K]>
1718
}
1819

19-
export type ModelBlock = Extract<
20-
PdlBlock,
21-
LitellmModelBlock | GraniteioModelBlock
22-
>
20+
export type ModelBlock = LitellmModelBlock | GraniteioModelBlock
2321

2422
export type ModelBlockWithUsage = ModelBlock & {
2523
pdl__usage: Required<MakeNonNullable<import("./pdl_ast").PdlUsage>>
@@ -317,3 +315,17 @@ export function extractCode({ code }: CodeBlock): string {
317315

318316
return String(code)
319317
}
318+
319+
function isExpr(e: unknown): e is LocalizedExpression {
320+
return (
321+
e !== null && typeof e === "object" && "expr" in (e as LocalizedExpression)
322+
)
323+
}
324+
325+
export function extractModel({ model }: ModelBlock): string {
326+
return typeof model === "string"
327+
? model
328+
: isExpr(model)
329+
? String(model.pdl__result)
330+
: "unknown"
331+
}

pdl-live-react/src/view/detail/kind/Model.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import Group from "../Group"
44
import Result from "../../Result"
55
import {
66
capitalizeAndUnSnakeCase,
7+
extractModel,
78
extractStructuredModelResponse,
89
ModelBlock,
910
} from "../../../helpers"
1011

1112
export default function ModelItems({ block }: { block: ModelBlock }) {
12-
const { platform, model, input } = block
13+
const { platform, input } = block
14+
const model = extractModel(block)
1315
const { meta } = extractStructuredModelResponse(block)
1416

1517
const metaForDisplay = meta?.map(([k, v], idx) => (

0 commit comments

Comments
 (0)