async function sendPrompt() { document.getElementById("status").classList.remove("generate"); document.getElementById("status").classList.remove("done"); document.getElementById("status").classList.add("loading"); document.getElementById("status").innerText = "Loading"; const prompt = document.getElementById("prompt" ).value; const responseDiv = document.getElementById("response" ); responseDiv.textContent = ""; const response = await fetch("http://localhost:11434/api/generate", { method : "POST", headers : { "Content-Type": "application/json" }, body : JSON.stringify({ model : "deepseek-v2:16b", prompt : prompt, stream : true }) }); const reader = response.body.getReader(); const decoder = new TextDecoder("utf-8"); document.getElementById("status").classList.remove("loading"); document.getElementById("status").classList.remove("done"); document.getElementById("status").classList.add("generate"); document.getElementById("status").innerText = "Generate"; while (true) { const { done, value } = await reader.read(); if (done) { document.getElementById("status").classList.remove("loading"); document.getElementById("status").classList.remove("generate"); document.getElementById("status").classList.add("done"); document.getElementById("status").innerText = "Done"; break; } const chunk = decoder.decode(value, { stream: true }); const lines = chunk.trim().split("\n"); for (const line of lines) { if (line) { try { const json = JSON.parse(line); if (json.response) { responseDiv.textContent += json.response; } } catch (e) { console.warn("Failed:", line); } } } } }