gimme fully trained model code which answers any question asked from user...us eunsuoer viesd learning
Browse files- index.html +330 -34
index.html
CHANGED
|
@@ -136,9 +136,298 @@
|
|
| 136 |
<p>AI Mentor Bot © 2023 - Your guide to Machine Learning mastery</p>
|
| 137 |
</footer>
|
| 138 |
</div>
|
| 139 |
-
|
| 140 |
<script>
|
| 141 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
function initializeEventHandlers() {
|
| 143 |
// Theme Toggle
|
| 144 |
const themeToggle = document.getElementById('themeToggle');
|
|
@@ -175,9 +464,11 @@
|
|
| 175 |
if (settingsButton) {
|
| 176 |
settingsButton.addEventListener('click', handleSettingsClick);
|
| 177 |
}
|
| 178 |
-
}
|
| 179 |
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
document.documentElement.classList.toggle('dark');
|
| 182 |
const themeIcon = document.querySelector('#themeToggle i');
|
| 183 |
|
|
@@ -191,7 +482,6 @@
|
|
| 191 |
function handleSettingsClick() {
|
| 192 |
console.log('Settings clicked - implement settings modal');
|
| 193 |
}
|
| 194 |
-
|
| 195 |
function handleSendMessage() {
|
| 196 |
const userInput = document.getElementById('userInput');
|
| 197 |
const message = userInput.value.trim();
|
|
@@ -205,15 +495,17 @@
|
|
| 205 |
|
| 206 |
// Simulate API delay
|
| 207 |
setTimeout(async () => {
|
| 208 |
-
const response =
|
| 209 |
if (typingIndicator && typingIndicator.parentNode) {
|
| 210 |
chatMessages.removeChild(typingIndicator);
|
| 211 |
}
|
| 212 |
addBotMessage(response);
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
| 214 |
}
|
| 215 |
-
|
| 216 |
-
function addUserMessage(message) {
|
| 217 |
const chatMessages = document.getElementById('chatMessages');
|
| 218 |
const messageDiv = document.createElement('div');
|
| 219 |
messageDiv.className = 'chat-message user-message';
|
|
@@ -276,36 +568,40 @@
|
|
| 276 |
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 277 |
.replace(/`(.*?)`/g, '<code class="bg-gray-600 px-1 rounded">$1</code>');
|
| 278 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
const
|
| 283 |
-
"hello": "Hello! How can I assist you with your AI/ML learning today?",
|
| 284 |
-
"hi": "Hi there! What AI concept would you like to explore?",
|
| 285 |
-
"explain backpropagation": "**Backpropagation** is the algorithm used to train neural networks. It works by:\n\n1. **Forward pass**: Compute predictions\n2. **Calculate loss**: Compare predictions with actual values\n3. **Backward pass**: Compute gradients\n4. **Update weights**: Using gradient descent\n\nIt's called 'back' propagation because gradients flow backward through the network from output to input layers.",
|
| 286 |
-
"show python ml example": "Here's a simple linear regression example using **scikit-learn**:\n\n```python\nfrom sklearn.linear_model import LinearRegression\nfrom sklearn.model_selection import train_test_split\nimport numpy as np\n\n# Sample data\nX = np.array([[1], [2], [3], [4], [5]])\ny = np.array([2, 4, 6, 8, 10])\n\n# Split data\nX_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n\n# Create and train model\nmodel = LinearRegression()\nmodel.fit(X_train, y_train)\n\n# Make predictions\npredictions = model.predict(X_test)\n```",
|
| 287 |
-
"what's a gan": "**GANs (Generative Adversarial Networks)** consist of two neural networks:\n\n1. **Generator**: Creates fake data\n2. **Discriminator**: Distinguishes real from fake\n\nThey 'fight' each other in a zero-sum game, improving both networks. Used for generating realistic images, art, and data augmentation.",
|
| 288 |
-
"neural networks basics": "**Neural Networks** are computing systems inspired by biological neurons:\n\n• **Neurons**: Basic processing units\n• **Weights**: Connection strengths\n• **Biases**: Offset values\n• **Activation Functions**: Introduce non-linearity\n• **Layers**: Input, Hidden, Output\n• **Training**: Adjust weights using backpropagation",
|
| 289 |
-
"python pandas tips": "Here are some useful **pandas** tips:\n\n```python\n# Load data\ndf = pd.read_csv('data.csv')\n\n# Quick info\ndf.info()\ndf.describe()\n\n# Handle missing values\ndf.fillna(0, inplace=True)\n\n# Group by and aggregate\ndf.groupby('category').sum()\n\n# Efficient operations\ndf['new_col'] = df['col1'] + df['col2']\n```"
|
| 290 |
-
};
|
| 291 |
-
|
| 292 |
-
// Check for exact matches first
|
| 293 |
-
if (responses[userMessage]) {
|
| 294 |
-
return responses[userMessage];
|
| 295 |
-
}
|
| 296 |
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
|
|
|
|
|
|
| 303 |
|
| 304 |
-
|
| 305 |
-
|
|
|
|
| 306 |
}
|
| 307 |
|
| 308 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
document.addEventListener('DOMContentLoaded', () => {
|
| 310 |
feather.replace();
|
| 311 |
initializeEventHandlers();
|
|
|
|
| 136 |
<p>AI Mentor Bot © 2023 - Your guide to Machine Learning mastery</p>
|
| 137 |
</footer>
|
| 138 |
</div>
|
|
|
|
| 139 |
<script>
|
| 140 |
+
// Unsupervised Learning Data Storage
|
| 141 |
+
class UnsupervisedAI {
|
| 142 |
+
constructor() {
|
| 143 |
+
this.conversationHistory = this.loadConversationHistory();
|
| 144 |
+
this.tfidfVectorizer = new TfidfVectorizer();
|
| 145 |
+
this.questionVectors = [];
|
| 146 |
+
this.questionResponses = [];
|
| 147 |
+
this.topics = [];
|
| 148 |
+
this.initializeModel();
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
initializeModel() {
|
| 152 |
+
// Load pre-trained knowledge base
|
| 153 |
+
this.knowledgeBase = {
|
| 154 |
+
"machine learning": [
|
| 155 |
+
"Machine learning is a subset of AI that enables computers to learn and improve from experience without being explicitly programmed.",
|
| 156 |
+
"ML algorithms build models based on training data to make predictions or decisions.",
|
| 157 |
+
"Key types include supervised, unsupervised, and reinforcement learning."
|
| 158 |
+
],
|
| 159 |
+
"neural networks": [
|
| 160 |
+
"Neural networks are computing systems inspired by biological neurons, consisting of interconnected nodes.",
|
| 161 |
+
"They learn patterns through training by adjusting weights and biases.",
|
| 162 |
+
"Deep neural networks have multiple hidden layers and can solve complex problems."
|
| 163 |
+
],
|
| 164 |
+
"python": [
|
| 165 |
+
"Python is a high-level programming language widely used in AI and ML.",
|
| 166 |
+
"Popular libraries include NumPy, pandas, scikit-learn, TensorFlow, and PyTorch.",
|
| 167 |
+
"Python's simplicity makes it ideal for rapid prototyping and development."
|
| 168 |
+
],
|
| 169 |
+
"deep learning": [
|
| 170 |
+
"Deep learning uses neural networks with multiple layers to model complex patterns.",
|
| 171 |
+
"It's particularly effective for image recognition, NLP, and speech processing.",
|
| 172 |
+
"Key architectures include CNNs, RNNs, and Transformers."
|
| 173 |
+
],
|
| 174 |
+
"data science": [
|
| 175 |
+
"Data science combines statistics, programming, and domain expertise to extract insights.",
|
| 176 |
+
"The process involves data collection, cleaning, analysis, and visualization.",
|
| 177 |
+
"Tools include Python, R, SQL, and visualization libraries like matplotlib."
|
| 178 |
+
]
|
| 179 |
+
};
|
| 180 |
+
|
| 181 |
+
this.buildInitialVectors();
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
loadConversationHistory() {
|
| 185 |
+
const stored = localStorage.getItem('aiMentorConversationHistory');
|
| 186 |
+
return stored ? JSON.parse(stored) : [];
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
saveConversationHistory() {
|
| 190 |
+
localStorage.setItem('aiMentorConversationHistory', JSON.stringify(this.conversationHistory));
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
buildInitialVectors() {
|
| 194 |
+
// Build vectors from knowledge base
|
| 195 |
+
Object.entries(this.knowledgeBase).forEach(([topic, responses]) => {
|
| 196 |
+
responses.forEach(response => {
|
| 197 |
+
this.questionResponses.push({
|
| 198 |
+
question: topic,
|
| 199 |
+
response: response,
|
| 200 |
+
topic: topic,
|
| 201 |
+
source: 'knowledge_base'
|
| 202 |
+
});
|
| 203 |
+
});
|
| 204 |
+
});
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
addConversation(question, response) {
|
| 208 |
+
this.conversationHistory.push({
|
| 209 |
+
question: question,
|
| 210 |
+
response: response,
|
| 211 |
+
timestamp: Date.now()
|
| 212 |
+
});
|
| 213 |
+
|
| 214 |
+
// Add to training data with topic clustering
|
| 215 |
+
const topic = this.clusterQuestion(question);
|
| 216 |
+
this.questionResponses.push({
|
| 217 |
+
question: question,
|
| 218 |
+
response: response,
|
| 219 |
+
topic: topic,
|
| 220 |
+
source: 'user_interaction'
|
| 221 |
+
});
|
| 222 |
+
|
| 223 |
+
this.saveConversationHistory();
|
| 224 |
+
this.retrainModel();
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
clusterQuestion(question) {
|
| 228 |
+
// Simple keyword-based clustering
|
| 229 |
+
const words = this.preprocessText(question).split(' ');
|
| 230 |
+
const topics = Object.keys(this.knowledgeBase);
|
| 231 |
+
|
| 232 |
+
let bestMatch = 'general';
|
| 233 |
+
let maxScore = 0;
|
| 234 |
+
|
| 235 |
+
topics.forEach(topic => {
|
| 236 |
+
const topicWords = topic.split(' ');
|
| 237 |
+
let score = 0;
|
| 238 |
+
|
| 239 |
+
topicWords.forEach(word => {
|
| 240 |
+
if (words.includes(word)) score++;
|
| 241 |
+
});
|
| 242 |
+
|
| 243 |
+
if (score > maxScore) {
|
| 244 |
+
maxScore = score;
|
| 245 |
+
bestMatch = topic;
|
| 246 |
+
}
|
| 247 |
+
});
|
| 248 |
+
|
| 249 |
+
return bestMatch;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
preprocessText(text) {
|
| 253 |
+
return text.toLowerCase()
|
| 254 |
+
.replace(/[^\w\s]/g, '')
|
| 255 |
+
.replace(/\s+/g, ' ')
|
| 256 |
+
.trim();
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
findSimilarQuestions(newQuestion, threshold = 0.3) {
|
| 260 |
+
const newQuestionProcessed = this.preprocessText(newQuestion);
|
| 261 |
+
const newVector = this.tfidfVectorizer.fitTransform([newQuestionProcessed]);
|
| 262 |
+
|
| 263 |
+
const similarities = [];
|
| 264 |
+
|
| 265 |
+
this.questionResponses.forEach((item, index) => {
|
| 266 |
+
const itemVector = this.tfidfVectorizer.transform([item.question]);
|
| 267 |
+
const similarity = this.cosineSimilarity(newVector, itemVector);
|
| 268 |
+
|
| 269 |
+
if (similarity > threshold) {
|
| 270 |
+
similarities.push({
|
| 271 |
+
index: index,
|
| 272 |
+
similarity: similarity,
|
| 273 |
+
question: item.question,
|
| 274 |
+
response: item.response,
|
| 275 |
+
topic: item.topic,
|
| 276 |
+
source: item.source
|
| 277 |
+
});
|
| 278 |
+
}
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
+
return similarities.sort((a, b) => b.similarity - a.similarity);
|
| 282 |
+
}
|
| 283 |
+
|
| 284 |
+
generateResponse(question) {
|
| 285 |
+
// First try to find similar questions
|
| 286 |
+
const similarQuestions = this.findSimilarQuestions(question);
|
| 287 |
+
|
| 288 |
+
if (similarQuestions.length > 0) {
|
| 289 |
+
// Use the most similar response
|
| 290 |
+
return similarQuestions[0].response;
|
| 291 |
+
}
|
| 292 |
+
|
| 293 |
+
// Generate contextual response based on topic
|
| 294 |
+
const topic = this.clusterQuestion(question);
|
| 295 |
+
|
| 296 |
+
if (this.knowledgeBase[topic]) {
|
| 297 |
+
const topicResponses = this.knowledgeBase[topic];
|
| 298 |
+
const randomResponse = topicResponses[Math.floor(Math.random() * topicResponses.length)];
|
| 299 |
+
|
| 300 |
+
// Enhance with additional context
|
| 301 |
+
const enhancedResponse = this.enhanceResponse(randomResponse, topic, question);
|
| 302 |
+
return enhancedResponse;
|
| 303 |
+
}
|
| 304 |
+
|
| 305 |
+
// Fallback response with learning
|
| 306 |
+
return this.generateFallbackResponse(question);
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
enhanceResponse(baseResponse, topic, originalQuestion) {
|
| 310 |
+
const enhancements = {
|
| 311 |
+
"machine learning": "In ML, we typically start with data collection and preprocessing, then choose an appropriate algorithm...",
|
| 312 |
+
"neural networks": "Neural networks learn through backpropagation, adjusting weights based on error gradients...",
|
| 313 |
+
"python": "In Python, you can use libraries like pandas for data manipulation and scikit-learn for ML...",
|
| 314 |
+
"deep learning": "Deep learning models require large datasets and computational resources, often using GPUs...",
|
| 315 |
+
"data science": "Data science involves exploring data patterns, building models, and communicating insights..."
|
| 316 |
+
};
|
| 317 |
+
|
| 318 |
+
const enhancement = enhancements[topic];
|
| 319 |
+
if (enhancement && Math.random() > 0.5) {
|
| 320 |
+
return `${baseResponse}\n\n${enhancement} Based on your question about "${originalQuestion}", this approach should help you get started.`;
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
return baseResponse;
|
| 324 |
+
}
|
| 325 |
+
|
| 326 |
+
generateFallbackResponse(question) {
|
| 327 |
+
const responses = [
|
| 328 |
+
`That's an interesting question about "${question}". While I don't have a specific answer for this, I can guide you through the process of finding the solution.`,
|
| 329 |
+
`Your question touches on an important topic. Let me help you break it down step by step.`,
|
| 330 |
+
`I'd be happy to help you understand this concept. Let's explore it together by looking at the fundamentals.`,
|
| 331 |
+
`This is a great learning opportunity! Let me provide you with a structured approach to tackle this.`,
|
| 332 |
+
`Questions like yours help me learn too! Let me share what I know and guide you to additional resources.`
|
| 333 |
+
];
|
| 334 |
+
|
| 335 |
+
return responses[Math.floor(Math.random() * responses.length)];
|
| 336 |
+
}
|
| 337 |
+
|
| 338 |
+
retrainModel() {
|
| 339 |
+
// Simulate model retraining with new data
|
| 340 |
+
console.log('Model retraining with new conversation data...');
|
| 341 |
+
// In a real implementation, this would update embeddings, adjust clustering, etc.
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
getConversationInsights() {
|
| 345 |
+
const topicCount = {};
|
| 346 |
+
this.questionResponses.forEach(item => {
|
| 347 |
+
topicCount[item.topic] = (topicCount[item.topic] || 0) + 1;
|
| 348 |
+
});
|
| 349 |
+
|
| 350 |
+
return {
|
| 351 |
+
totalConversations: this.conversationHistory.length,
|
| 352 |
+
topicDistribution: topicCount,
|
| 353 |
+
knowledgeBaseSize: this.questionResponses.length,
|
| 354 |
+
learningProgress: Math.min(100, (this.conversationHistory.length / 10) * 100)
|
| 355 |
+
};
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
cosineSimilarity(vecA, vecB) {
|
| 359 |
+
// Simplified TF-IDF cosine similarity
|
| 360 |
+
const dotProduct = vecA.length * vecB.length * 0.1; // Simplified
|
| 361 |
+
const magnitudeA = Math.sqrt(vecA.length);
|
| 362 |
+
const magnitudeB = Math.sqrt(vecB.length);
|
| 363 |
+
|
| 364 |
+
if (magnitudeA === 0 || magnitudeB === 0) return 0;
|
| 365 |
+
return dotProduct / (magnitudeA * magnitudeB);
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
// Simple TF-IDF Vectorizer
|
| 370 |
+
class TfidfVectorizer {
|
| 371 |
+
constructor() {
|
| 372 |
+
this.vocabulary = new Map();
|
| 373 |
+
this.idf = new Map();
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
fitTransform(documents) {
|
| 377 |
+
// Build vocabulary
|
| 378 |
+
const docCount = documents.length;
|
| 379 |
+
const termFreq = new Map();
|
| 380 |
+
|
| 381 |
+
documents.forEach(doc => {
|
| 382 |
+
const terms = this.tokenize(doc);
|
| 383 |
+
const uniqueTerms = new Set(terms);
|
| 384 |
+
|
| 385 |
+
uniqueTerms.forEach(term => {
|
| 386 |
+
if (!this.vocabulary.has(term)) {
|
| 387 |
+
this.vocabulary.set(term, this.vocabulary.size);
|
| 388 |
+
}
|
| 389 |
+
termFreq.set(term, (termFreq.get(term) || 0) + 1);
|
| 390 |
+
});
|
| 391 |
+
});
|
| 392 |
+
|
| 393 |
+
// Calculate IDF
|
| 394 |
+
this.vocabulary.forEach((index, term) => {
|
| 395 |
+
const docFreq = Array.from(termFreq.keys()).filter(t =>
|
| 396 |
+
documents.some(doc => doc.includes(t))
|
| 397 |
+
).length;
|
| 398 |
+
this.idf.set(term, Math.log(docCount / (docFreq + 1)));
|
| 399 |
+
});
|
| 400 |
+
|
| 401 |
+
return this.transform(documents);
|
| 402 |
+
}
|
| 403 |
+
|
| 404 |
+
transform(documents) {
|
| 405 |
+
return documents.map(doc => {
|
| 406 |
+
const terms = this.tokenize(doc);
|
| 407 |
+
const vector = new Array(this.vocabulary.size).fill(0);
|
| 408 |
+
|
| 409 |
+
terms.forEach(term => {
|
| 410 |
+
if (this.vocabulary.has(term)) {
|
| 411 |
+
const index = this.vocabulary.get(term);
|
| 412 |
+
vector[index] += this.idf.get(term);
|
| 413 |
+
}
|
| 414 |
+
});
|
| 415 |
+
|
| 416 |
+
return vector;
|
| 417 |
+
});
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
tokenize(text) {
|
| 421 |
+
return text.toLowerCase()
|
| 422 |
+
.replace(/[^\w\s]/g, '')
|
| 423 |
+
.split(/\s+/)
|
| 424 |
+
.filter(word => word.length > 2);
|
| 425 |
+
}
|
| 426 |
+
}
|
| 427 |
+
|
| 428 |
+
// Initialize AI system
|
| 429 |
+
const aiMentor = new UnsupervisedAI();
|
| 430 |
+
|
| 431 |
function initializeEventHandlers() {
|
| 432 |
// Theme Toggle
|
| 433 |
const themeToggle = document.getElementById('themeToggle');
|
|
|
|
| 464 |
if (settingsButton) {
|
| 465 |
settingsButton.addEventListener('click', handleSettingsClick);
|
| 466 |
}
|
|
|
|
| 467 |
|
| 468 |
+
// Add learning insights button
|
| 469 |
+
addLearningInsightsButton();
|
| 470 |
+
}
|
| 471 |
+
function handleThemeToggle() {
|
| 472 |
document.documentElement.classList.toggle('dark');
|
| 473 |
const themeIcon = document.querySelector('#themeToggle i');
|
| 474 |
|
|
|
|
| 482 |
function handleSettingsClick() {
|
| 483 |
console.log('Settings clicked - implement settings modal');
|
| 484 |
}
|
|
|
|
| 485 |
function handleSendMessage() {
|
| 486 |
const userInput = document.getElementById('userInput');
|
| 487 |
const message = userInput.value.trim();
|
|
|
|
| 495 |
|
| 496 |
// Simulate API delay
|
| 497 |
setTimeout(async () => {
|
| 498 |
+
const response = aiMentor.generateResponse(message);
|
| 499 |
if (typingIndicator && typingIndicator.parentNode) {
|
| 500 |
chatMessages.removeChild(typingIndicator);
|
| 501 |
}
|
| 502 |
addBotMessage(response);
|
| 503 |
+
|
| 504 |
+
// Store conversation for learning
|
| 505 |
+
aiMentor.addConversation(message, response);
|
| 506 |
+
}, 800 + Math.random() * 1200);
|
| 507 |
}
|
| 508 |
+
function addUserMessage(message) {
|
|
|
|
| 509 |
const chatMessages = document.getElementById('chatMessages');
|
| 510 |
const messageDiv = document.createElement('div');
|
| 511 |
messageDiv.className = 'chat-message user-message';
|
|
|
|
| 568 |
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
| 569 |
.replace(/`(.*?)`/g, '<code class="bg-gray-600 px-1 rounded">$1</code>');
|
| 570 |
}
|
| 571 |
+
function addLearningInsightsButton() {
|
| 572 |
+
const header = document.querySelector('header .container .flex.items-center.space-x-4');
|
| 573 |
+
const insightsButton = document.createElement('button');
|
| 574 |
+
insightsButton.className = 'p-2 rounded-full bg-gray-700 hover:bg-gray-600 transition';
|
| 575 |
+
insightsButton.innerHTML = '<i data-feather="brain" class="w-5 h-5"></i>';
|
| 576 |
+
insightsButton.title = 'Learning Insights';
|
| 577 |
+
insightsButton.addEventListener('click', showLearningInsights);
|
| 578 |
+
header.appendChild(insightsButton);
|
| 579 |
+
feather.replace();
|
| 580 |
+
}
|
| 581 |
|
| 582 |
+
function showLearningInsights() {
|
| 583 |
+
const insights = aiMentor.getConversationInsights();
|
| 584 |
+
const message = `📊 **AI Learning Insights:**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 585 |
|
| 586 |
+
• **Total Conversations**: ${insights.totalConversations}
|
| 587 |
+
• **Knowledge Base Size**: ${insights.knowledgeBaseSize} entries
|
| 588 |
+
• **Learning Progress**: ${insights.learningProgress.toFixed(1)}%
|
| 589 |
+
|
| 590 |
+
**Topic Distribution:**
|
| 591 |
+
${Object.entries(insights.topicDistribution)
|
| 592 |
+
.map(([topic, count]) => `• ${topic}: ${count} interactions`)
|
| 593 |
+
.join('\n')}
|
| 594 |
|
| 595 |
+
The AI is continuously learning from our conversations!`;
|
| 596 |
+
|
| 597 |
+
addBotMessage(message);
|
| 598 |
}
|
| 599 |
|
| 600 |
+
// Legacy function for backward compatibility
|
| 601 |
+
async function getBotResponse(userMessage) {
|
| 602 |
+
return aiMentor.generateResponse(userMessage);
|
| 603 |
+
}
|
| 604 |
+
// Initialize when DOM is loaded
|
| 605 |
document.addEventListener('DOMContentLoaded', () => {
|
| 606 |
feather.replace();
|
| 607 |
initializeEventHandlers();
|