From d37be8dc9e341697a8f25c142192d962d7b9f5c3 Mon Sep 17 00:00:00 2001 From: Jhen Date: Wed, 2 Aug 2023 15:57:19 +0800 Subject: [PATCH] server : implement Probabilites --- examples/server/public/index.html | 47 +++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/examples/server/public/index.html b/examples/server/public/index.html index ff17c8a18..740154262 100644 --- a/examples/server/public/index.html +++ b/examples/server/public/index.html @@ -404,7 +404,46 @@ ` } - const Probabilites = (params) => { /* Not implemented yet */ } + const probColor = (p) => { + const r = Math.floor(192 * (1 - p)); + const g = Math.floor(192 * p); + return `rgba(${r},${g},0,0.75)`; + } + + const Probabilites = (params) => { + return params.data.map(msg => { + const { completion_probabilities } = msg; + + let pColor = 'transparent'; + if (completion_probabilities.length === 1) { + const { probs } = completion_probabilities[0] + const found = probs.find(p => p.tok_str === msg.content) + pColor = probColor(found ? found.prob : 0) + } + + const popoverChildren = html` +
+ ${completion_probabilities.map((cp, i) => { + return cp.probs.map((p, j) => { + return html` +
+ ${p.tok_str}: + ${p.prob} +
+ ` + }) + })} +
+ ` + + return html` + <${Popover} style=${{ backgroundColor: pColor}} popoverChildren=${popoverChildren}>${msg.content} + ` + }); + } // poor mans markdown replacement const Markdownish = (params) => { @@ -552,7 +591,7 @@ function App(props) { return html` -
+

llama.cpp

@@ -573,11 +612,13 @@ `; } - render(h(App), document.body); + render(h(App), document.querySelector('#container')); +
+