MCPcopy
hub / github.com/bbycroft/llm-viz / renderInputAtTop

Function renderInputAtTop

src/llm/components/ModelCard.ts:264–323  ·  view source on GitHub ↗
(state: IProgramState)

Source from the content-addressed store, hash-verified

262}
263
264function renderInputAtTop(state: IProgramState) {
265 let layout = state.layout;
266 let render = state.render;
267
268 let inputTokBlk = layout.idxObj;
269
270 let topMid = new Vec3(inputTokBlk.x + inputTokBlk.dx/2, inputTokBlk.y - layout.margin);
271
272 let inCellH = 10;
273 let inCellW = 6;
274
275 let nCells = layout.shape.T;
276 let tl = new Vec3(topMid.x - inCellW * nCells / 2, topMid.y - inCellH);
277 let br = new Vec3(topMid.x + inCellW * nCells / 2, topMid.y);
278
279 let outputOpacity = state.display.topOutputOpacity ?? 1.0;
280
281 let lineOpts = makeLineOpts({ color: Vec4.fromHexColor("#000000", 0.2), mtx: new Mat4f(), thick: 1.5 });
282 let titleTextOpts: IFontOpts = { color: Vec4.fromHexColor("#666666", 1.0), mtx: lineOpts.mtx, size: 1.9 };
283
284 renderInputBoxes(state, layout, tl, br, inCellW, 4, lineOpts, { tokMixes: state.display.tokenColors, idxMixes: state.display.tokenIdxColors });
285
286 let inputTitle = "Input";
287 drawText(render.modelFontBuf, inputTitle, tl.x, tl.y - lineHeight(titleTextOpts), titleTextOpts);
288
289 {
290 let outCellH = 12;
291 let outBr = new Vec3(br.x, tl.y - 4);
292 let outTl = new Vec3(tl.x, outBr.y - outCellH);
293 renderOutputBoxes(state, layout, outTl, outBr, inCellW, 4, lineOpts, { opacity: outputOpacity, boldLast: outputOpacity < 1.0, tokMixes: state.display.tokenOutputColors });
294
295 let outputTitle = "Output";
296 let outputTextOpts = { ...titleTextOpts, color: titleTextOpts.color.mul(outputOpacity) };
297 drawText(render.modelFontBuf, outputTitle, outTl.x, outTl.y - lineHeight(titleTextOpts), outputTextOpts);
298 }
299
300 for (let i = 0; i < nCells; i++) {
301 let mixes = state.display.tokenIdxColors;
302
303 let lineOptsLocal = { ...lineOpts, color: mixColorValues(mixes, lineOpts.color, i) };
304
305 let tx = tl.x + (i + 0.5) * inCellW;
306 let ty = tl.y + layout.cell + inCellH;
307 let bx = cellPosition(layout, inputTokBlk, Dim.X, i) + 0.5 * layout.cell;
308 let by = inputTokBlk.y - 0.5 * layout.cell;
309
310 let midY1 = lerp(by, ty, 1/6);
311 let midY2 = lerp(by, ty, 3/4);
312
313 drawLine(state.render.lineRender, new Vec3(bx, by), new Vec3(bx, midY1), lineOptsLocal);
314 drawLine(state.render.lineRender, new Vec3(bx, midY1), new Vec3(tx, midY2), lineOptsLocal);
315 drawLine(state.render.lineRender, new Vec3(tx, midY2), new Vec3(tx, ty), lineOptsLocal);
316
317 let arrLen = 0.6;
318 let arrowLeft = new Vec3(bx - arrLen, by - arrLen);
319 let arrowRight = new Vec3(bx + arrLen, by - arrLen);
320 drawLine(state.render.lineRender, arrowLeft, new Vec3(bx, by), lineOptsLocal);
321 drawLine(state.render.lineRender, arrowRight, new Vec3(bx, by), lineOptsLocal);

Callers 1

drawModelCardFunction · 0.85

Calls 10

makeLineOptsFunction · 0.90
drawTextFunction · 0.90
lineHeightFunction · 0.90
cellPositionFunction · 0.90
lerpFunction · 0.90
renderInputBoxesFunction · 0.85
renderOutputBoxesFunction · 0.85
mixColorValuesFunction · 0.85
fromHexColorMethod · 0.80
mulMethod · 0.45

Tested by

no test coverage detected