Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added breakdown bar for context #76

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 78 additions & 3 deletions mikupad.html
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,31 @@
}
}

.contextBar {
height:1.25em;
border-radius:2px;
overflow:hidden;
}
.contextBar-contextModal {
margin-top:.25em;
}

.contextBar .percentagebar-Prompt {
background-color: #fff;
}
.contextBar .percentagebar-Memory {
background-color: #8c94ff;
}
.contextBar .percentagebar-WorldInfo {
background-color: #8cff94;
}
.contextBar .percentagebar-AuthorsNote {
background-color: #ff948c;
}
.contextBar .percentagebar-FreeContext {
background-color: #fff0;
}

@media (min-width: 767.98px) {
#sidebar .SelectBox:first-child, .horz-separator, .collapsible-group {
display: block !important;
Expand Down Expand Up @@ -2167,6 +2192,30 @@
style=${{ 'transform':'scaleX(-1)' }}/>
`};


const PercentageBar = ({ values, className, colors }) => {
// const color = colors ? colors : ["#fff","#8c94ff","#8cff94","#ff948c"]
const total = Object.values(values).reduce((acc, curr) => acc + curr, 0);
const percentages = Object.values(values).map(value => (value / total) * 100);

return html`
<div className="${className}" style=${{ opacity: "80%", background: 'grey', display: 'flex', flexDirection: 'row' }}>
${Object.keys(values).map((name, index) => html`
<div class="tooltip"
key=${index}
title='${name} (${percentages[index].toFixed(1)}%)'
className='${"percentagebar-" + name.replace(/[^a-z]/ig,"")}'
style=${{
...( colors ? { backgroundColor: colors[index], } : {} ),
width: percentages[index] + '%',
height: '100%'
}}>
</div>
`)}
</div>
`;
};

function Modal({ isOpen, onClose, title, description, children, ...props }) {
if (!isOpen) {
return null;
Expand Down Expand Up @@ -2278,7 +2327,7 @@
</${Modal}>`;
}

function ContextModal({ isOpen, closeModal, tokens, memoryTokens, authorNoteTokens, handleMemoryTokensChange, finalPromptText, defaultPresets, cancel }) {
function ContextModal({ isOpen, closeModal, tokens, contextLength, memoryTokens, authorNoteTokens, handleMemoryTokensChange, finalPromptText, defaultPresets, cancel }) {
return html`
<${Modal} isOpen=${isOpen} onClose=${closeModal}
title="Context"
Expand All @@ -2288,26 +2337,36 @@
<thead>
<tr>
<th></th>
<th>Prompt</th>
<th>Memory</th>
<th>World Info</th>
<th>Author's Note</th>
<th>Prompt</th>
<th></th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<th>Tokens</th>
<td>${tokens - authorNoteTokens.tokens - memoryTokens.tokensWI - memoryTokens.tokens}</td>
<td>${memoryTokens.tokens}</td>
<td>${memoryTokens.tokensWI}</td>
<td>${authorNoteTokens.tokens}</td>
<td>${tokens - authorNoteTokens.tokens - memoryTokens.tokensWI - memoryTokens.tokens}</td>
<td></td>
<td>${tokens}</td>
</tr>
</tbody>
</table>
<${PercentageBar}
className="contextBar contextBar-contextModal"
values=${{
"Prompt": tokens - authorNoteTokens.tokens - memoryTokens.tokensWI - memoryTokens.tokens,
"Memory": memoryTokens.tokens,
"World Info": memoryTokens.tokensWI,
"Author's Note": authorNoteTokens.tokens,
"Free Context": Math.max(contextLength - tokens, 0)
}}>
</${PercentageBar}>
</div>
<${CollapsibleGroup} label="Advanced Context Ordering">
<div id="context-order-desc">
Expand Down Expand Up @@ -3918,6 +3977,7 @@
const [showProbs, setShowProbs] = useState(true);
const [cancel, setCancel] = useState(null);
const [spellCheck, setSpellCheck] = usePersistentState('spellCheck', false);
const [showContextBar, setShowContextBar] = usePersistentState('showContextBar', false);
const [attachSidebar, setAttachSidebar] = usePersistentState('attachSidebar', false);
const [showProbsMode, setShowProbsMode] = usePersistentState('showProbsMode', 0);
const [highlightGenTokens, setHighlightGenTokens] = usePersistentState('highlightGenTokens', true);
Expand Down Expand Up @@ -5427,6 +5487,18 @@
</${CollapsibleGroup}>
${!!tokens && html`
<${InputBox} label="Tokens" value=${tokens} readOnly/>`}
${showContextBar && !!tokens && html`
<${PercentageBar}
className="contextBar"
values=${{
"Prompt": tokens - authorNoteTokens.tokens - memoryTokens.tokensWI - memoryTokens.tokens,
"Memory": memoryTokens.tokens,
"World Info": memoryTokens.tokensWI,
"Author's Note": authorNoteTokens.tokens,
"Free Context": Math.max(contextLength - tokens, 0)
}}>
</${PercentageBar}>
`}
<div className="buttons">
<button
title="Run next prediction (Ctrl + Enter)"
Expand Down Expand Up @@ -5489,6 +5561,8 @@
closeModal=${() => closeModal("prompt")}>
<${Checkbox} label="Enable spell checking"
value=${spellCheck} onValueChange=${setSpellCheck}/>
<${Checkbox} label="Show Context Breakdown Bar"
value=${showContextBar} onValueChange=${setShowContextBar}/>
<${Checkbox} label="Attach sidebar"
value=${attachSidebar} onValueChange=${setAttachSidebar}/>
<${Checkbox} label="Highlight generated tokens"
Expand Down Expand Up @@ -5533,6 +5607,7 @@
isOpen=${modalState.context}
closeModal=${() => closeModal("context")}
tokens=${tokens}
contextLength=${contextLength}
memoryTokens=${memoryTokens}
authorNoteTokens=${authorNoteTokens}
handleMemoryTokensChange=${handleMemoryTokensChange}
Expand Down