Chatbot






ZedHouse AI Chatbot


Welcome to ZedHouse AI Chatbot 🤖


async function sendMessage() { const userInput = document.getElementById("userInput").value.trim(); if (!userInput) return;

const chatBox = document.getElementById("chatBox"); chatBox.innerHTML += `

${userInput}

`; document.getElementById("userInput").value = "";

try { const response = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", "Authorization": "Bearer YOUR_API_KEY_HERE" }, body: JSON.stringify({ model: "gpt-3.5-turbo", messages: [{ role: "user", content: userInput }] }) });

if (!response.ok) { throw new Error(`API Error: ${response.status}`); }

const data = await response.json(); const botMessage = data.choices?.[0]?.message?.content || "Sorry, I couldn't process your request.";

chatBox.innerHTML += `

${botMessage}

`; chatBox.scrollTop = chatBox.scrollHeight; } catch (error) { chatBox.innerHTML += `

Error: ${error.message}

`; } }