Commit
·
19eaf6a
1
Parent(s):
ab229ee
Display stats after generation
Browse files- dist/index.js +0 -0
- index.html +1 -0
- src/index.js +10 -1
- style/style.css +21 -2
dist/index.js
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|
index.html
CHANGED
|
@@ -71,6 +71,7 @@
|
|
| 71 |
<form>
|
| 72 |
<label class="output"
|
| 73 |
><span><b>Output</b></span>
|
|
|
|
| 74 |
<div id="output"></div>
|
| 75 |
</label>
|
| 76 |
</form>
|
|
|
|
| 71 |
<form>
|
| 72 |
<label class="output"
|
| 73 |
><span><b>Output</b></span>
|
| 74 |
+
<p class="info hidden" id="stats"></p>
|
| 75 |
<div id="output"></div>
|
| 76 |
</label>
|
| 77 |
</form>
|
src/index.js
CHANGED
|
@@ -108,6 +108,7 @@ document.getElementById("generate").onclick = async () => {
|
|
| 108 |
}
|
| 109 |
const request = {
|
| 110 |
stream: true,
|
|
|
|
| 111 |
messages: [
|
| 112 |
{
|
| 113 |
role: "user",
|
|
@@ -122,13 +123,16 @@ document.getElementById("generate").onclick = async () => {
|
|
| 122 |
};
|
| 123 |
|
| 124 |
let curMessage = "";
|
|
|
|
| 125 |
const generator = await engine.chatCompletion(request);
|
| 126 |
for await (const chunk of generator) {
|
| 127 |
const curDelta = chunk.choices[0]?.delta.content;
|
| 128 |
if (curDelta) {
|
| 129 |
curMessage += curDelta;
|
| 130 |
}
|
| 131 |
-
|
|
|
|
|
|
|
| 132 |
document.getElementById("output").textContent = curMessage;
|
| 133 |
}
|
| 134 |
const finalMessage = await engine.getMessage();
|
|
@@ -140,4 +144,9 @@ document.getElementById("generate").onclick = async () => {
|
|
| 140 |
} else {
|
| 141 |
document.getElementById("output").textContent = finalMessage;
|
| 142 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
};
|
|
|
|
| 108 |
}
|
| 109 |
const request = {
|
| 110 |
stream: true,
|
| 111 |
+
stream_options: { include_usage: true },
|
| 112 |
messages: [
|
| 113 |
{
|
| 114 |
role: "user",
|
|
|
|
| 123 |
};
|
| 124 |
|
| 125 |
let curMessage = "";
|
| 126 |
+
let usage = null;
|
| 127 |
const generator = await engine.chatCompletion(request);
|
| 128 |
for await (const chunk of generator) {
|
| 129 |
const curDelta = chunk.choices[0]?.delta.content;
|
| 130 |
if (curDelta) {
|
| 131 |
curMessage += curDelta;
|
| 132 |
}
|
| 133 |
+
if (chunk.usage) {
|
| 134 |
+
usage = chunk.usage;
|
| 135 |
+
}
|
| 136 |
document.getElementById("output").textContent = curMessage;
|
| 137 |
}
|
| 138 |
const finalMessage = await engine.getMessage();
|
|
|
|
| 144 |
} else {
|
| 145 |
document.getElementById("output").textContent = finalMessage;
|
| 146 |
}
|
| 147 |
+
if (usage) {
|
| 148 |
+
const stats = usage['extra'];
|
| 149 |
+
document.getElementById("stats").textContent = `Prefill: ${stats['prefill_tokens_per_s'].toFixed(2)}, Decode: ${stats['decode_tokens_per_s'].toFixed(2)}, Grammar Init: ${stats['grammar_init_ms'].toFixed(2)}, Grammar Overhead Per Token: ${stats['grammar_per_token_ms'].toFixed(2)}`;
|
| 150 |
+
document.getElementById("stats").classList.remove("hidden");
|
| 151 |
+
}
|
| 152 |
};
|
style/style.css
CHANGED
|
@@ -3,16 +3,18 @@
|
|
| 3 |
}
|
| 4 |
|
| 5 |
body {
|
| 6 |
-
padding: 2rem;
|
| 7 |
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
| 8 |
display: flex;
|
| 9 |
flex-direction: column;
|
| 10 |
flex-grow: 1;
|
| 11 |
background: white;
|
|
|
|
|
|
|
|
|
|
| 12 |
}
|
| 13 |
|
| 14 |
main {
|
| 15 |
-
width: 100
|
| 16 |
display: flex;
|
| 17 |
flex-grow: 1;
|
| 18 |
flex-direction: column;
|
|
@@ -125,6 +127,18 @@ textarea {
|
|
| 125 |
line-height: 1.4;
|
| 126 |
}
|
| 127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
#prompt {
|
| 129 |
height: 12rem;
|
| 130 |
}
|
|
@@ -167,12 +181,17 @@ button:hover {
|
|
| 167 |
}
|
| 168 |
|
| 169 |
@media (min-width: 1600px) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
main {
|
| 171 |
display: flex;
|
| 172 |
flex-direction: row;
|
| 173 |
justify-content: space-evenly;
|
| 174 |
align-items: start;
|
| 175 |
max-width: 1600px;
|
|
|
|
| 176 |
}
|
| 177 |
|
| 178 |
#right-col {
|
|
|
|
| 3 |
}
|
| 4 |
|
| 5 |
body {
|
|
|
|
| 6 |
font-family: -apple-system, BlinkMacSystemFont, "Arial", sans-serif;
|
| 7 |
display: flex;
|
| 8 |
flex-direction: column;
|
| 9 |
flex-grow: 1;
|
| 10 |
background: white;
|
| 11 |
+
position: relative;
|
| 12 |
+
margin: 0;
|
| 13 |
+
padding: 2rem;
|
| 14 |
}
|
| 15 |
|
| 16 |
main {
|
| 17 |
+
width: calc(100% - 4rem);
|
| 18 |
display: flex;
|
| 19 |
flex-grow: 1;
|
| 20 |
flex-direction: column;
|
|
|
|
| 127 |
line-height: 1.4;
|
| 128 |
}
|
| 129 |
|
| 130 |
+
.info {
|
| 131 |
+
font-size: .8em;
|
| 132 |
+
border: 1px solid #91caff;
|
| 133 |
+
border-radius: 8px;
|
| 134 |
+
background: #e6f4ff;
|
| 135 |
+
padding: 8px 12px;
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
.hidden {
|
| 139 |
+
display: none !important;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
#prompt {
|
| 143 |
height: 12rem;
|
| 144 |
}
|
|
|
|
| 181 |
}
|
| 182 |
|
| 183 |
@media (min-width: 1600px) {
|
| 184 |
+
body {
|
| 185 |
+
padding: 4rem;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
main {
|
| 189 |
display: flex;
|
| 190 |
flex-direction: row;
|
| 191 |
justify-content: space-evenly;
|
| 192 |
align-items: start;
|
| 193 |
max-width: 1600px;
|
| 194 |
+
margin-top: 4rem;
|
| 195 |
}
|
| 196 |
|
| 197 |
#right-col {
|