File size: 8,555 Bytes
02e9fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0c6493e
02e9fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6b1d9eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02e9fed
6b1d9eb
 
 
02e9fed
6b1d9eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02e9fed
 
6b1d9eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22bba31
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chatbot Interface</title>
    <!-- Load JetBrains Mono font from Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        /* Global Styles */
        body {
            font-family: 'JetBrains Mono', monospace;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            background-color: #000; /* Vercel-like dark background */
            color: #fff;
        }

        /* Chat Container */
        .chat-container {
            width: 500px;
            background-color: #111; /* Dark container background */
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }

        /* Chat Header */
        .chat-header {
            background-color: #000; /* Vercel-like black header */
            padding: 16px;
            text-align: center;
            font-size: 18px;
            font-weight: 700;
            border-bottom: 1px solid #333;
        }

        /* Chat Box */
        .chat-box {
            flex: 1;
            padding: 16px;
            overflow-y: auto;
            background-color: #111;
        }

        /* Messages */
        .message {
            margin-bottom: 12px;
            padding: 12px;
            border-radius: 8px;
            max-width: 80%;
            font-size: 14px;
            line-height: 1.5;
        }

        .user-message {
            background-color: #007bff; /* Vercel-like blue */
            color: #fff;
            margin-left: auto;
        }

        .bot-message {
            background-color: #222; /* Dark gray for bot messages */
            color: #fff;
            margin-right: auto;
        }

        .bot-message code {
            display: block;
            background-color: #000; /* Black background for code */
            color: #00ff88; /* Vercel-like green for code */
            padding: 12px;
            border-radius: 6px;
            margin-top: 10px;
            font-family: 'JetBrains Mono', monospace;
            white-space: pre-wrap;
            font-size: 13px;
        }

        /* Typing Animation */
        .typing-animation {
            display: inline-block;
        }

        .typing-animation span {
            display: inline-block;
            width: 8px;
            height: 8px;
            background-color: #fff;
            border-radius: 50%;
            margin: 0 2px;
            animation: typing 1s infinite;
        }

        .typing-animation span:nth-child(2) {
            animation-delay: 0.2s;
        }

        .typing-animation span:nth-child(3) {
            animation-delay: 0.4s;
        }

        @keyframes typing {
            0%, 100% {
                opacity: 0.3;
            }
            50% {
                opacity: 1;
            }
        }

        /* Chat Input */
        .chat-input {
            display: flex;
            padding: 16px;
            background-color: #000; /* Black input area */
            border-top: 1px solid #333;
        }

        .chat-input input {
            flex: 1;
            padding: 12px;
            background-color: #111; /* Dark input field */
            border: 1px solid #333;
            border-radius: 8px;
            outline: none;
            color: #fff;
            font-family: 'JetBrains Mono', monospace;
            font-size: 14px;
        }

        .chat-input input::placeholder {
            color: #666;
        }

        .chat-input button {
            margin-left: 12px;
            padding: 12px 16px;
            background-color: #007bff; /* Vercel-like blue */
            color: #fff;
            border: none;
            border-radius: 8px;
            font-family: 'JetBrains Mono', monospace;
            font-size: 14px;
            font-weight: 500;
            cursor: pointer;
            transition: background-color 0.2s;
        }

        .chat-input button:hover {
            background-color: #005bb5; /* Darker blue on hover */
        }
    </style>
</head>
<body>
    <div class="chat-container">
        <div class="chat-header">
            gpt-4.5-preview(unfinished code generation)
        </div>
        <div class="chat-box" id="chat-box">
            <!-- Chat messages will appear here -->
        </div>
        <div class="chat-input">
            <input type="text" id="user-input" placeholder="Type your message...">
            <button onclick="sendMessage()">Send</button>
        </div>
    </div>

    <script>
        const apiKey = 'dad7e44eea25413d881f7866f68d09ef';
        const baseURL = 'https://api.aimlapi.com/v1';

        async function sendMessage() {
    const userInput = document.getElementById('user-input').value;
    if (!userInput) return;

    // Display user message
    const chatBox = document.getElementById('chat-box');
    const userMessage = document.createElement('div');
    userMessage.classList.add('message', 'user-message');
    userMessage.textContent = userInput;
    chatBox.appendChild(userMessage);

    // Clear input
    document.getElementById('user-input').value = '';

    // Show typing animation
    const typingAnimation = document.createElement('div');
    typingAnimation.classList.add('message', 'bot-message', 'typing-animation');
    typingAnimation.innerHTML = `
        <span></span>
        <span></span>
        <span></span>
    `;
    chatBox.appendChild(typingAnimation);

    // Scroll to bottom
    chatBox.scrollTop = chatBox.scrollHeight;

    // Send message to API
    const response = await fetch(`${baseURL}/chat/completions`, {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${apiKey}`
        },
        body: JSON.stringify({
            model: 'gpt-4.5-preview',
            messages: [
                {
                    role: 'system',
                    content: 'You are an AI assistant who knows everything.'
                },
                {
                    role: 'user',
                    content: userInput
                }
            ]
        })
    });

    const data = await response.json();
    const botMessage = data.choices[0].message.content;

    // Remove typing animation
    chatBox.removeChild(typingAnimation);

    // Display bot message with typewriter animation
    const botMessageElement = document.createElement('div');
    botMessageElement.classList.add('message', 'bot-message');
    chatBox.appendChild(botMessageElement);

    // Function to simulate typewriter effect
    function typeWriter(text, element, delay = 20) { // Reduced delay to 20ms
        let i = 0;
        function type() {
            if (i < text.length) {
                element.textContent += text.charAt(i);
                i++;
                setTimeout(type, delay);
            }
        }
        type();
    }

    // Parse and display the bot message
    let remainingText = botMessage;
    while (remainingText.includes('```')) {
        // Extract text before the code block
        const [textBeforeCode, rest] = remainingText.split('```', 2);
        typeWriter(textBeforeCode, botMessageElement);

        // Extract the code block
        const [codeSnippet, restAfterCode] = rest.split('```', 2);
        const codeElement = document.createElement('code');
        codeElement.classList.add('code-block'); // Optional: Add a class for styling
        codeElement.style.display = 'block';

        // Simulate typewriter effect for the code block
        setTimeout(() => {
            typeWriter(codeSnippet, codeElement);
            botMessageElement.appendChild(codeElement);
        }, textBeforeCode.length * 20 + 50); // Adjusted delay

        // Update remaining text
        remainingText = restAfterCode || '';
    }

    // Append any remaining text after the last code block
    if (remainingText) {
        setTimeout(() => {
            typeWriter(remainingText, botMessageElement);
        }, botMessageElement.textContent.length * 20 + 50); // Adjusted delay
    }

    // Scroll to bottom
    chatBox.scrollTop = chatBox.scrollHeight;
      }
      </script>
</body>
</html>