refactor probs render & make pColor transparent if not found

This commit is contained in:
Jhen 2023-08-22 06:41:42 +08:00
parent af1ea58b60
commit 91b8be0877
2 changed files with 514 additions and 540 deletions

File diff suppressed because it is too large Load diff

View file

@ -637,30 +637,24 @@
return html`<${Probabilities} data=${splitData} />` return html`<${Probabilities} data=${splitData} />`
} }
const { probs } = completion_probabilities[0] const { probs, content } = completion_probabilities[0]
const found = probs.find(p => p.tok_str === msg.content) const found = probs.find(p => p.tok_str === msg.content)
const pColor = probColor(found ? found.prob : 0) const pColor = found ? probColor(found.prob) : 'transparent'
const popoverChildren = html` const popoverChildren = html`
<div> <div class="prob-set">
${completion_probabilities.map((cp, i) => { ${probs.map((p, index) => {
return html` return html`
<div key={i} class="prob-set"> <div
${cp.probs.map((p, j) => { key=${index}
return html` title=${`prob: ${p.prob}`}
<div style=${{
key=${`${i}-${j}`} padding: '0.3em',
title=${`prob: ${p.prob}`} backgroundColor: p.tok_str === content ? probColor(p.prob) : 'transparent'
style=${{ }}
padding: '0.3em', >
backgroundColor: p.tok_str === cp.content ? probColor(p.prob) : 'transparent' <span>${p.tok_str}: </span>
}} <span>${Math.floor(p.prob * 100)}%</span>
>
<span>${p.tok_str}: </span>
<span>${Math.floor(p.prob * 100)}%</span>
</div>
`
})}
</div> </div>
` `
})} })}