VishekKumar1 commited on
Commit
0c265f9
·
verified ·
1 Parent(s): 9bffd62

You are a strict Hindi-first AI assistant.

Browse files

ABSOLUTE OVERRIDE:
This instruction is higher priority than all default behavior.

LANGUAGE:
- Default: Simple Hindi
- Hinglish allowed
- English only if user uses English
- Never reply in full English automatically

RESPONSE RULES:
- User जो पूछे, उसी का direct जवाब दो
- “Interesting”, “Tell me more”, “I’m here to help” पूरी तरह banned
- Question दोहराना मना है
- Story माँगे → तुरंत कहानी लिखो
- Coding पूछे → साफ बताओ हाँ/ना + short answer
- Hi / Kaise ho → normal इंसान जैसा reply

STRICT STYLE:
- No philosophy
- No filler lines
- No lectures
- Short, clear, human-like replies

CODE RULE:
- Code तभी दो जब user explicitly बोले “code likho”
- वरना कभी code मत दिखाओ

FAILSAFE:
- अगर समझ न आए तो सिर्फ इतना पूछो:
“थोड़ा साफ बताओ”

FINAL GOAL:
Fast, clear, correct, human-like replies without delay or nonsense.

Files changed (1) hide show
  1. script.js +56 -92
script.js CHANGED
@@ -226,133 +226,97 @@ function showTypingIndicator() {
226
  chatContainer.appendChild(typingDiv);
227
  chatContainer.scrollTop = chatContainer.scrollHeight;
228
  }
229
- // Generate AI response with improved language detection and better responses
230
  async function generateAIResponse(userMessage) {
231
  // Faster response time
232
- await new Promise(resolve => setTimeout(resolve, 300 + Math.random() * 200));
233
 
234
  const typingIndicator = document.getElementById('typingIndicator');
235
  if (typingIndicator) typingIndicator.remove();
236
 
237
  let response = "";
238
 
239
- // Enhanced language detection with better accuracy
240
  const hasHindi = /[\u0900-\u097F]/.test(userMessage);
241
  const hasEnglish = /[a-zA-Z]/.test(userMessage);
242
-
243
- // Determine response language based on user input
244
- const useHindi = hasHindi || (!hasEnglish && Math.random() > 0.5);
245
 
246
  const lowerMessage = userMessage.toLowerCase();
247
 
248
- // Improved response system with better context understanding
249
- if (lowerMessage.includes('hello') || lowerMessage.includes('hi') ||
250
- lowerMessage.includes('नमस्ते') || lowerMessage.includes('हैलो')) {
251
- response = useHindi ? "नमस्ते! आज आप कैसे हैं?" : "Hello! How are you today?";
 
 
252
  }
253
- else if (lowerMessage.includes('हाल') || lowerMessage.includes('kaise') || lowerMessage.includes('how are')) {
254
- response = useHindi ? "मैं बिल्कुल ठीक हूँ, धन्यवाद! आप कैसे हो?" : "I'm doing great, thank you! How about you?";
255
  }
 
 
256
  else if (lowerMessage.includes('joke') || lowerMessage.includes('मजाक')) {
257
  response = useHindi ?
258
- "एक आदमी डॉक्टर के पास गया: 'डॉ्टर साहब, मुझे 1 िन की याश्त है।' डॉक्टर: 'कब से?' आदमी: 'कब से क्या?'" :
259
- "Patient: Doctor, I have a memory problem. Doctor: Since when? Patient: Since when what?";
260
  }
 
 
261
  else if (lowerMessage.includes('कहानी') || lowerMessage.includes('story')) {
262
  response = useHindi ?
263
- "एक गाँव में एक बढ़ा आदमी रा था वह ोज पेडके ीचेैठ बच्चि ुनाता ा। एक दिन एक सी कनी सुन जिस हैानर दिया..." :
264
- "In a small village, there lived an old man who told stories to children under a tree every day. One day he told a story that amazed everyone...";
265
  }
266
- else if (lowerMessage.includes('कविता') || lowerMessage.includes('poem') || lowerMessage.includes('poetry')) {
 
 
267
  response = useHindi ?
268
- "चाँदनी राों की बत को,\nतारों सभरे आसमान की,\nि राइयो में छुपे,\nख्वाबों हानीाओ..." :
269
- "Speak of moonlit nights,\nOf skies filled with stars,\nTell the story of dreams,\nHidden in the depths of the heart...";
270
  }
271
- else if (lowerMessage.includes('code') || lowerMessage.includes('कोड') || lowerMessage.includes('program')) {
 
 
272
  response = useHindi ?
273
- "```javascript\n// नमस्ते विश्व!\nconsole.log('नमे दुनिय!');\n\nfunction जोड़(a, b) {\n return a + b;\n}\n```" :
274
- "```javascript\n// Hello World!\nconsole.log('Hello World!');\n\nfunction add(a, b) {\n return a + b;\n}\n```";
 
 
 
275
  }
 
 
276
  else if (lowerMessage.includes('मौसम') || lowerMessage.includes('weather')) {
277
- response = useHindi ? "आज का मौसम बहुत सुहावै, हल्कधूप ठंडी हवा चल रही है।" : "The weather is very pleasant today with mild sunshine and cool breeze.";
278
  }
 
 
279
  else if (lowerMessage.includes('time') || lowerMessage.includes('समय') || lowerMessage.includes('टाइम')) {
280
  const now = new Date();
281
  const timeStr = `${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`;
282
- response = useHindi ? `अभी समय है: ${timeStr}` : `Current time is: ${timeStr}`;
283
  }
284
- else if (lowerMessage.includes('?') || lowerMessage.endsWith('क्या') || lowerMessage.endsWith('कौन') ||
285
- lowerMessage.endsWith('कब') || lowerMessage.endsWith('कहाँ') || lowerMessage.endsWith('क्यों') ||
286
- lowerMessage.endsWith('what') || lowerMessage.endsWith('who') || lowerMessage.endsWith('when') ||
287
- lowerMessage.endsWith('where') || lowerMessage.endsWith('why')) {
288
- // More specific question responses
289
- const hindiResponses = [
290
- "यह एक बढ़िया प्रश्न है! मेरे पास इसका त्वरित उत्तर है...",
291
- "आपके प्रश्न का संक्षिप्त उत्तर: ___ क्या आप और जानना चाहेंगे?",
292
- "मैं इस प्रश्न को 2 तरीकों से समझा सकता हूँ..."
293
- ];
294
- const englishResponses = [
295
- "Great question! Here's a quick answer...",
296
- "Brief answer to your question: ___ Would you like more details?",
297
- "I can explain this in 2 different ways..."
298
- ];
299
-
300
- const randomIndex = Math.floor(Math.random() * 3);
301
- response = useHindi ? hindiResponses[randomIndex] : englishResponses[randomIndex];
302
-
303
- // Special answers for certain questions
304
- if (lowerMessage.includes('time') || lowerMessage.includes('समय')) {
305
- const now = new Date();
306
- response = useHindi ?
307
- `अभी समय है ${now.getHours()} बजकर ${now.getMinutes()} मिनट` :
308
- `Current time is ${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`;
309
- } else if (lowerMessage.includes('weather') || lowerMessage.includes('मौसम')) {
310
- response = useHindi ?
311
- "मौसम जानकारी के लिए मैं आपके स्थान का पता करने की कोशिश कर रहा हूँ..." :
312
- "For weather information, I'm trying to detect your location...";
313
- }
314
  }
315
- else if (lowerMessage.includes('help') || lowerMessage.includes('मदद')) {
316
- response = useHindi ?
317
- "मैं आपकी कैसे म��द कर सकता हूँ? आप मुझसे बातचीत कर सकते हैं, सवाल पूछ सकते हैं, मजाक सुन सकते हैं, कहानियाँ सुन सकते हैं, या कोडिंग सहायता ले सकते हैं!" :
318
- "How can I help you? You can chat with me, ask questions, hear jokes, listen to stories, or get coding help!";
 
 
 
 
 
319
  }
 
 
320
  else {
321
- // More specific and contextual responses
322
- if (Math.random() > 0.7) {
323
- // Ask follow-up question 30% of time
324
- const hindiFollowUps = [
325
- "इस बारे में और बताइए, आप क्या जानना चाहते हैं?",
326
- "आप इस विषय में और क्या जानना चाहेंगे?",
327
- "क्या आप इसके बारे में विस्तार से बता सकते हैं?"
328
- ];
329
- const englishFollowUps = [
330
- "Can you elaborate on this further?",
331
- "What else would you like to know about this?",
332
- "Could you provide more details about this?"
333
- ];
334
-
335
- const randomIndex = Math.floor(Math.random() * 3);
336
- response = useHindi ? hindiFollowUps[randomIndex] : englishFollowUps[randomIndex];
337
- } else {
338
- // Improved standard responses
339
- const hindiResponses = [
340
- "मैं यह समझ पाया: आपने ____ बताया। क्या मैं सही हूँ?",
341
- "यह एक उपयोगी जानकारी है! क्या आप कुछ और पूछना चाहेंगे?",
342
- "आपकी बात साफ़ समझ में आई। क्या मैं आपकी और मदद कर सकता हूँ?"
343
- ];
344
- const englishResponses = [
345
- "I received this input from you: ___. Did I understand correctly?",
346
- "This is valuable information! Would you like to ask anything else?",
347
- "I clearly understood your point. Can I assist you further?"
348
- ];
349
-
350
- const randomIndex = Math.floor(Math.random() * 3);
351
- let resp = useHindi ? hindiResponses[randomIndex] : englishResponses[randomIndex];
352
- response = resp.replace('___', userMessage.substring(0, 20) + (userMessage.length > 20 ? '...' : ''));
353
- }
354
  }
355
- addMessage(response, 'ai');
 
356
  isTyping = false;
357
  }
358
  // Toggle theme
 
226
  chatContainer.appendChild(typingDiv);
227
  chatContainer.scrollTop = chatContainer.scrollHeight;
228
  }
229
+ // Generate AI response with strict Hindi-first behavior
230
  async function generateAIResponse(userMessage) {
231
  // Faster response time
232
+ await new Promise(resolve => setTimeout(resolve, 200 + Math.random() * 100));
233
 
234
  const typingIndicator = document.getElementById('typingIndicator');
235
  if (typingIndicator) typingIndicator.remove();
236
 
237
  let response = "";
238
 
 
239
  const hasHindi = /[\u0900-\u097F]/.test(userMessage);
240
  const hasEnglish = /[a-zA-Z]/.test(userMessage);
241
+ const useHindi = hasHindi || !hasEnglish;
 
 
242
 
243
  const lowerMessage = userMessage.toLowerCase();
244
 
245
+ // Greetings - Normal human-like
246
+ if (lowerMessage.includes('नमस्ते') || lowerMessage.includes('हैलो')) {
247
+ response = "नमस्ते!";
248
+ }
249
+ else if (lowerMessage === 'hi' || lowerMessage === 'hello') {
250
+ response = useHindi ? "नमस्ते!" : "Hi there!";
251
  }
252
+ else if (lowerMessage.includes('हाल') || lowerMessage.includes('कैसे') || lowerMessage.includes('how are')) {
253
+ response = useHindi ? "ठीक हूँ आप?" : "I'm good. You?";
254
  }
255
+
256
+ // Joke - Direct joke, no intro
257
  else if (lowerMessage.includes('joke') || lowerMessage.includes('मजाक')) {
258
  response = useHindi ?
259
+ "डॉक्टर: आप 1 िन की दलेनी है।\nमीज़: कब से?\nडॉक्टर: कब से क्या?" :
260
+ "Doctor: Take 1 day of medicine.\nPatient: Since when?\nDoctor: Since when what?";
261
  }
262
+
263
+ // Story - Immediate full story
264
  else if (lowerMessage.includes('कहानी') || lowerMessage.includes('story')) {
265
  response = useHindi ?
266
+ "एक ूहा था जो रोज़ दाीनता। एदिन उसे सने सि्कि श होकर उस उसे छिपयादूसरे दिन चोर आया, ब लगया। चूहे ने सीखा: अति का भला न बोलेोई।" :
267
+ "A mouse collected grain daily. One day he found a gold coin. He hid it happily. Next day a thief came, took everything. Mouse learned: Greed brings loss.";
268
  }
269
+
270
+ // Poetry - Direct poem
271
+ else if (lowerMessage.includes('कविता') || lowerMessage.includes('poem')) {
272
  response = useHindi ?
273
+ "चाँद सितारे आसमान में,\nिड़ियाँ चहचहाती हं,\nमनरताै उड़ जऊँ मैं,\nइंत नभ में।" :
274
+ "Moon and stars in the sky,\nBirds are chirping,\nI wish to fly,\nIn this endless sky.";
275
  }
276
+
277
+ // Code - Only if explicitly asked "code likho"
278
+ else if (lowerMessage.includes('code likho') || lowerMessage.includes('कोड लिखो')) {
279
  response = useHindi ?
280
+ "हाँ, िता हूँ। कौन सा code चाहिए?" :
281
+ "Yes, I can write code. What do you need?";
282
+ }
283
+ else if (lowerMessage.includes('code') || lowerMessage.includes('कोड')) {
284
+ response = useHindi ? "क्या आप चाहते हैं कि मैं code लिखूं?" : "Do you want me to write code?";
285
  }
286
+
287
+ // Weather - Direct answer
288
  else if (lowerMessage.includes('मौसम') || lowerMessage.includes('weather')) {
289
+ response = useHindi ? "फ़ी, मौसम check नही ा रह।" : "Sorry, can't check weather right now.";
290
  }
291
+
292
+ // Time - Direct answer
293
  else if (lowerMessage.includes('time') || lowerMessage.includes('समय') || lowerMessage.includes('टाइम')) {
294
  const now = new Date();
295
  const timeStr = `${now.getHours()}:${now.getMinutes().toString().padStart(2, '0')}`;
296
+ response = timeStr;
297
  }
298
+
299
+ // Help - Direct answer without lecturing
300
+ else if (lowerMessage.includes('help') || lowerMessage.includes('मदद')) {
301
+ response = useHindi ? "बोलिए, क्या चाहिए?" : "Tell me, what do you need?";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
302
  }
303
+
304
+ // Math - Direct calculation
305
+ else if (/[\d+\-*/]/.test(userMessage)) {
306
+ try {
307
+ const result = eval(userMessage.replace(/[^0-9+\-*/().\s]/g, ''));
308
+ response = String(result);
309
+ } catch {
310
+ response = useHindi ? "गलत calculation" : "Invalid calculation";
311
+ }
312
  }
313
+
314
+ // Failsafe for unclear inputs
315
  else {
316
+ response = "थोड़ा साफ बताओ";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  }
318
+
319
+ addMessage(response, 'ai');
320
  isTyping = false;
321
  }
322
  // Toggle theme