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,23 +637,20 @@
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 pColor = probColor(found ? found.prob : 0)
const pColor = found ? probColor(found.prob) : 'transparent'
const popoverChildren = html`
<div>
${completion_probabilities.map((cp, i) => {
return html`
<div key={i} class="prob-set">
${cp.probs.map((p, j) => {
<div class="prob-set">
${probs.map((p, index) => {
return html`
<div
key=${`${i}-${j}`}
key=${index}
title=${`prob: ${p.prob}`}
style=${{
padding: '0.3em',
backgroundColor: p.tok_str === cp.content ? probColor(p.prob) : 'transparent'
backgroundColor: p.tok_str === content ? probColor(p.prob) : 'transparent'
}}
>
<span>${p.tok_str}: </span>
@ -663,9 +660,6 @@
})}
</div>
`
})}
</div>
`
return html`
<${Popover} style=${{ backgroundColor: pColor }} popoverChildren=${popoverChildren}>${msg.content}</>