diff --git a/index.js b/index.js index 9ba89b4..20e663c 100644 --- a/index.js +++ b/index.js @@ -42,12 +42,10 @@ void (async () => { res.json({ success: true }) }) - app.post("/chat", async (req, res) => { + app.post("/chat", urlencoded({ "extended": true }), async (req, res) => { try { - const output = await chat(req.body.prompt, redisClient) - res.json({ - response: output - }) + const output = await chat(req.body.text, redisClient) + res.send(output) } catch(err) { console.log("Error in /chat", err) res.status(500).send(err) diff --git a/public/index.html b/public/index.html index 7297a5d..c1af42c 100644 --- a/public/index.html +++ b/public/index.html @@ -44,6 +44,10 @@ width: 100%; } +input[type="submit"]:disabled { + background-color: #888; +} + button:hover { background-color: #444; } @@ -83,7 +87,8 @@

Teach something to the AI

hx-push-url="false" hx-swap="none" hx-on::before-send="handleBeforeSend(event)" - hx-on::after-request="handleAfterRequest(event)" + hx-on::after-request="handleAfterAdd(event)" + hx-on::after-settle="alert('I learned something new!')" >
- +

@@ -127,14 +136,23 @@

Talk to the AI about your data

button.disabled = true } - function handleAfterRequest(event) { + function handleAfterAdd(event) { + const textArea = event.target.querySelector("textarea") + const button = event.target.querySelector("input[type='submit']") + + textArea.disabled = false + button.disabled = false + textArea.value = "" + alert("I learned something new!") + } + + function handleAfterChat(event) { const textArea = event.target.querySelector("textarea") const button = event.target.querySelector("input[type='submit']") textArea.disabled = false button.disabled = false textArea.value = "" - alert('I learned something new!') } function talk2data() {