diff --git a/pdl-live-react/src/helpers.ts b/pdl-live-react/src/helpers.ts index 3fa7da637..06b904da4 100644 --- a/pdl-live-react/src/helpers.ts +++ b/pdl-live-react/src/helpers.ts @@ -7,6 +7,7 @@ import type { ArgsBlock, CodeBlock, PdlModelInput, + LocalizedExpression, } from "./pdl_ast" /** Re-export for convenience */ @@ -16,10 +17,7 @@ type MakeNonNullable = { [K in keyof T]-?: NonNullable } -export type ModelBlock = Extract< - PdlBlock, - LitellmModelBlock | GraniteioModelBlock -> +export type ModelBlock = LitellmModelBlock | GraniteioModelBlock export type ModelBlockWithUsage = ModelBlock & { pdl__usage: Required> @@ -317,3 +315,17 @@ export function extractCode({ code }: CodeBlock): string { return String(code) } + +function isExpr(e: unknown): e is LocalizedExpression { + return ( + e !== null && typeof e === "object" && "expr" in (e as LocalizedExpression) + ) +} + +export function extractModel({ model }: ModelBlock): string { + return typeof model === "string" + ? model + : isExpr(model) + ? String(model.pdl__result) + : "unknown" +} diff --git a/pdl-live-react/src/view/detail/kind/Model.tsx b/pdl-live-react/src/view/detail/kind/Model.tsx index f76048ab6..c837f3482 100644 --- a/pdl-live-react/src/view/detail/kind/Model.tsx +++ b/pdl-live-react/src/view/detail/kind/Model.tsx @@ -4,12 +4,18 @@ import Group from "../Group" import Result from "../../Result" import { capitalizeAndUnSnakeCase, + extractModel, extractStructuredModelResponse, + hasInput, ModelBlock, } from "../../../helpers" export default function ModelItems({ block }: { block: ModelBlock }) { - const { platform, model, input } = block + const { platform } = block + const model = extractModel(block) + const input = !hasInput(block) + ? undefined + : String(block.pdl__model_input[block.pdl__model_input.length - 1].content) const { meta } = extractStructuredModelResponse(block) const metaForDisplay = meta?.map(([k, v], idx) => (