script.js
// β
REPLACE THIS WITH YOUR OWN OPENAI API KEY
const apiKey = "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"; // <-- Put your OpenAI API key here
const apiUrl = "https://api.openai.com/v1/chat/completions";
async function sendMessage() {
let userInput = document.getElementById("user-input").value.trim();
let chatBox = document.getElementById("chat-box");
if (userInput === "") return;
// Display user message
chatBox.innerHTML += `
You: ${userInput}
`; // Clear input field document.getElementById("user-input").value = ""; // Scroll to latest message chatBox.scrollTop = chatBox.scrollHeight; try { const response = await fetch(apiUrl, { method: "POST", headers: { "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json" }, body: JSON.stringify({ model: "gpt-4", // πΉ Use "gpt-3.5-turbo" if you want a cheaper option messages: [ { role: "system", content: "You are a veterinary AI assistant that helps answer pet-related health questions." }, { role: "user", content: userInput } ] }) }); const data = await response.json(); const botReply = data.choices[0].message.content; // Display bot response chatBox.innerHTML += `VetGPT: ${botReply}
`; // Scroll to latest message chatBox.scrollTop = chatBox.scrollHeight; } catch (error) { console.error("Error:", error); chatBox.innerHTML += `VetGPT: Sorry, I couldn't get an answer right now. Try again later. πΎ
`; } } function handleKeyPress(event) { if (event.key === "Enter") { sendMessage(); } }
VetGPT - Ask a Veterinarian
VetGPT - Ask a Veterinarian πΆπ±
VetGPT: Hi! Ask me anything about pet health! π©Ί