-
Notifications
You must be signed in to change notification settings - Fork 0
/
manual.html
62 lines (51 loc) · 1.53 KB
/
manual.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>llama2.c-emscripten example</title>
<script src="llama2.js"></script>
</head>
<body>
<input id="prompt" placeholder="Prompt"></input> <input type="button" id="generate" value="Generate"></input>
<script>
(async () => {
const llama2 = await new LLAMA2();
document.querySelector('#generate').addEventListener('click', async function() {
const prompt = document.querySelector('#prompt').value;
// UI
document.querySelector('#generate').remove();
document.querySelector('#prompt').remove();
const btn = document.createElement('button');
btn.innerHTML = prompt;
btn.disabled = true;
document.body.appendChild(btn);
const options = {
temperature: 0.9,
};
// this will emit a "tokens" event, handled below
llama2.manualStart(prompt);
});
llama2.on('tokens', async function(tokens) {
// UI
for (let i=0; i < 40; i++) {
const btn = document.createElement('button');
btn.innerHTML = tokens[i].str;
btn.id = tokens[i].index;
btn.className = 'continuation';
btn.addEventListener('click', onButtonClick);
document.body.appendChild(btn);
}
});
const onButtonClick = async function() {
const nextToken = parseInt(this.id);
// UI
this.className = '';
this.disabled = true;
document.querySelectorAll('.continuation').forEach(e => e.remove());
// this will emit a "tokens" event, handled above
llama2.manualNext(nextToken);
};
})();
</script>
</body>
</html>