Something went wrong. Try again.
Something went wrong. Try again.
15 kB · 420 lines
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421pragma ComponentBehavior: Bound
import "../components"import ".."import "../components/ModuleData.js" as ModuleDataimport "PromptLabels.js" as PromptLabelsimport QtQuickimport Quickshellimport Quickshell.Ioimport Quickshell.Widgets
ClippingRectangle { id: root
required property var barWindow property var ipc: null property bool moduleVisible: true property int interval: 5000 property int activeInterval: 1000 property int rateWindowMs: 3000 property var models: [] property var generationSamples: ({}) property int promptLabelIndex: 0 property string activePromptLabel: "" property bool advancePromptLabel: false property bool generatingLastSample: false readonly property int activeCount: models.filter(model => model.active).length readonly property real tokensPerSecond: models.reduce((total, model) => total + (model.active && model.ratePhase === "generation" ? Number(model.tokensPerSecond || 0) : 0), 0) readonly property bool generating: models.some(model => model.active && model.ratePhase === "generation") readonly property bool prompting: models.some(model => model.active && model.ratePhase !== "generation") readonly property bool loading: models.some(model => model.status === "loading")
function refresh() { if (!moduleVisible || refreshRunner.running) return;
refreshRunner.run(); }
function applyOutput(output) { if (!moduleVisible) return;
const trimmed = output.trim(); if (trimmed.length === 0) { models = []; generationSamples = ({}); return; }
try { const parsed = ModuleData.parseObject(trimmed); const now = Date.now(); const nextModels = Array.isArray(parsed.models) ? parsed.models : []; for (const model of nextModels) updateRate(model, now);
const nextGenerating = nextModels.some(model => model.active && model.ratePhase === "generation"); const nextPrompting = nextModels.some(model => model.active && model.ratePhase !== "generation"); if (nextGenerating && !generatingLastSample) advancePromptLabel = true; if (nextPrompting && (activePromptLabel.length === 0 || advancePromptLabel)) { activePromptLabel = nextPromptLabel(); advancePromptLabel = false; } for (const model of nextModels) { if (model.active && model.ratePhase !== "generation") model.promptLabel = activePromptLabel; } generatingLastSample = nextGenerating;
for (const id of Object.keys(generationSamples)) { if (!nextModels.some(model => model.id === id)) delete generationSamples[id]; } models = nextModels; } catch (error) { models = []; generationSamples = ({}); } }
function updateRate(model, now) { model.tokensPerSecond = 0; model.ratePhase = ""; if (!model.active) { delete generationSamples[model.id]; return; }
const generationId = model.generationId.length > 0 ? model.generationId : "pending"; let state = generationSamples[model.id]; if (!state) { state = { generationId: generationId, samples: [], phase: "prompt" }; } else if (state.generationId === "pending" && generationId !== "pending") { state.generationId = generationId; state.samples = []; } else if (state.generationId !== generationId) { state = { generationId: generationId, samples: [], phase: "prompt" }; }
const sample = { timestamp: now, generated: Number(model.generationTokens || 0), prompt: Number(model.promptTokens || 0) }; let previous = state.samples[state.samples.length - 1]; if (previous && (sample.generated < previous.generated || sample.prompt < previous.prompt)) { state.samples = []; state.phase = "prompt"; previous = null; } state.samples.push(sample); state.samples = state.samples.filter(item => item.timestamp >= now - rateWindowMs); generationSamples[model.id] = state;
const first = state.samples[0]; const elapsed = sample.timestamp - first.timestamp; const promptTokens = Math.max(0, sample.prompt - first.prompt); const generatedTokens = Math.max(0, sample.generated - first.generated); if (generatedTokens > 0) state.phase = "generation";
const tokens = state.phase === "prompt" ? promptTokens : generatedTokens; model.tokensPerSecond = elapsed > 0 ? Math.max(0, tokens) * 1000 / elapsed : 0; model.ratePhase = state.phase; }
function nextPromptLabel() { const label = PromptLabels.values[promptLabelIndex]; promptLabelIndex = (promptLabelIndex + 1) % PromptLabels.values.length; return label; }
function currentPromptLabel() { return activePromptLabel || "Processing"; }
function rateText(value) { return Number(value || 0).toFixed(0); }
function compactStatusText() { if (activeCount === 0) return String(models.length); if (generating) return `${rateText(tokensPerSecond)} t/s`; return prompting ? currentPromptLabel() : "0 t/s"; }
function summaryStatusText() { if (activeCount === 0) return "All models idle"; if (generating) return `${activeCount} active · ${rateText(tokensPerSecond)} generated tokens/s`; return prompting ? `${activeCount} active · ${currentPromptLabel()}` : `${activeCount} active · 0 generated tokens/s`; }
function modelStatusText(model) { if (model.status === "loading") return "Loading"; if (!model.active) return "Idle"; return model.ratePhase === "prompt" ? (model.promptLabel || "Processing") : `${rateText(model.tokensPerSecond)} t/s`; }
function compactName(value) { return String(value || "Unknown model").replace(/^.*\//, "").replace(/-GGUF.*$/i, ""); }
function paramsText(value) { const params = Number(value || 0); return params > 0 ? `${(params / 1000000000).toFixed(1)}B param` : ""; }
function contextText(value) { const context = Number(value || 0); return context > 0 ? `${Math.round(context / 1024)}k ctx` : ""; }
function modelSpec(model) { const details = []; const vram = Number(model.vramBytes || 0); const params = paramsText(model.params); const context = contextText(model.contextSize); if (vram > 0) details.push(`${(vram / 1073741824).toFixed(1)} GiB VRAM`); if (params.length > 0) details.push(params); if (context.length > 0) details.push(context); return details.join(" · "); }
implicitWidth: compactContent.implicitWidth + 20 implicitHeight: 34 radius: 8 color: activeCount > 0 ? theme.alpha(theme.green, 0.38) : mouse.containsMouse ? theme.surface2 : theme.alpha(theme.surface0, 0.28) border.color: activeCount > 0 ? theme.alpha(theme.green, 0.72) : theme.alpha(theme.text, 0.1) border.width: 1 contentUnderBorder: true visible: moduleVisible && models.length > 0
Theme { id: theme }
Row { id: compactContent
anchors.centerIn: parent spacing: 6
Text { anchors.verticalCenter: parent.verticalCenter color: root.loading ? theme.yellow : theme.sky font.family: theme.fontFamily font.pixelSize: theme.barFontPixelSize text: "" textFormat: Text.PlainText }
Text { anchors.verticalCenter: parent.verticalCenter color: theme.text font.family: theme.fontFamily font.pixelSize: theme.barFontPixelSize text: root.compactStatusText() textFormat: Text.PlainText } }
MouseArea { id: mouse
anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton hoverEnabled: true onClicked: root.refresh() onContainsMouseChanged: { if (containsMouse) root.refresh(); } }
BarPopup { id: tooltipWindow
barWindow: root.barWindow anchorItem: root shown: mouse.containsMouse implicitWidth: 420 implicitHeight: detailsColumn.implicitHeight + 28
PopupSurface { anchors.fill: parent clip: true
Column { id: detailsColumn
anchors.fill: parent anchors.margins: 14 spacing: 10
Row { width: parent.width spacing: 8
Text { anchors.verticalCenter: parent.verticalCenter color: root.loading ? theme.yellow : theme.sky font.family: theme.fontFamily font.pixelSize: theme.barFontPixelSize + 4 text: "" }
Column { width: parent.width - 32 spacing: 2
Text { width: parent.width color: theme.text font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize + 2 font.bold: true text: `${root.models.length} model${root.models.length === 1 ? "" : "s"} loaded` }
Text { width: parent.width color: root.activeCount > 0 ? theme.green : theme.subtext0 font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize text: root.summaryStatusText() } } }
Repeater { model: root.models
Rectangle { id: modelRow
required property var modelData width: detailsColumn.width height: modelInfo.implicitHeight + 16 radius: 6 color: theme.alpha(theme.crust, 0.3) border.color: theme.alpha(modelData.active ? theme.green : modelData.status === "loading" ? theme.yellow : theme.text, 0.22) border.width: 1
Row { anchors.fill: parent anchors.margins: 8 spacing: 8
Text { anchors.verticalCenter: parent.verticalCenter color: modelRow.modelData.active ? theme.green : modelRow.modelData.status === "loading" ? theme.yellow : theme.overlay1 font.family: theme.fontFamily font.pixelSize: 11 text: "●" }
Column { id: modelInfo
width: parent.width - 20 spacing: 2
Row { width: parent.width spacing: 8
Text { width: parent.width - stateLabel.width - parent.spacing color: theme.text elide: Text.ElideMiddle font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize font.bold: true text: root.compactName(modelRow.modelData.id) }
Text { id: stateLabel
color: modelRow.modelData.active ? theme.green : modelRow.modelData.status === "loading" ? theme.yellow : theme.subtext0 font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize text: root.modelStatusText(modelRow.modelData) } }
Text { width: parent.width visible: text.length > 0 color: theme.subtext0 font.family: theme.fontFamily font.pixelSize: theme.tooltipFontPixelSize - 1 text: root.modelSpec(modelRow.modelData) } } } } } } } }
Timer { interval: root.models.length > 0 ? root.activeInterval : root.interval running: root.moduleVisible && interval > 0 repeat: true onTriggered: root.refresh() onIntervalChanged: { if (running) restart(); } }
HelperProcess { id: refreshRunner helper: "llama-models" onOutput: text => root.applyOutput(text) }
Connections { target: root.ipc function onRefreshRequested(name) { if (name === "llama-models" || name === "all") root.refresh(); } }
Component.onCompleted: refresh() onModuleVisibleChanged: { if (moduleVisible) refresh(); else { refreshRunner.cancel(); models = []; generationSamples = ({}); activePromptLabel = ""; advancePromptLabel = false; generatingLastSample = false; } }}