Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 16 additions & 4 deletions pdl-live-react/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
ArgsBlock,
CodeBlock,
PdlModelInput,
LocalizedExpression,
} from "./pdl_ast"

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

export type ModelBlock = Extract<
PdlBlock,
LitellmModelBlock | GraniteioModelBlock
>
export type ModelBlock = LitellmModelBlock | GraniteioModelBlock

export type ModelBlockWithUsage = ModelBlock & {
pdl__usage: Required<MakeNonNullable<import("./pdl_ast").PdlUsage>>
Expand Down Expand Up @@ -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"
}
8 changes: 7 additions & 1 deletion pdl-live-react/src/view/detail/kind/Model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
Expand Down