Skip to content

Commit 879f5e9

Browse files
committed
fix: refinements to ui avoiding repeating model inputs
This also eliminates "<newline>" only blocks in the masonry ui. Signed-off-by: Nick Mitchell <[email protected]>
1 parent 10fa5b1 commit 879f5e9

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

pdl-live-react/src/view/masonry/model.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
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

4653
export default function computeModel(block: import("../../pdl_ast").PdlBlock) {

pdl-live-react/src/view/timeline/model.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -64,24 +64,21 @@ export function computeModel(block: unknown | PdlBlock): TimelineModel {
6464
* blocks.
6565
*/
6666
function 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

8784
function computeModelIter(

0 commit comments

Comments
 (0)