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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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>Chatbot Interface</title>
|
7 |
+
<!-- Load JetBrains Mono font from Google Fonts -->
|
8 |
+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
|
9 |
+
<style>
|
10 |
+
/* Global Styles */
|
11 |
+
body {
|
12 |
+
font-family: 'JetBrains Mono', monospace;
|
13 |
+
margin: 0;
|
14 |
+
padding: 0;
|
15 |
+
display: flex;
|
16 |
+
justify-content: center;
|
17 |
+
align-items: center;
|
18 |
+
height: 100vh;
|
19 |
+
background-color: #000; /* Vercel-like dark background */
|
20 |
+
color: #fff;
|
21 |
+
}
|
22 |
+
|
23 |
+
/* Chat Container */
|
24 |
+
.chat-container {
|
25 |
+
width: 500px;
|
26 |
+
background-color: #111; /* Dark container background */
|
27 |
+
border-radius: 12px;
|
28 |
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
29 |
+
overflow: hidden;
|
30 |
+
display: flex;
|
31 |
+
flex-direction: column;
|
32 |
+
}
|
33 |
+
|
34 |
+
/* Chat Header */
|
35 |
+
.chat-header {
|
36 |
+
background-color: #000; /* Vercel-like black header */
|
37 |
+
padding: 16px;
|
38 |
+
text-align: center;
|
39 |
+
font-size: 18px;
|
40 |
+
font-weight: 700;
|
41 |
+
border-bottom: 1px solid #333;
|
42 |
+
}
|
43 |
+
|
44 |
+
/* Chat Box */
|
45 |
+
.chat-box {
|
46 |
+
flex: 1;
|
47 |
+
padding: 16px;
|
48 |
+
overflow-y: auto;
|
49 |
+
background-color: #111;
|
50 |
+
}
|
51 |
+
|
52 |
+
/* Messages */
|
53 |
+
.message {
|
54 |
+
margin-bottom: 12px;
|
55 |
+
padding: 12px;
|
56 |
+
border-radius: 8px;
|
57 |
+
max-width: 80%;
|
58 |
+
font-size: 14px;
|
59 |
+
line-height: 1.5;
|
60 |
+
}
|
61 |
+
|
62 |
+
.user-message {
|
63 |
+
background-color: #007bff; /* Vercel-like blue */
|
64 |
+
color: #fff;
|
65 |
+
margin-left: auto;
|
66 |
+
}
|
67 |
+
|
68 |
+
.bot-message {
|
69 |
+
background-color: #222; /* Dark gray for bot messages */
|
70 |
+
color: #fff;
|
71 |
+
margin-right: auto;
|
72 |
+
}
|
73 |
+
|
74 |
+
.bot-message code {
|
75 |
+
display: block;
|
76 |
+
background-color: #000; /* Black background for code */
|
77 |
+
color: #00ff88; /* Vercel-like green for code */
|
78 |
+
padding: 12px;
|
79 |
+
border-radius: 6px;
|
80 |
+
margin-top: 10px;
|
81 |
+
font-family: 'JetBrains Mono', monospace;
|
82 |
+
white-space: pre-wrap;
|
83 |
+
font-size: 13px;
|
84 |
+
}
|
85 |
+
|
86 |
+
/* Typing Animation */
|
87 |
+
.typing-animation {
|
88 |
+
display: inline-block;
|
89 |
+
}
|
90 |
+
|
91 |
+
.typing-animation span {
|
92 |
+
display: inline-block;
|
93 |
+
width: 8px;
|
94 |
+
height: 8px;
|
95 |
+
background-color: #fff;
|
96 |
+
border-radius: 50%;
|
97 |
+
margin: 0 2px;
|
98 |
+
animation: typing 1s infinite;
|
99 |
+
}
|
100 |
+
|
101 |
+
.typing-animation span:nth-child(2) {
|
102 |
+
animation-delay: 0.2s;
|
103 |
+
}
|
104 |
+
|
105 |
+
.typing-animation span:nth-child(3) {
|
106 |
+
animation-delay: 0.4s;
|
107 |
+
}
|
108 |
+
|
109 |
+
@keyframes typing {
|
110 |
+
0%, 100% {
|
111 |
+
opacity: 0.3;
|
112 |
+
}
|
113 |
+
50% {
|
114 |
+
opacity: 1;
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
/* Chat Input */
|
119 |
+
.chat-input {
|
120 |
+
display: flex;
|
121 |
+
padding: 16px;
|
122 |
+
background-color: #000; /* Black input area */
|
123 |
+
border-top: 1px solid #333;
|
124 |
+
}
|
125 |
+
|
126 |
+
.chat-input input {
|
127 |
+
flex: 1;
|
128 |
+
padding: 12px;
|
129 |
+
background-color: #111; /* Dark input field */
|
130 |
+
border: 1px solid #333;
|
131 |
+
border-radius: 8px;
|
132 |
+
outline: none;
|
133 |
+
color: #fff;
|
134 |
+
font-family: 'JetBrains Mono', monospace;
|
135 |
+
font-size: 14px;
|
136 |
+
}
|
137 |
+
|
138 |
+
.chat-input input::placeholder {
|
139 |
+
color: #666;
|
140 |
+
}
|
141 |
+
|
142 |
+
.chat-input button {
|
143 |
+
margin-left: 12px;
|
144 |
+
padding: 12px 16px;
|
145 |
+
background-color: #007bff; /* Vercel-like blue */
|
146 |
+
color: #fff;
|
147 |
+
border: none;
|
148 |
+
border-radius: 8px;
|
149 |
+
font-family: 'JetBrains Mono', monospace;
|
150 |
+
font-size: 14px;
|
151 |
+
font-weight: 500;
|
152 |
+
cursor: pointer;
|
153 |
+
transition: background-color 0.2s;
|
154 |
+
}
|
155 |
+
|
156 |
+
.chat-input button:hover {
|
157 |
+
background-color: #005bb5; /* Darker blue on hover */
|
158 |
+
}
|
159 |
+
</style>
|
160 |
+
</head>
|
161 |
+
<body>
|
162 |
+
<div class="chat-container">
|
163 |
+
<div class="chat-header">
|
164 |
+
gpt-4.5-preview
|
165 |
+
</div>
|
166 |
+
<div class="chat-box" id="chat-box">
|
167 |
+
<!-- Chat messages will appear here -->
|
168 |
+
</div>
|
169 |
+
<div class="chat-input">
|
170 |
+
<input type="text" id="user-input" placeholder="Type your message...">
|
171 |
+
<button onclick="sendMessage()">Send</button>
|
172 |
+
</div>
|
173 |
+
</div>
|
174 |
+
|
175 |
+
<script>
|
176 |
+
const apiKey = 'dad7e44eea25413d881f7866f68d09ef';
|
177 |
+
const baseURL = 'https://api.aimlapi.com/v1';
|
178 |
+
|
179 |
+
async function sendMessage() {
|
180 |
+
const userInput = document.getElementById('user-input').value;
|
181 |
+
if (!userInput) return;
|
182 |
+
|
183 |
+
// Display user message
|
184 |
+
const chatBox = document.getElementById('chat-box');
|
185 |
+
const userMessage = document.createElement('div');
|
186 |
+
userMessage.classList.add('message', 'user-message');
|
187 |
+
userMessage.textContent = userInput;
|
188 |
+
chatBox.appendChild(userMessage);
|
189 |
+
|
190 |
+
// Clear input
|
191 |
+
document.getElementById('user-input').value = '';
|
192 |
+
|
193 |
+
// Show typing animation
|
194 |
+
const typingAnimation = document.createElement('div');
|
195 |
+
typingAnimation.classList.add('message', 'bot-message', 'typing-animation');
|
196 |
+
typingAnimation.innerHTML = `
|
197 |
+
<span></span>
|
198 |
+
<span></span>
|
199 |
+
<span></span>
|
200 |
+
`;
|
201 |
+
chatBox.appendChild(typingAnimation);
|
202 |
+
|
203 |
+
// Scroll to bottom
|
204 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
205 |
+
|
206 |
+
// Send message to API
|
207 |
+
const response = await fetch(`${baseURL}/chat/completions`, {
|
208 |
+
method: 'POST',
|
209 |
+
headers: {
|
210 |
+
'Content-Type': 'application/json',
|
211 |
+
'Authorization': `Bearer ${apiKey}`
|
212 |
+
},
|
213 |
+
body: JSON.stringify({
|
214 |
+
model: 'gpt-4.5-preview',
|
215 |
+
messages: [
|
216 |
+
{
|
217 |
+
role: 'system',
|
218 |
+
content: 'You are an AI assistant who knows everything.'
|
219 |
+
},
|
220 |
+
{
|
221 |
+
role: 'user',
|
222 |
+
content: userInput
|
223 |
+
}
|
224 |
+
]
|
225 |
+
})
|
226 |
+
});
|
227 |
+
|
228 |
+
const data = await response.json();
|
229 |
+
const botMessage = data.choices[0].message.content;
|
230 |
+
|
231 |
+
// Remove typing animation
|
232 |
+
chatBox.removeChild(typingAnimation);
|
233 |
+
|
234 |
+
// Display bot message with typewriter animation
|
235 |
+
const botMessageElement = document.createElement('div');
|
236 |
+
botMessageElement.classList.add('message', 'bot-message');
|
237 |
+
chatBox.appendChild(botMessageElement);
|
238 |
+
|
239 |
+
// Function to simulate typewriter effect (faster)
|
240 |
+
function typeWriter(text, element, delay = 20) { // Reduced delay to 20ms
|
241 |
+
let i = 0;
|
242 |
+
function type() {
|
243 |
+
if (i < text.length) {
|
244 |
+
element.textContent += text.charAt(i);
|
245 |
+
i++;
|
246 |
+
setTimeout(type, delay);
|
247 |
+
}
|
248 |
+
}
|
249 |
+
type();
|
250 |
+
}
|
251 |
+
|
252 |
+
// Check if the message contains code
|
253 |
+
if (botMessage.includes('```')) {
|
254 |
+
const [textBeforeCode, codeSnippet] = botMessage.split('```');
|
255 |
+
const codeElement = document.createElement('code');
|
256 |
+
codeElement.style.display = 'block'; // Ensure code block is displayed properly
|
257 |
+
|
258 |
+
// Display text before code
|
259 |
+
typeWriter(textBeforeCode, botMessageElement);
|
260 |
+
|
261 |
+
// Display code snippet after a short delay
|
262 |
+
setTimeout(() => {
|
263 |
+
codeElement.textContent = codeSnippet;
|
264 |
+
botMessageElement.appendChild(codeElement);
|
265 |
+
}, textBeforeCode.length * 20 + 500); // Adjusted delay based on faster typing
|
266 |
+
} else {
|
267 |
+
// Display plain text with typewriter effect
|
268 |
+
typeWriter(botMessage, botMessageElement);
|
269 |
+
}
|
270 |
+
|
271 |
+
// Scroll to bottom
|
272 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
273 |
+
}
|
274 |
+
</script>
|
275 |
+
</body>
|
276 |
+
</html>
|