File tree Expand file tree Collapse file tree 2 files changed +22
-18
lines changed
Expand file tree Collapse file tree 2 files changed +22
-18
lines changed Original file line number Diff line number Diff line change 88 hasParser ,
99 hasScalarResult ,
1010 hasModelUsage ,
11+ hasResult ,
1112 hasTimingInformation ,
1213 capitalizeAndUnSnakeCase ,
1314 extractStructuredModelResponse ,
@@ -37,10 +38,16 @@ import { hasStabilityMetrics, type StabilityMetric } from "./stability"
3738} */
3839
3940/** Remove objects from the Masonry model that aren't helpful to display */
40- function removeFluff ( { kind } : { kind ?: string } ) {
41+ function removeFluff ( { kind, block } : Tile ) {
4142 // re: empty, these house only defs, which are spliced in below via
4243 // `withDefs()`
43- return kind !== "if" && kind !== "empty"
44+ return (
45+ kind !== "if" &&
46+ kind !== "empty" &&
47+ ( ! hasResult ( block ) ||
48+ typeof block . pdl__result !== "string" ||
49+ block . pdl__result . trim ( ) . length > 0 )
50+ )
4451}
4552
4653export default function computeModel ( block : import ( "../../pdl_ast" ) . PdlBlock ) {
Original file line number Diff line number Diff line change @@ -64,24 +64,21 @@ export function computeModel(block: unknown | PdlBlock): TimelineModel {
6464 * blocks.
6565 */
6666function squashProximateModelInputs ( model : TimelineModel ) : TimelineModel {
67- return model
68- . reduceRight ( ( model , row , idx , A ) => {
69- if ( idx < A . length - 1 ) {
70- const prior = A [ idx + 1 ] . block
71- if ( isLLMBlock ( prior ) && hasInput ( prior ) ) {
72- const lastInput =
73- prior . pdl__model_input [ prior . pdl__model_input . length - 1 ]
74- if ( ! ! lastInput && lastInput . defsite === row . id ) {
75- // Skip! We have found block_i such that block_(i+1) is a
76- // model block whose final input message was defined by
77- // block_i. No sense in repeating ourselves...
78- return model
79- }
67+ const modelInputDefsites = model . reduce (
68+ ( M , { block } ) => {
69+ if ( isLLMBlock ( block ) && hasInput ( block ) ) {
70+ const lastInput =
71+ block . pdl__model_input [ block . pdl__model_input . length - 1 ]
72+ if ( lastInput && typeof lastInput . defsite === "string" ) {
73+ M [ lastInput . defsite ] = true
8074 }
8175 }
82- return [ ...model , row ]
83- } , [ ] as TimelineModel )
84- . reverse ( )
76+ return M
77+ } ,
78+ { } as Record < string , boolean > ,
79+ )
80+
81+ return model . filter ( ( { id } ) => ! modelInputDefsites [ id ] ) . filter ( nonNullable )
8582}
8683
8784function computeModelIter (
You can’t perform that action at this time.
0 commit comments