Skip to content

Commit ff54158

Browse files
committed
feat: ui does not need to repeat model input
If we find block_i such that block_(i+1) is a model block whose final input message was defined by block_i, then we can skip showing block_i. No sense in repeating ourselves... Signed-off-by: Nick Mitchell <[email protected]>
1 parent 61dfe6f commit ff54158

File tree

1 file changed

+28
-0
lines changed
  • pdl-live-react/src/view/timeline

1 file changed

+28
-0
lines changed

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

+28
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { type PdlBlock } from "../../pdl_ast"
44
import {
55
hasTimingInformation,
66
nonNullable,
7+
isLLMBlock,
8+
hasInput,
79
type PdlBlockWithTiming,
810
type NonScalarPdlBlock,
911
} from "../../helpers"
@@ -53,7 +55,33 @@ export function computeModel(block: unknown | PdlBlock): TimelineModel {
5355
}
5456
})
5557

58+
return squashProximateModelInputs(model)
59+
}
60+
61+
/**
62+
* We don't need to repeat model inputs as a separate top-level
63+
* element in the UI, since they will be presented in the model
64+
* blocks.
65+
*/
66+
function squashProximateModelInputs(model: TimelineModel): TimelineModel {
5667
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+
}
80+
}
81+
}
82+
return [...model, row]
83+
}, [] as TimelineModel)
84+
.reverse()
5785
}
5886

5987
function computeModelIter(

0 commit comments

Comments
 (0)