sreepathi-ravikumar commited on
Commit
dff042c
·
verified ·
1 Parent(s): b8303a7

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +22 -0
script.js ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function askAI() {
2
+ const question = document.getElementById("userInput").value;
3
+ const responseBox = document.getElementById("response");
4
+
5
+ // Clear previous response and show loading...
6
+ responseBox.innerText = "Thinking... 🤔";
7
+
8
+ if (question.trim() === "") {
9
+ responseBox.innerText = "Please enter a question.";
10
+ return;
11
+ }
12
+
13
+ // Ask the question to the AI
14
+ puter.ai.chat(question)
15
+ .then(response => {
16
+ responseBox.innerText = response;
17
+ })
18
+ .catch(error => {
19
+ responseBox.innerText = "Oops! Something went wrong.";
20
+ console.error(error);
21
+ });
22
+ }