Created
May 14, 2023 21:37
-
-
Save yne/5d35b39b3887afad38ad28851d0fcc4a to your computer and use it in GitHub Desktop.
llama.cpp minimal websocket based interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang=en> | |
<!-- | |
clone+make llama.cpp, mkdir static, put this file as index.html in it, then run | |
websocketd --port=8080 --staticdir=static --binary=true ./main -m models/ggml-vic7b-uncensored-q4_0.bin -n 50 --interactive-first | |
--> | |
<form name=prompt style=display:grid> | |
<textarea name=stdin placeholder=prompt style=resize:vertical></textarea> | |
<button>send</button> | |
<pre style="white-space: break-spaces"><output name=stdout></output></pre> | |
<input type=hidden name=continue value=continue> | |
</form> | |
<script type=module> | |
const form = document.forms.prompt; | |
let showContinueTimer; | |
form.continue.onclick = ()=>{form.ws.send('\n');form.continue.type="hidden"}; | |
form.onsubmit = function() { | |
if (form.ws) form.ws.close(); | |
const prompt = form.stdin.value; | |
form.ws = new WebSocket(`ws://${location.host}`); | |
form.ws.addEventListener('open', ()=>form.ws.send(prompt.replace(/\n/g,'\\\n')+"\n")); | |
form.ws.addEventListener('message', ({data}) => data.text().then(txt=>{ | |
form.stdout.value += txt.replace(/\0/g, ''); | |
clearTimeout(showContinueTimer); | |
form.continue.type="hidden"; | |
showContinueTimer = setTimeout(() => { form.continue.type="button" }, 2000); | |
})); | |
form.stdout.value=prompt+"\n"; | |
form.stdin.value=""; | |
return false; | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment