Spaces:
Running
Running
Abhi yah work nahin kar raha check karo acche se
Browse files
script.js
CHANGED
|
@@ -116,7 +116,6 @@ async function sendMessage() {
|
|
| 116 |
// Simulate AI response
|
| 117 |
await simulateAIResponse(message);
|
| 118 |
}
|
| 119 |
-
|
| 120 |
// Add message to chat
|
| 121 |
function addMessage(content, sender) {
|
| 122 |
const messageDiv = document.createElement('div');
|
|
@@ -126,4 +125,91 @@ function addMessage(content, sender) {
|
|
| 126 |
messageContent.className = sender === 'user' ? 'user-message' : 'ai-message';
|
| 127 |
|
| 128 |
// Check if content is code
|
| 129 |
-
if (content.includes('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
// Simulate AI response
|
| 117 |
await simulateAIResponse(message);
|
| 118 |
}
|
|
|
|
| 119 |
// Add message to chat
|
| 120 |
function addMessage(content, sender) {
|
| 121 |
const messageDiv = document.createElement('div');
|
|
|
|
| 125 |
messageContent.className = sender === 'user' ? 'user-message' : 'ai-message';
|
| 126 |
|
| 127 |
// Check if content is code
|
| 128 |
+
if (content.includes('```')) {
|
| 129 |
+
const parts = content.split('```');
|
| 130 |
+
parts.forEach((part, index) => {
|
| 131 |
+
if (index % 2 === 1) {
|
| 132 |
+
// Code block
|
| 133 |
+
const pre = document.createElement('pre');
|
| 134 |
+
pre.className = 'code-block';
|
| 135 |
+
const code = document.createElement('code');
|
| 136 |
+
code.textContent = part.trim();
|
| 137 |
+
pre.appendChild(code);
|
| 138 |
+
messageContent.appendChild(pre);
|
| 139 |
+
} else if (part.trim()) {
|
| 140 |
+
// Regular text
|
| 141 |
+
const p = document.createElement('p');
|
| 142 |
+
p.textContent = part;
|
| 143 |
+
messageContent.appendChild(p);
|
| 144 |
+
}
|
| 145 |
+
});
|
| 146 |
+
} else {
|
| 147 |
+
const p = document.createElement('p');
|
| 148 |
+
p.textContent = content;
|
| 149 |
+
messageContent.appendChild(p);
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
messageDiv.appendChild(messageContent);
|
| 153 |
+
chatContainer.appendChild(messageDiv);
|
| 154 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 155 |
+
|
| 156 |
+
// Store in current chat
|
| 157 |
+
currentChat.push({ content, sender, timestamp: new Date() });
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// Show typing indicator
|
| 161 |
+
function showTypingIndicator() {
|
| 162 |
+
isTyping = true;
|
| 163 |
+
const typingDiv = document.createElement('div');
|
| 164 |
+
typingDiv.className = 'flex justify-start message-enter';
|
| 165 |
+
typingDiv.id = 'typingIndicator';
|
| 166 |
+
|
| 167 |
+
const typingContent = document.createElement('div');
|
| 168 |
+
typingContent.className = 'typing-indicator';
|
| 169 |
+
typingContent.innerHTML = '<span></span><span></span><span></span>';
|
| 170 |
+
|
| 171 |
+
typingDiv.appendChild(typingContent);
|
| 172 |
+
chatContainer.appendChild(typingDiv);
|
| 173 |
+
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
// Simulate AI response
|
| 177 |
+
async function simulateAIResponse(userMessage) {
|
| 178 |
+
// Simulate network delay
|
| 179 |
+
await new Promise(resolve => setTimeout(resolve, 1500 + Math.random() * 1000));
|
| 180 |
+
|
| 181 |
+
// Remove typing indicator
|
| 182 |
+
const typingIndicator = document.getElementById('typingIndicator');
|
| 183 |
+
if (typingIndicator) {
|
| 184 |
+
typingIndicator.remove();
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
// Simulate different types of responses
|
| 188 |
+
const responses = [
|
| 189 |
+
"Based on quantum computing principles, I can help you explore complex computational problems. What specific aspect interests you?",
|
| 190 |
+
"That's a fascinating question! Let me analyze it from multiple perspectives and provide you with a comprehensive answer.",
|
| 191 |
+
"I understand you're curious about advanced AI capabilities. Here's what I can tell you about machine learning and neural networks...",
|
| 192 |
+
"Interesting! Let me break this down into simple terms while maintaining scientific accuracy.",
|
| 193 |
+
"As an AI assistant, I can help you with coding, problem-solving, creative writing, and much more. What would you like to explore next?",
|
| 194 |
+
"Quantum mechanics suggests that particles can exist in multiple states simultaneously. This principle applies to quantum computing as well.",
|
| 195 |
+
"Here's a code example to help you understand this concept better:\n```javascript\nfunction quantumCompute() {\n return Math.random() > 0.5 ? 'heads' : 'tails';\n}\n```",
|
| 196 |
+
"The future of AI is incredibly exciting! We're moving towards more human-like reasoning and problem-solving capabilities."
|
| 197 |
+
];
|
| 198 |
+
|
| 199 |
+
const randomResponse = responses[Math.floor(Math.random() * responses.length)];
|
| 200 |
+
addMessage(randomResponse, 'ai');
|
| 201 |
+
isTyping = false;
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
// Toggle theme
|
| 205 |
+
function toggleTheme() {
|
| 206 |
+
isDarkMode = !isDarkMode;
|
| 207 |
+
document.body.classList.toggle('bg-gray-900');
|
| 208 |
+
document.body.classList.toggle('text-white');
|
| 209 |
+
document.body.classList.toggle('bg-white');
|
| 210 |
+
document.body.classList.toggle('text-gray-900');
|
| 211 |
+
|
| 212 |
+
const icon = themeToggle.querySelector('i');
|
| 213 |
+
icon.setAttribute('data-feather', isDarkMode ? 'sun' : 'moon');
|
| 214 |
+
feather.replace();
|
| 215 |
+
}
|