master
bel 2023-06-17 14:36:41 -06:00
parent 1a7f783fe0
commit 0a3a7a0616
1 changed files with 25 additions and 13 deletions

View File

@ -9,19 +9,33 @@
} }
function startStream(newPrompt) { function startStream(newPrompt) {
body = new URLSearchParams(new FormData(newPrompt)).toString() body = new URLSearchParams(new FormData(newPrompt)).toString()
console.log(body) http("POST", "/api/v0/chatbot", (body, status) => {
http("POST", "/api/v0/chatbot", (body, status) => { if (status != 200) {
if (status != 200) { log(body)
log(body) return
return }
} }, body)
}, body) }
function pushStream(newMessage) {
body = new URLSearchParams(new FormData(newMessage)).toString()
newMessage.getElementsByTagName("button").disabled = true
newMessage.getElementsByTagName("input").disabled = true
http("PUT", "/api/v0/chatbot", (body, status) => {
newMessage.getElementsByTagName("button").disabled = false
newMessage.getElementsByTagName("input").disabled = false
if (status != 200) {
log(body)
return
}
log(body)
}, body)
} }
function log() { function log() {
console.log(arguments) console.log(arguments)
document.getElementById("debug-log").innerHTML += "\n" + new String(arguments) document.getElementById("debug-log").innerHTML += "\n" + new String(arguments)
} }
function http(method, remote, callback, body) { function http(method, remote, callback, body) {
@ -37,8 +51,6 @@
} }
xmlhttp.send(body); xmlhttp.send(body);
} }
function callback(responseBody, responseStatus) {
}
</script> </script>
</header> </header>
<body onload="loadStream()"> <body onload="loadStream()">
@ -51,7 +63,7 @@
</details> </details>
<details open=true> <details open=true>
<summary>Use your session</summary> <summary>Use your session</summary>
<form id="stream" onsubmit="return false;"> <form id="stream" onsubmit="pushStream(this); return false;">
<textarea id="stream-log" readonly=true></textarea> <textarea id="stream-log" readonly=true></textarea>
<div style="display: flex; flex-direction: row;"> <div style="display: flex; flex-direction: row;">
<input style="flex-grow: 1;" type="text" name="Message"/> <input style="flex-grow: 1;" type="text" name="Message"/>