File size: 650 Bytes
dff042c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function askAI() {
    const question = document.getElementById("userInput").value;
    const responseBox = document.getElementById("response");

    // Clear previous response and show loading...
    responseBox.innerText = "Thinking... 🤔";

    if (question.trim() === "") {
        responseBox.innerText = "Please enter a question.";
        return;
    }

    // Ask the question to the AI
    puter.ai.chat(question)
        .then(response => {
            responseBox.innerText = response;
        })
        .catch(error => {
            responseBox.innerText = "Oops! Something went wrong.";
            console.error(error);
        });
}