File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed
Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff 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
2422export 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+ }
Original file line number Diff line number Diff line change @@ -4,12 +4,14 @@ import Group from "../Group"
44import Result from "../../Result"
55import {
66 capitalizeAndUnSnakeCase ,
7+ extractModel ,
78 extractStructuredModelResponse ,
89 ModelBlock ,
910} from "../../../helpers"
1011
1112export 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 ) => (
You can’t perform that action at this time.
0 commit comments