Skip to content

Commit bf45410

Browse files
authored
Create ai-test.html
1 parent 0290f04 commit bf45410

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

src/ai-test.html

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Floating Widget Button</title>
7+
<link rel="stylesheet" href="style.css">
8+
</head>
9+
<body>
10+
11+
<button id="floatingButton">Forum AI</button>
12+
13+
<div id="widgetContainer" class="widget">
14+
<div class="widget-header">
15+
<h3>Chat With Forum AI</h3>
16+
<button id="closeWidgetButton">&times;</button>
17+
</div>
18+
<div class="widget-content">
19+
<div style="font-family: 'Courier New', monospace; color: #fff; background: linear-gradient(135deg, #2a003f, #1a1a2e); border-radius: 12px; padding: 20px; box-shadow: 0 0 15px #8a2be2; width: 100%; max-width: 400px; cursor: pointer;">
20+
<h4 style="font-size: 18px; margin: 0; color: #c0c0ff;">🤖 Forum AI: ChatGPT Assistant</h4>
21+
<p style="font-size: 14px; color: #b0b0ff; margin-top: 4px;">Made by kRxZy_kRxZy. Ask anything, Forum AI is here to help!</p>
22+
<div style="margin-top: 10px; border-top: 2px solid #8a2be2; padding-top: 15px;">
23+
<label for="userQuery" style="font-size: 14px; color: #ddd;">Your Question:</label>
24+
<input type="text" id="userQuery" placeholder="Ask me anything..." style="width: 100%; padding: 8px; border-radius: 5px; border: 1px solid #8a2be2; background-color: #333; color: #fff; font-size: 14px;">
25+
<button id="askButton" style="margin-top: 10px; padding: 10px 15px; background-color: #8a2be2; color: white; border: none; border-radius: 5px; width: 100%; font-size: 14px;">Ask Forum AI</button>
26+
</div>
27+
<div id="responseBox" style="margin-top: 15px; padding: 10px; background-color: #222; border-radius: 5px; color: #ddd; font-size: 14px; display: none;">
28+
<b>Forum AI's Response:</b>
29+
<p id="responseContent">I'm thinking... 🤔</p>
30+
</div>
31+
</div>
32+
33+
</div>
34+
</div>
35+
36+
<script src="script.js"></script>
37+
</body>
38+
</html>
39+
40+
<script>
41+
const apiKey = "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"; // Your provided API key
42+
43+
document.getElementById("askButton").addEventListener("click", async function() {
44+
const query = document.getElementById("userQuery").value;
45+
if (query.trim() === "") {
46+
alert("Please ask a question!");
47+
return;
48+
}
49+
50+
document.getElementById("responseBox").style.display = "block";
51+
document.getElementById("responseContent").textContent = "Processing...";
52+
53+
try {
54+
const res = await fetch("https://api.openai.com/v1/chat/completions", { // Updated endpoint for GPT-4 or GPT-3.5
55+
method: "POST",
56+
headers: {
57+
"Content-Type": "application/json",
58+
"Authorization": `Bearer ${apiKey}`,
59+
},
60+
body: JSON.stringify({
61+
model: "gpt-4", // or "gpt-3.5-turbo"
62+
messages: [{ role: "user", content: query }],
63+
max_tokens: 100,
64+
temperature: 0.7,
65+
}),
66+
});
67+
68+
const data = await res.json();
69+
const answer = data.choices[0].message.content.trim();
70+
document.getElementById("responseContent").textContent = answer;
71+
72+
} catch (err) {
73+
console.error(err);
74+
document.getElementById("responseContent").textContent = "Oops, something went wrong!";
75+
}
76+
});

0 commit comments

Comments
 (0)