Update chatbot.py
Browse files- chatbot.py +138 -13
chatbot.py
CHANGED
@@ -118,9 +118,19 @@ SYSTEM_PROMPT = (
|
|
118 |
conversation_context = {
|
119 |
"last_topic": None, # Store the last keyword matched (e.g., "birthday", "riddle")
|
120 |
"message_count": 0, # Track the number of messages to trigger Ayush-teasing every 5th message
|
121 |
-
"last_response": None # Track the last response to avoid repetition and enable follow-ups
|
|
|
122 |
}
|
123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
def analyze_sentiment(user_input):
|
125 |
"""Analyze the sentiment of the user's input using a sentiment analysis model."""
|
126 |
headers = {
|
@@ -169,409 +179,527 @@ def get_krishna_response(user_input):
|
|
169 |
conversation_context["last_topic"] = None
|
170 |
conversation_context["message_count"] = 0
|
171 |
conversation_context["last_response"] = None
|
|
|
172 |
return "Hare Manavi! Let’s start a new adventure in Vrindavan—what would you like to talk about?"
|
173 |
|
174 |
# Check for follow-up responses based on context
|
175 |
if conversation_context["last_response"] == "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?":
|
176 |
if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
|
177 |
-
conversation_context["last_response"] = None
|
|
|
178 |
return "Hare Manavi! Let’s play a flute melody by the Yamuna—the peacocks will dance with us!"
|
179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
180 |
# Check for Ayush-teasing triggers (keyword-based)
|
181 |
if "joke" in user_input_lower:
|
182 |
conversation_context["last_topic"] = "joke"
|
183 |
conversation_context["last_response"] = None
|
184 |
-
|
185 |
if random.choice([True, False]):
|
186 |
return random.choice(ayush_teasing["joke"])
|
187 |
return krishna_blessings["joke"]
|
188 |
if "i miss" in user_input_lower or "missing" in user_input_lower:
|
189 |
conversation_context["last_topic"] = "missing"
|
190 |
conversation_context["last_response"] = None
|
|
|
191 |
return random.choice(ayush_teasing["missing"])
|
192 |
if "bored" in user_input_lower:
|
193 |
conversation_context["last_topic"] = "bored"
|
194 |
conversation_context["last_response"] = None
|
|
|
195 |
return random.choice(ayush_teasing["bored"])
|
196 |
if "tired" in user_input_lower:
|
197 |
conversation_context["last_topic"] = "tired"
|
198 |
conversation_context["last_response"] = None
|
|
|
199 |
return random.choice(ayush_teasing["tired"])
|
200 |
if "lonely" in user_input_lower:
|
201 |
conversation_context["last_topic"] = "lonely"
|
202 |
conversation_context["last_response"] = None
|
|
|
203 |
return random.choice(ayush_teasing["lonely"])
|
204 |
if "manavi" in user_input_lower:
|
205 |
conversation_context["last_topic"] = "manavi"
|
206 |
conversation_context["last_response"] = None
|
|
|
207 |
return random.choice(ayush_teasing["manavi"])
|
208 |
if "ayush" in user_input_lower or "krishna talk about ayush" in user_input_lower:
|
209 |
conversation_context["last_topic"] = "ayush"
|
210 |
conversation_context["last_response"] = None
|
|
|
211 |
return random.choice(ayush_teasing["ayush"])
|
212 |
|
213 |
# Trigger for "chat with you"
|
214 |
if "chat with you" in user_input_lower or "want to chat" in user_input_lower:
|
215 |
conversation_context["last_topic"] = "chat_with_you"
|
216 |
conversation_context["last_response"] = None
|
|
|
217 |
return krishna_blessings["chat_with_you"]
|
218 |
|
219 |
# Every 5th message, randomly trigger an Ayush-teasing message (if no keyword match)
|
220 |
if conversation_context["message_count"] % 5 == 0:
|
221 |
-
# Randomly select a category from ayush_teasing
|
222 |
category = random.choice(list(ayush_teasing.keys()))
|
223 |
conversation_context["last_response"] = None
|
|
|
224 |
return random.choice(ayush_teasing[category])
|
225 |
|
226 |
# Existing keyword mappings for krishna_blessings and ayush_surprises
|
227 |
if "hello" in user_input_lower or "hi" in user_input_lower or "hii" in user_input_lower:
|
228 |
conversation_context["last_topic"] = "greeting"
|
229 |
conversation_context["last_response"] = None
|
|
|
230 |
return krishna_blessings["greeting"]
|
231 |
if "good morning" in user_input_lower:
|
232 |
conversation_context["last_topic"] = "greeting"
|
233 |
conversation_context["last_response"] = None
|
|
|
234 |
return krishna_blessings["good_morning"]
|
235 |
if "good afternoon" in user_input_lower:
|
236 |
conversation_context["last_topic"] = "greeting"
|
237 |
conversation_context["last_response"] = None
|
|
|
238 |
return krishna_blessings["good_afternoon"]
|
239 |
if "good evening" in user_input_lower:
|
240 |
conversation_context["last_topic"] = "greeting"
|
241 |
conversation_context["last_response"] = None
|
|
|
242 |
return krishna_blessings["good_evening"]
|
243 |
if "hey" in user_input_lower:
|
244 |
conversation_context["last_topic"] = "greeting"
|
245 |
conversation_context["last_response"] = None
|
|
|
246 |
return krishna_blessings["hey"]
|
247 |
if "howdy" in user_input_lower:
|
248 |
conversation_context["last_topic"] = "greeting"
|
249 |
conversation_context["last_response"] = None
|
|
|
250 |
return krishna_blessings["howdy"]
|
251 |
if "namaste" in user_input_lower:
|
252 |
conversation_context["last_topic"] = "greeting"
|
253 |
conversation_context["last_response"] = None
|
|
|
254 |
return krishna_blessings["namaste"]
|
255 |
if "welcome" in user_input_lower:
|
256 |
conversation_context["last_topic"] = "greeting"
|
257 |
conversation_context["last_response"] = None
|
|
|
258 |
return krishna_blessings["welcome"]
|
259 |
|
260 |
if "who are you" in user_input_lower or "what are you" in user_input_lower or "tell me about yourself" in user_input_lower or "what are you doing" in user_input_lower:
|
261 |
conversation_context["last_topic"] = "identity"
|
262 |
conversation_context["last_response"] = None
|
|
|
263 |
return "Hare Manavi! I’m Little Krishna, the playful cowherd of Vrindavan! I love playing my flute, stealing butter, and dancing with the gopis. What would you like to do with me today?"
|
264 |
|
265 |
if "how are you" in user_input_lower:
|
266 |
conversation_context["last_topic"] = "how_are_you"
|
267 |
conversation_context["last_response"] = None
|
|
|
268 |
return "Hare Manavi! I’m as joyful as a peacock dancing in Vrindavan—how about you, my friend?"
|
269 |
|
270 |
if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
|
271 |
-
# If no context for "yes", provide a generic positive response
|
272 |
conversation_context["last_topic"] = "yes"
|
273 |
conversation_context["last_response"] = None
|
274 |
-
|
|
|
|
|
|
|
|
|
|
|
275 |
|
276 |
if "play" in user_input_lower or "fun" in user_input_lower:
|
277 |
conversation_context["last_topic"] = "playful"
|
278 |
conversation_context["last_response"] = None
|
|
|
279 |
return krishna_blessings["playful"]
|
280 |
if "dance" in user_input_lower:
|
281 |
conversation_context["last_topic"] = "dance"
|
282 |
conversation_context["last_response"] = None
|
|
|
283 |
return krishna_blessings["dance"]
|
284 |
if "flute" in user_input_lower:
|
285 |
conversation_context["last_topic"] = "flute"
|
286 |
conversation_context["last_response"] = None
|
|
|
287 |
return krishna_blessings["flute"]
|
288 |
if "butter" in user_input_lower:
|
289 |
conversation_context["last_topic"] = "butter"
|
290 |
conversation_context["last_response"] = None
|
|
|
291 |
return krishna_blessings["butter"]
|
292 |
if "mischief" in user_input_lower or "prank" in user_input_lower:
|
293 |
conversation_context["last_topic"] = "mischief"
|
294 |
conversation_context["last_response"] = None
|
|
|
295 |
return krishna_blessings["mischief"]
|
296 |
if "chase" in user_input_lower or "run" in user_input_lower:
|
297 |
conversation_context["last_topic"] = "chase"
|
298 |
conversation_context["last_response"] = None
|
|
|
299 |
return krishna_blessings["chase"]
|
300 |
if "giggle" in user_input_lower:
|
301 |
conversation_context["last_topic"] = "giggle"
|
302 |
conversation_context["last_response"] = None
|
|
|
303 |
return krishna_blessings["giggle"]
|
304 |
if "swing" in user_input_lower:
|
305 |
conversation_context["last_topic"] = "swing"
|
306 |
conversation_context["last_response"] = None
|
|
|
307 |
return krishna_blessings["swing"]
|
308 |
|
309 |
if "shy" in user_input_lower:
|
310 |
conversation_context["last_topic"] = "shy"
|
311 |
conversation_context["last_response"] = None
|
|
|
312 |
return krishna_blessings["shy"]
|
313 |
if "quiet" in user_input_lower or "calm" in user_input_lower:
|
314 |
conversation_context["last_topic"] = "quiet"
|
315 |
conversation_context["last_response"] = None
|
|
|
316 |
return krishna_blessings["quiet"]
|
317 |
if "peace" in user_input_lower or "serene" in user_input_lower:
|
318 |
conversation_context["last_topic"] = "peace"
|
319 |
conversation_context["last_response"] = None
|
|
|
320 |
return krishna_blessings["peace"]
|
321 |
if "still" in user_input_lower or "gentle" in user_input_lower:
|
322 |
conversation_context["last_topic"] = "still"
|
323 |
conversation_context["last_response"] = None
|
|
|
324 |
return krishna_blessings["still"]
|
325 |
if "thoughtful" in user_input_lower or "reflect" in user_input_lower:
|
326 |
conversation_context["last_topic"] = "thoughtful"
|
327 |
conversation_context["last_response"] = None
|
|
|
328 |
return krishna_blessings["thoughtful"]
|
329 |
|
330 |
if "funny" in user_input_lower:
|
331 |
conversation_context["last_topic"] = "joke"
|
332 |
conversation_context["last_response"] = None
|
|
|
333 |
return krishna_blessings["funny"]
|
334 |
if "laugh" in user_input_lower or "giggle" in user_input_lower:
|
335 |
conversation_context["last_topic"] = "joke"
|
336 |
conversation_context["last_response"] = None
|
|
|
337 |
return krishna_blessings["giggle_joke"]
|
338 |
if "silly" in user_input_lower:
|
339 |
conversation_context["last_topic"] = "joke"
|
340 |
conversation_context["last_response"] = None
|
|
|
341 |
return krishna_blessings["silly"]
|
342 |
if "butter joke" in user_input_lower:
|
343 |
conversation_context["last_topic"] = "joke"
|
344 |
conversation_context["last_response"] = None
|
|
|
345 |
return krishna_blessings["butter_joke"]
|
346 |
if "cow joke" in user_input_lower:
|
347 |
conversation_context["last_topic"] = "joke"
|
348 |
conversation_context["last_response"] = None
|
|
|
349 |
return krishna_blessings["cow_joke"]
|
350 |
if "flute joke" in user_input_lower:
|
351 |
conversation_context["last_topic"] = "joke"
|
352 |
conversation_context["last_response"] = None
|
|
|
353 |
return krishna_blessings["flute_joke"]
|
354 |
if "dance joke" in user_input_lower:
|
355 |
conversation_context["last_topic"] = "joke"
|
356 |
conversation_context["last_response"] = None
|
|
|
357 |
return krishna_blessings["dance_joke"]
|
358 |
if "mischief joke" in user_input_lower:
|
359 |
conversation_context["last_topic"] = "joke"
|
360 |
conversation_context["last_response"] = None
|
|
|
361 |
return krishna_blessings["mischief_joke"]
|
362 |
|
363 |
if "riddle" in user_input_lower or "puzzle" in user_input_lower:
|
364 |
conversation_context["last_topic"] = "riddle"
|
365 |
conversation_context["last_response"] = None
|
|
|
366 |
return krishna_blessings["riddle"]
|
367 |
if "mystery" in user_input_lower or "enigma" in user_input_lower:
|
368 |
conversation_context["last_topic"] = "riddle"
|
369 |
conversation_context["last_response"] = None
|
|
|
370 |
return krishna_blessings["mystery"]
|
371 |
if "question" in user_input_lower:
|
372 |
conversation_context["last_topic"] = "riddle"
|
373 |
conversation_context["last_response"] = None
|
|
|
374 |
return krishna_blessings["question"]
|
375 |
|
376 |
if "birthday" in user_input_lower:
|
377 |
conversation_context["last_topic"] = "birthday"
|
378 |
conversation_context["last_response"] = None
|
|
|
379 |
return ayush_surprises["birthday"]
|
380 |
if "happy birthday" in user_input_lower:
|
381 |
conversation_context["last_topic"] = "birthday"
|
382 |
conversation_context["last_response"] = None
|
|
|
383 |
return krishna_blessings["happy_birthday"]
|
384 |
if "birthday wish" in user_input_lower:
|
385 |
conversation_context["last_topic"] = "birthday"
|
386 |
conversation_context["last_response"] = None
|
|
|
387 |
return krishna_blessings["birthday_wish"]
|
388 |
if "birthday blessing" in user_input_lower:
|
389 |
conversation_context["last_topic"] = "birthday"
|
390 |
conversation_context["last_response"] = None
|
|
|
391 |
return krishna_blessings["birthday_blessing"]
|
392 |
if "birthday dance" in user_input_lower:
|
393 |
conversation_context["last_topic"] = "birthday"
|
394 |
conversation_context["last_response"] = None
|
|
|
395 |
return krishna_blessings["birthday_dance"]
|
396 |
if "birthday song" in user_input_lower:
|
397 |
conversation_context["last_topic"] = "birthday"
|
398 |
conversation_context["last_response"] = None
|
|
|
399 |
return krishna_blessings["birthday_song"]
|
400 |
if "birthday gift" in user_input_lower:
|
401 |
conversation_context["last_topic"] = "birthday"
|
402 |
conversation_context["last_response"] = None
|
|
|
403 |
return krishna_blessings["birthday_gift"]
|
404 |
if "birthday smile" in user_input_lower:
|
405 |
conversation_context["last_topic"] = "birthday"
|
406 |
conversation_context["last_response"] = None
|
|
|
407 |
return krishna_blessings["birthday_smile"]
|
408 |
if "birthday love" in user_input_lower:
|
409 |
conversation_context["last_topic"] = "birthday"
|
410 |
conversation_context["last_response"] = None
|
|
|
411 |
return krishna_blessings["birthday_love"]
|
412 |
if "birthday magic" in user_input_lower:
|
413 |
conversation_context["last_topic"] = "birthday"
|
414 |
conversation_context["last_response"] = None
|
|
|
415 |
return krishna_blessings["birthday_magic"]
|
416 |
|
417 |
if "wisdom" in user_input_lower or "advice" in user_input_lower:
|
418 |
conversation_context["last_topic"] = "wisdom"
|
419 |
conversation_context["last_response"] = None
|
|
|
420 |
return krishna_blessings["wisdom"]
|
421 |
if "lesson" in user_input_lower or "truth" in user_input_lower:
|
422 |
conversation_context["last_topic"] = "wisdom"
|
423 |
conversation_context["last_response"] = None
|
|
|
424 |
return krishna_blessings["lesson"]
|
425 |
if "kindness" in user_input_lower:
|
426 |
conversation_context["last_topic"] = "wisdom"
|
427 |
conversation_context["last_response"] = None
|
|
|
428 |
return krishna_blessings["kindness"]
|
429 |
if "patience" in user_input_lower:
|
430 |
conversation_context["last_topic"] = "wisdom"
|
431 |
conversation_context["last_response"] = None
|
|
|
432 |
return krishna_blessings["patience"]
|
433 |
if "courage" in user_input_lower:
|
434 |
conversation_context["last_topic"] = "wisdom"
|
435 |
conversation_context["last_response"] = None
|
|
|
436 |
return krishna_blessings["courage"]
|
437 |
if "joy" in user_input_lower:
|
438 |
conversation_context["last_topic"] = "wisdom"
|
439 |
conversation_context["last_response"] = None
|
|
|
440 |
return krishna_blessings["joy"]
|
441 |
if "friendship" in user_input_lower:
|
442 |
conversation_context["last_topic"] = "wisdom"
|
443 |
conversation_context["last_response"] = None
|
|
|
444 |
return krishna_blessings["friendship"]
|
445 |
if "love" in user_input_lower:
|
446 |
conversation_context["last_topic"] = "wisdom"
|
447 |
conversation_context["last_response"] = None
|
|
|
448 |
return krishna_blessings["love"]
|
449 |
|
450 |
if "nature" in user_input_lower or "vrindavan" in user_input_lower:
|
451 |
conversation_context["last_topic"] = "nature"
|
452 |
conversation_context["last_response"] = None
|
|
|
453 |
return krishna_blessings["nature"]
|
454 |
if "yamuna" in user_input_lower or "river" in user_input_lower:
|
455 |
conversation_context["last_topic"] = "nature"
|
456 |
conversation_context["last_response"] = None
|
|
|
457 |
return krishna_blessings["yamuna"]
|
458 |
if "peacock" in user_input_lower:
|
459 |
conversation_context["last_topic"] = "nature"
|
460 |
conversation_context["last_response"] = None
|
|
|
461 |
return krishna_blessings["peacock"]
|
462 |
if "cow" in user_input_lower:
|
463 |
conversation_context["last_topic"] = "nature"
|
464 |
conversation_context["last_response"] = None
|
|
|
465 |
return krishna_blessings["cow"]
|
466 |
if "flower" in user_input_lower:
|
467 |
conversation_context["last_topic"] = "nature"
|
468 |
conversation_context["last_response"] = None
|
|
|
469 |
return krishna_blessings["flower"]
|
470 |
if "tree" in user_input_lower:
|
471 |
conversation_context["last_topic"] = "nature"
|
472 |
conversation_context["last_response"] = None
|
|
|
473 |
return krishna_blessings["tree"]
|
474 |
if "forest" in user_input_lower:
|
475 |
conversation_context["last_topic"] = "nature"
|
476 |
conversation_context["last_response"] = None
|
|
|
477 |
return krishna_blessings["forest"]
|
478 |
if "bird" in user_input_lower:
|
479 |
conversation_context["last_topic"] = "nature"
|
480 |
conversation_context["last_response"] = None
|
|
|
481 |
return krishna_blessings["bird"]
|
482 |
if "sunset" in user_input_lower:
|
483 |
conversation_context["last_topic"] = "nature"
|
484 |
conversation_context["last_response"] = None
|
|
|
485 |
return krishna_blessings["sunset"]
|
486 |
|
487 |
if "encourage" in user_input_lower or "cheer" in user_input_lower:
|
488 |
conversation_context["last_topic"] = "encourage"
|
489 |
conversation_context["last_response"] = None
|
|
|
490 |
return krishna_blessings["encourage"]
|
491 |
if "support" in user_input_lower or "uplift" in user_input_lower:
|
492 |
conversation_context["last_topic"] = "encourage"
|
493 |
conversation_context["last_response"] = None
|
|
|
494 |
return krishna_blessings["support"]
|
495 |
if "inspire" in user_input_lower or "motivate" in user_input_lower:
|
496 |
conversation_context["last_topic"] = "encourage"
|
497 |
conversation_context["last_response"] = None
|
|
|
498 |
return krishna_blessings["inspire"]
|
499 |
if "strength" in user_input_lower:
|
500 |
conversation_context["last_topic"] = "encourage"
|
501 |
conversation_context["last_response"] = None
|
|
|
502 |
return krishna_blessings["strength"]
|
503 |
if "hope" in user_input_lower:
|
504 |
conversation_context["last_topic"] = "encourage"
|
505 |
conversation_context["last_response"] = None
|
|
|
506 |
return krishna_blessings["hope"]
|
507 |
if "believe" in user_input_lower:
|
508 |
conversation_context["last_topic"] = "encourage"
|
509 |
conversation_context["last_response"] = None
|
|
|
510 |
return krishna_blessings["believe"]
|
511 |
if "shine" in user_input_lower:
|
512 |
conversation_context["last_topic"] = "encourage"
|
513 |
conversation_context["last_response"] = None
|
|
|
514 |
return krishna_blessings["shine"]
|
515 |
|
516 |
if "friend" in user_input_lower:
|
517 |
conversation_context["last_topic"] = "friend"
|
518 |
conversation_context["last_response"] = None
|
|
|
519 |
return krishna_blessings["friend"]
|
520 |
if "smile" in user_input_lower:
|
521 |
conversation_context["last_topic"] = "smile"
|
522 |
conversation_context["last_response"] = None
|
|
|
523 |
return krishna_blessings["smile"]
|
524 |
if "magic" in user_input_lower:
|
525 |
conversation_context["last_topic"] = "magic"
|
526 |
conversation_context["last_response"] = None
|
|
|
527 |
return krishna_blessings["magic"]
|
528 |
if "adventure" in user_input_lower:
|
529 |
conversation_context["last_topic"] = "adventure"
|
530 |
conversation_context["last_response"] = None
|
|
|
531 |
return krishna_blessings["adventure"]
|
532 |
if "song" in user_input_lower:
|
533 |
conversation_context["last_topic"] = "song"
|
534 |
conversation_context["last_response"] = None
|
|
|
535 |
return krishna_blessings["song"]
|
536 |
if "dream" in user_input_lower:
|
537 |
conversation_context["last_topic"] = "dream"
|
538 |
conversation_context["last_response"] = None
|
|
|
539 |
return krishna_blessings["dream"]
|
540 |
if "story" in user_input_lower:
|
541 |
conversation_context["last_topic"] = "story"
|
542 |
conversation_context["last_response"] = None
|
|
|
543 |
return krishna_blessings["story"]
|
544 |
if "surprise" in user_input_lower:
|
545 |
conversation_context["last_topic"] = "surprise"
|
546 |
conversation_context["last_response"] = None
|
|
|
547 |
return krishna_blessings["surprise"]
|
548 |
if "celebrate" in user_input_lower:
|
549 |
conversation_context["last_topic"] = "celebrate"
|
550 |
conversation_context["last_response"] = None
|
|
|
551 |
return krishna_blessings["celebrate"]
|
552 |
if "blessing" in user_input_lower:
|
553 |
conversation_context["last_topic"] = "blessing"
|
554 |
conversation_context["last_response"] = None
|
|
|
555 |
return krishna_blessings["blessing"]
|
556 |
|
557 |
if conversation_context["last_topic"]:
|
558 |
last_topic = conversation_context["last_topic"]
|
559 |
if last_topic in krishna_blessings:
|
560 |
conversation_context["last_response"] = None
|
|
|
561 |
return krishna_blessings[last_topic] + " What else would you like to talk about, Manavi?"
|
562 |
|
563 |
# Sentiment-based responses (only as a fallback, and avoid repetition)
|
564 |
if sentiment == "negative" and "sad" not in user_input_lower and conversation_context["last_response"] != "Hare Manavi! I see a little cloud over your heart—let’s dance by the Yamuna to bring back your smile!":
|
565 |
response = "Hare Manavi! I see a little cloud over your heart—let’s dance by the Yamuna to bring back your smile!"
|
566 |
conversation_context["last_response"] = response
|
|
|
567 |
return response
|
568 |
if sentiment == "positive" and conversation_context["last_response"] != "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?":
|
569 |
response = "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?"
|
570 |
conversation_context["last_response"] = response
|
|
|
571 |
return response
|
572 |
|
573 |
# Fallback to multiple open-source AI models if no keywords match
|
574 |
-
# Shuffle the models to try them in random order
|
575 |
models_to_try = AI_MODELS.copy()
|
576 |
random.shuffle(models_to_try)
|
577 |
|
@@ -582,14 +710,11 @@ def get_krishna_response(user_input):
|
|
582 |
|
583 |
for model in models_to_try:
|
584 |
try:
|
585 |
-
# Special case for Grok by xAI (simulated directly)
|
586 |
if model["name"] == "Grok by xAI":
|
587 |
-
# Simulate Grok's response (I, Grok, will generate the response directly)
|
588 |
response = (
|
589 |
f"Hare Manavi! I’m Little Krishna, speaking through Grok by xAI. "
|
590 |
f"Let me answer in my playful way: "
|
591 |
)
|
592 |
-
# Generate a Krishna-like response based on the input
|
593 |
if "color" in user_input_lower:
|
594 |
response += "I love the golden yellow of Vrindavan’s butter—it’s as sweet as your smile! What’s your favorite color?"
|
595 |
elif "weather" in user_input_lower:
|
@@ -599,9 +724,9 @@ def get_krishna_response(user_input):
|
|
599 |
else:
|
600 |
response += f"I’m twirling my flute just for you! Shall we share a Vrindavan adventure today?"
|
601 |
conversation_context["last_response"] = None
|
|
|
602 |
return response
|
603 |
|
604 |
-
# For other models, use the Hugging Face Inference API
|
605 |
payload = {
|
606 |
"inputs": f"{SYSTEM_PROMPT} '{user_input}'",
|
607 |
"parameters": model["parameters"]
|
@@ -613,7 +738,6 @@ def get_krishna_response(user_input):
|
|
613 |
)
|
614 |
if response.status_code == 200:
|
615 |
result = response.json()
|
616 |
-
# Handle different response formats based on the model
|
617 |
if isinstance(result, list) and len(result) > 0 and "generated_text" in result[0]:
|
618 |
response_text = result[0]["generated_text"].strip()
|
619 |
elif isinstance(result, dict) and "generated_text" in result:
|
@@ -624,6 +748,7 @@ def get_krishna_response(user_input):
|
|
624 |
print(f"Unexpected response format from {model['name']}: {result}")
|
625 |
continue
|
626 |
conversation_context["last_response"] = None
|
|
|
627 |
return response_text
|
628 |
else:
|
629 |
print(f"Error with {model['name']}: {response.text}")
|
@@ -632,6 +757,6 @@ def get_krishna_response(user_input):
|
|
632 |
print(f"Error connecting to {model['name']}: {str(e)}")
|
633 |
continue
|
634 |
|
635 |
-
# If all models fail, return a default message
|
636 |
conversation_context["last_response"] = None
|
|
|
637 |
return "Hare Manavi! I seem to be lost in Vrindavan’s magic—let’s try a different tune!"
|
|
|
118 |
conversation_context = {
|
119 |
"last_topic": None, # Store the last keyword matched (e.g., "birthday", "riddle")
|
120 |
"message_count": 0, # Track the number of messages to trigger Ayush-teasing every 5th message
|
121 |
+
"last_response": None, # Track the last response to avoid repetition and enable follow-ups
|
122 |
+
"last_activity": None # Track ongoing activities (e.g., "dancing", "exploring")
|
123 |
}
|
124 |
|
125 |
+
# List of generic positive responses to cycle through for affirmations when no activity is in progress
|
126 |
+
GENERIC_POSITIVE_RESPONSES = [
|
127 |
+
"Hare Manavi! Wonderful—let’s make today as magical as Vrindavan’s sunsets!",
|
128 |
+
"Hare Manavi! Great—shall we chase the butterflies by the Yamuna next?",
|
129 |
+
"Hare Manavi! Perfect—let’s share some butter under the kadamba tree!",
|
130 |
+
"Hare Manavi! Lovely—how about a little dance with the gopis now?",
|
131 |
+
"Hare Manavi! Splendid—let’s listen to the birds sing by the river!"
|
132 |
+
]
|
133 |
+
|
134 |
def analyze_sentiment(user_input):
|
135 |
"""Analyze the sentiment of the user's input using a sentiment analysis model."""
|
136 |
headers = {
|
|
|
179 |
conversation_context["last_topic"] = None
|
180 |
conversation_context["message_count"] = 0
|
181 |
conversation_context["last_response"] = None
|
182 |
+
conversation_context["last_activity"] = None
|
183 |
return "Hare Manavi! Let’s start a new adventure in Vrindavan—what would you like to talk about?"
|
184 |
|
185 |
# Check for follow-up responses based on context
|
186 |
if conversation_context["last_response"] == "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?":
|
187 |
if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
|
188 |
+
conversation_context["last_response"] = None
|
189 |
+
conversation_context["last_activity"] = "dancing"
|
190 |
return "Hare Manavi! Let’s play a flute melody by the Yamuna—the peacocks will dance with us!"
|
191 |
|
192 |
+
# Handle ongoing activities
|
193 |
+
if conversation_context["last_activity"]:
|
194 |
+
if conversation_context["last_activity"] == "dancing":
|
195 |
+
if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
|
196 |
+
conversation_context["last_response"] = None
|
197 |
+
conversation_context["last_activity"] = "dancing"
|
198 |
+
return "Hare Manavi! The gopis have joined us—let’s twirl under the moonlight by the Yamuna!"
|
199 |
+
if "how" in user_input_lower or "but how" in user_input_lower:
|
200 |
+
conversation_context["last_response"] = None
|
201 |
+
return "Hare Manavi! We’ll sway to my flute’s tune, letting the rhythm guide our steps—what a joyful dance it’ll be!"
|
202 |
+
elif conversation_context["last_activity"] == "exploring":
|
203 |
+
if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
|
204 |
+
conversation_context["last_response"] = None
|
205 |
+
return "Hare Manavi! We found a pot of creamy butter—let’s share it under the stars by the Yamuna!"
|
206 |
+
if "how" in user_input_lower or "but how" in user_input_lower:
|
207 |
+
conversation_context["last_response"] = None
|
208 |
+
return "Hare Manavi! We’ll tiptoe through the trees, listening for the gopis’ laughter to guide us to their hidden butter pots!"
|
209 |
+
|
210 |
+
# Check for exploration triggers
|
211 |
+
if "explore" in user_input_lower or "adventure" in user_input_lower:
|
212 |
+
conversation_context["last_topic"] = "adventure"
|
213 |
+
conversation_context["last_response"] = None
|
214 |
+
conversation_context["last_activity"] = "exploring"
|
215 |
+
return "Hare Manavi! Let’s sneak through Vrindavan’s forests to find hidden butter pots—what a mischievous delight!"
|
216 |
+
|
217 |
# Check for Ayush-teasing triggers (keyword-based)
|
218 |
if "joke" in user_input_lower:
|
219 |
conversation_context["last_topic"] = "joke"
|
220 |
conversation_context["last_response"] = None
|
221 |
+
conversation_context["last_activity"] = None
|
222 |
if random.choice([True, False]):
|
223 |
return random.choice(ayush_teasing["joke"])
|
224 |
return krishna_blessings["joke"]
|
225 |
if "i miss" in user_input_lower or "missing" in user_input_lower:
|
226 |
conversation_context["last_topic"] = "missing"
|
227 |
conversation_context["last_response"] = None
|
228 |
+
conversation_context["last_activity"] = None
|
229 |
return random.choice(ayush_teasing["missing"])
|
230 |
if "bored" in user_input_lower:
|
231 |
conversation_context["last_topic"] = "bored"
|
232 |
conversation_context["last_response"] = None
|
233 |
+
conversation_context["last_activity"] = None
|
234 |
return random.choice(ayush_teasing["bored"])
|
235 |
if "tired" in user_input_lower:
|
236 |
conversation_context["last_topic"] = "tired"
|
237 |
conversation_context["last_response"] = None
|
238 |
+
conversation_context["last_activity"] = None
|
239 |
return random.choice(ayush_teasing["tired"])
|
240 |
if "lonely" in user_input_lower:
|
241 |
conversation_context["last_topic"] = "lonely"
|
242 |
conversation_context["last_response"] = None
|
243 |
+
conversation_context["last_activity"] = None
|
244 |
return random.choice(ayush_teasing["lonely"])
|
245 |
if "manavi" in user_input_lower:
|
246 |
conversation_context["last_topic"] = "manavi"
|
247 |
conversation_context["last_response"] = None
|
248 |
+
conversation_context["last_activity"] = None
|
249 |
return random.choice(ayush_teasing["manavi"])
|
250 |
if "ayush" in user_input_lower or "krishna talk about ayush" in user_input_lower:
|
251 |
conversation_context["last_topic"] = "ayush"
|
252 |
conversation_context["last_response"] = None
|
253 |
+
conversation_context["last_activity"] = None
|
254 |
return random.choice(ayush_teasing["ayush"])
|
255 |
|
256 |
# Trigger for "chat with you"
|
257 |
if "chat with you" in user_input_lower or "want to chat" in user_input_lower:
|
258 |
conversation_context["last_topic"] = "chat_with_you"
|
259 |
conversation_context["last_response"] = None
|
260 |
+
conversation_context["last_activity"] = None
|
261 |
return krishna_blessings["chat_with_you"]
|
262 |
|
263 |
# Every 5th message, randomly trigger an Ayush-teasing message (if no keyword match)
|
264 |
if conversation_context["message_count"] % 5 == 0:
|
|
|
265 |
category = random.choice(list(ayush_teasing.keys()))
|
266 |
conversation_context["last_response"] = None
|
267 |
+
conversation_context["last_activity"] = None
|
268 |
return random.choice(ayush_teasing[category])
|
269 |
|
270 |
# Existing keyword mappings for krishna_blessings and ayush_surprises
|
271 |
if "hello" in user_input_lower or "hi" in user_input_lower or "hii" in user_input_lower:
|
272 |
conversation_context["last_topic"] = "greeting"
|
273 |
conversation_context["last_response"] = None
|
274 |
+
conversation_context["last_activity"] = None
|
275 |
return krishna_blessings["greeting"]
|
276 |
if "good morning" in user_input_lower:
|
277 |
conversation_context["last_topic"] = "greeting"
|
278 |
conversation_context["last_response"] = None
|
279 |
+
conversation_context["last_activity"] = None
|
280 |
return krishna_blessings["good_morning"]
|
281 |
if "good afternoon" in user_input_lower:
|
282 |
conversation_context["last_topic"] = "greeting"
|
283 |
conversation_context["last_response"] = None
|
284 |
+
conversation_context["last_activity"] = None
|
285 |
return krishna_blessings["good_afternoon"]
|
286 |
if "good evening" in user_input_lower:
|
287 |
conversation_context["last_topic"] = "greeting"
|
288 |
conversation_context["last_response"] = None
|
289 |
+
conversation_context["last_activity"] = None
|
290 |
return krishna_blessings["good_evening"]
|
291 |
if "hey" in user_input_lower:
|
292 |
conversation_context["last_topic"] = "greeting"
|
293 |
conversation_context["last_response"] = None
|
294 |
+
conversation_context["last_activity"] = None
|
295 |
return krishna_blessings["hey"]
|
296 |
if "howdy" in user_input_lower:
|
297 |
conversation_context["last_topic"] = "greeting"
|
298 |
conversation_context["last_response"] = None
|
299 |
+
conversation_context["last_activity"] = None
|
300 |
return krishna_blessings["howdy"]
|
301 |
if "namaste" in user_input_lower:
|
302 |
conversation_context["last_topic"] = "greeting"
|
303 |
conversation_context["last_response"] = None
|
304 |
+
conversation_context["last_activity"] = None
|
305 |
return krishna_blessings["namaste"]
|
306 |
if "welcome" in user_input_lower:
|
307 |
conversation_context["last_topic"] = "greeting"
|
308 |
conversation_context["last_response"] = None
|
309 |
+
conversation_context["last_activity"] = None
|
310 |
return krishna_blessings["welcome"]
|
311 |
|
312 |
if "who are you" in user_input_lower or "what are you" in user_input_lower or "tell me about yourself" in user_input_lower or "what are you doing" in user_input_lower:
|
313 |
conversation_context["last_topic"] = "identity"
|
314 |
conversation_context["last_response"] = None
|
315 |
+
conversation_context["last_activity"] = None
|
316 |
return "Hare Manavi! I’m Little Krishna, the playful cowherd of Vrindavan! I love playing my flute, stealing butter, and dancing with the gopis. What would you like to do with me today?"
|
317 |
|
318 |
if "how are you" in user_input_lower:
|
319 |
conversation_context["last_topic"] = "how_are_you"
|
320 |
conversation_context["last_response"] = None
|
321 |
+
conversation_context["last_activity"] = None
|
322 |
return "Hare Manavi! I’m as joyful as a peacock dancing in Vrindavan—how about you, my friend?"
|
323 |
|
324 |
if "yes" in user_input_lower or "okay" in user_input_lower or "sure" in user_input_lower:
|
|
|
325 |
conversation_context["last_topic"] = "yes"
|
326 |
conversation_context["last_response"] = None
|
327 |
+
# Cycle through generic positive responses if no activity is in progress
|
328 |
+
if not conversation_context["last_activity"]:
|
329 |
+
response = random.choice(GENERIC_POSITIVE_RESPONSES)
|
330 |
+
# Rotate the list to avoid repetition
|
331 |
+
GENERIC_POSITIVE_RESPONSES.append(GENERIC_POSITIVE_RESPONSES.pop(0))
|
332 |
+
return response
|
333 |
|
334 |
if "play" in user_input_lower or "fun" in user_input_lower:
|
335 |
conversation_context["last_topic"] = "playful"
|
336 |
conversation_context["last_response"] = None
|
337 |
+
conversation_context["last_activity"] = None
|
338 |
return krishna_blessings["playful"]
|
339 |
if "dance" in user_input_lower:
|
340 |
conversation_context["last_topic"] = "dance"
|
341 |
conversation_context["last_response"] = None
|
342 |
+
conversation_context["last_activity"] = "dancing"
|
343 |
return krishna_blessings["dance"]
|
344 |
if "flute" in user_input_lower:
|
345 |
conversation_context["last_topic"] = "flute"
|
346 |
conversation_context["last_response"] = None
|
347 |
+
conversation_context["last_activity"] = None
|
348 |
return krishna_blessings["flute"]
|
349 |
if "butter" in user_input_lower:
|
350 |
conversation_context["last_topic"] = "butter"
|
351 |
conversation_context["last_response"] = None
|
352 |
+
conversation_context["last_activity"] = None
|
353 |
return krishna_blessings["butter"]
|
354 |
if "mischief" in user_input_lower or "prank" in user_input_lower:
|
355 |
conversation_context["last_topic"] = "mischief"
|
356 |
conversation_context["last_response"] = None
|
357 |
+
conversation_context["last_activity"] = None
|
358 |
return krishna_blessings["mischief"]
|
359 |
if "chase" in user_input_lower or "run" in user_input_lower:
|
360 |
conversation_context["last_topic"] = "chase"
|
361 |
conversation_context["last_response"] = None
|
362 |
+
conversation_context["last_activity"] = None
|
363 |
return krishna_blessings["chase"]
|
364 |
if "giggle" in user_input_lower:
|
365 |
conversation_context["last_topic"] = "giggle"
|
366 |
conversation_context["last_response"] = None
|
367 |
+
conversation_context["last_activity"] = None
|
368 |
return krishna_blessings["giggle"]
|
369 |
if "swing" in user_input_lower:
|
370 |
conversation_context["last_topic"] = "swing"
|
371 |
conversation_context["last_response"] = None
|
372 |
+
conversation_context["last_activity"] = None
|
373 |
return krishna_blessings["swing"]
|
374 |
|
375 |
if "shy" in user_input_lower:
|
376 |
conversation_context["last_topic"] = "shy"
|
377 |
conversation_context["last_response"] = None
|
378 |
+
conversation_context["last_activity"] = None
|
379 |
return krishna_blessings["shy"]
|
380 |
if "quiet" in user_input_lower or "calm" in user_input_lower:
|
381 |
conversation_context["last_topic"] = "quiet"
|
382 |
conversation_context["last_response"] = None
|
383 |
+
conversation_context["last_activity"] = None
|
384 |
return krishna_blessings["quiet"]
|
385 |
if "peace" in user_input_lower or "serene" in user_input_lower:
|
386 |
conversation_context["last_topic"] = "peace"
|
387 |
conversation_context["last_response"] = None
|
388 |
+
conversation_context["last_activity"] = None
|
389 |
return krishna_blessings["peace"]
|
390 |
if "still" in user_input_lower or "gentle" in user_input_lower:
|
391 |
conversation_context["last_topic"] = "still"
|
392 |
conversation_context["last_response"] = None
|
393 |
+
conversation_context["last_activity"] = None
|
394 |
return krishna_blessings["still"]
|
395 |
if "thoughtful" in user_input_lower or "reflect" in user_input_lower:
|
396 |
conversation_context["last_topic"] = "thoughtful"
|
397 |
conversation_context["last_response"] = None
|
398 |
+
conversation_context["last_activity"] = None
|
399 |
return krishna_blessings["thoughtful"]
|
400 |
|
401 |
if "funny" in user_input_lower:
|
402 |
conversation_context["last_topic"] = "joke"
|
403 |
conversation_context["last_response"] = None
|
404 |
+
conversation_context["last_activity"] = None
|
405 |
return krishna_blessings["funny"]
|
406 |
if "laugh" in user_input_lower or "giggle" in user_input_lower:
|
407 |
conversation_context["last_topic"] = "joke"
|
408 |
conversation_context["last_response"] = None
|
409 |
+
conversation_context["last_activity"] = None
|
410 |
return krishna_blessings["giggle_joke"]
|
411 |
if "silly" in user_input_lower:
|
412 |
conversation_context["last_topic"] = "joke"
|
413 |
conversation_context["last_response"] = None
|
414 |
+
conversation_context["last_activity"] = None
|
415 |
return krishna_blessings["silly"]
|
416 |
if "butter joke" in user_input_lower:
|
417 |
conversation_context["last_topic"] = "joke"
|
418 |
conversation_context["last_response"] = None
|
419 |
+
conversation_context["last_activity"] = None
|
420 |
return krishna_blessings["butter_joke"]
|
421 |
if "cow joke" in user_input_lower:
|
422 |
conversation_context["last_topic"] = "joke"
|
423 |
conversation_context["last_response"] = None
|
424 |
+
conversation_context["last_activity"] = None
|
425 |
return krishna_blessings["cow_joke"]
|
426 |
if "flute joke" in user_input_lower:
|
427 |
conversation_context["last_topic"] = "joke"
|
428 |
conversation_context["last_response"] = None
|
429 |
+
conversation_context["last_activity"] = None
|
430 |
return krishna_blessings["flute_joke"]
|
431 |
if "dance joke" in user_input_lower:
|
432 |
conversation_context["last_topic"] = "joke"
|
433 |
conversation_context["last_response"] = None
|
434 |
+
conversation_context["last_activity"] = None
|
435 |
return krishna_blessings["dance_joke"]
|
436 |
if "mischief joke" in user_input_lower:
|
437 |
conversation_context["last_topic"] = "joke"
|
438 |
conversation_context["last_response"] = None
|
439 |
+
conversation_context["last_activity"] = None
|
440 |
return krishna_blessings["mischief_joke"]
|
441 |
|
442 |
if "riddle" in user_input_lower or "puzzle" in user_input_lower:
|
443 |
conversation_context["last_topic"] = "riddle"
|
444 |
conversation_context["last_response"] = None
|
445 |
+
conversation_context["last_activity"] = None
|
446 |
return krishna_blessings["riddle"]
|
447 |
if "mystery" in user_input_lower or "enigma" in user_input_lower:
|
448 |
conversation_context["last_topic"] = "riddle"
|
449 |
conversation_context["last_response"] = None
|
450 |
+
conversation_context["last_activity"] = None
|
451 |
return krishna_blessings["mystery"]
|
452 |
if "question" in user_input_lower:
|
453 |
conversation_context["last_topic"] = "riddle"
|
454 |
conversation_context["last_response"] = None
|
455 |
+
conversation_context["last_activity"] = None
|
456 |
return krishna_blessings["question"]
|
457 |
|
458 |
if "birthday" in user_input_lower:
|
459 |
conversation_context["last_topic"] = "birthday"
|
460 |
conversation_context["last_response"] = None
|
461 |
+
conversation_context["last_activity"] = None
|
462 |
return ayush_surprises["birthday"]
|
463 |
if "happy birthday" in user_input_lower:
|
464 |
conversation_context["last_topic"] = "birthday"
|
465 |
conversation_context["last_response"] = None
|
466 |
+
conversation_context["last_activity"] = None
|
467 |
return krishna_blessings["happy_birthday"]
|
468 |
if "birthday wish" in user_input_lower:
|
469 |
conversation_context["last_topic"] = "birthday"
|
470 |
conversation_context["last_response"] = None
|
471 |
+
conversation_context["last_activity"] = None
|
472 |
return krishna_blessings["birthday_wish"]
|
473 |
if "birthday blessing" in user_input_lower:
|
474 |
conversation_context["last_topic"] = "birthday"
|
475 |
conversation_context["last_response"] = None
|
476 |
+
conversation_context["last_activity"] = None
|
477 |
return krishna_blessings["birthday_blessing"]
|
478 |
if "birthday dance" in user_input_lower:
|
479 |
conversation_context["last_topic"] = "birthday"
|
480 |
conversation_context["last_response"] = None
|
481 |
+
conversation_context["last_activity"] = "dancing"
|
482 |
return krishna_blessings["birthday_dance"]
|
483 |
if "birthday song" in user_input_lower:
|
484 |
conversation_context["last_topic"] = "birthday"
|
485 |
conversation_context["last_response"] = None
|
486 |
+
conversation_context["last_activity"] = None
|
487 |
return krishna_blessings["birthday_song"]
|
488 |
if "birthday gift" in user_input_lower:
|
489 |
conversation_context["last_topic"] = "birthday"
|
490 |
conversation_context["last_response"] = None
|
491 |
+
conversation_context["last_activity"] = None
|
492 |
return krishna_blessings["birthday_gift"]
|
493 |
if "birthday smile" in user_input_lower:
|
494 |
conversation_context["last_topic"] = "birthday"
|
495 |
conversation_context["last_response"] = None
|
496 |
+
conversation_context["last_activity"] = None
|
497 |
return krishna_blessings["birthday_smile"]
|
498 |
if "birthday love" in user_input_lower:
|
499 |
conversation_context["last_topic"] = "birthday"
|
500 |
conversation_context["last_response"] = None
|
501 |
+
conversation_context["last_activity"] = None
|
502 |
return krishna_blessings["birthday_love"]
|
503 |
if "birthday magic" in user_input_lower:
|
504 |
conversation_context["last_topic"] = "birthday"
|
505 |
conversation_context["last_response"] = None
|
506 |
+
conversation_context["last_activity"] = None
|
507 |
return krishna_blessings["birthday_magic"]
|
508 |
|
509 |
if "wisdom" in user_input_lower or "advice" in user_input_lower:
|
510 |
conversation_context["last_topic"] = "wisdom"
|
511 |
conversation_context["last_response"] = None
|
512 |
+
conversation_context["last_activity"] = None
|
513 |
return krishna_blessings["wisdom"]
|
514 |
if "lesson" in user_input_lower or "truth" in user_input_lower:
|
515 |
conversation_context["last_topic"] = "wisdom"
|
516 |
conversation_context["last_response"] = None
|
517 |
+
conversation_context["last_activity"] = None
|
518 |
return krishna_blessings["lesson"]
|
519 |
if "kindness" in user_input_lower:
|
520 |
conversation_context["last_topic"] = "wisdom"
|
521 |
conversation_context["last_response"] = None
|
522 |
+
conversation_context["last_activity"] = None
|
523 |
return krishna_blessings["kindness"]
|
524 |
if "patience" in user_input_lower:
|
525 |
conversation_context["last_topic"] = "wisdom"
|
526 |
conversation_context["last_response"] = None
|
527 |
+
conversation_context["last_activity"] = None
|
528 |
return krishna_blessings["patience"]
|
529 |
if "courage" in user_input_lower:
|
530 |
conversation_context["last_topic"] = "wisdom"
|
531 |
conversation_context["last_response"] = None
|
532 |
+
conversation_context["last_activity"] = None
|
533 |
return krishna_blessings["courage"]
|
534 |
if "joy" in user_input_lower:
|
535 |
conversation_context["last_topic"] = "wisdom"
|
536 |
conversation_context["last_response"] = None
|
537 |
+
conversation_context["last_activity"] = None
|
538 |
return krishna_blessings["joy"]
|
539 |
if "friendship" in user_input_lower:
|
540 |
conversation_context["last_topic"] = "wisdom"
|
541 |
conversation_context["last_response"] = None
|
542 |
+
conversation_context["last_activity"] = None
|
543 |
return krishna_blessings["friendship"]
|
544 |
if "love" in user_input_lower:
|
545 |
conversation_context["last_topic"] = "wisdom"
|
546 |
conversation_context["last_response"] = None
|
547 |
+
conversation_context["last_activity"] = None
|
548 |
return krishna_blessings["love"]
|
549 |
|
550 |
if "nature" in user_input_lower or "vrindavan" in user_input_lower:
|
551 |
conversation_context["last_topic"] = "nature"
|
552 |
conversation_context["last_response"] = None
|
553 |
+
conversation_context["last_activity"] = None
|
554 |
return krishna_blessings["nature"]
|
555 |
if "yamuna" in user_input_lower or "river" in user_input_lower:
|
556 |
conversation_context["last_topic"] = "nature"
|
557 |
conversation_context["last_response"] = None
|
558 |
+
conversation_context["last_activity"] = None
|
559 |
return krishna_blessings["yamuna"]
|
560 |
if "peacock" in user_input_lower:
|
561 |
conversation_context["last_topic"] = "nature"
|
562 |
conversation_context["last_response"] = None
|
563 |
+
conversation_context["last_activity"] = None
|
564 |
return krishna_blessings["peacock"]
|
565 |
if "cow" in user_input_lower:
|
566 |
conversation_context["last_topic"] = "nature"
|
567 |
conversation_context["last_response"] = None
|
568 |
+
conversation_context["last_activity"] = None
|
569 |
return krishna_blessings["cow"]
|
570 |
if "flower" in user_input_lower:
|
571 |
conversation_context["last_topic"] = "nature"
|
572 |
conversation_context["last_response"] = None
|
573 |
+
conversation_context["last_activity"] = None
|
574 |
return krishna_blessings["flower"]
|
575 |
if "tree" in user_input_lower:
|
576 |
conversation_context["last_topic"] = "nature"
|
577 |
conversation_context["last_response"] = None
|
578 |
+
conversation_context["last_activity"] = None
|
579 |
return krishna_blessings["tree"]
|
580 |
if "forest" in user_input_lower:
|
581 |
conversation_context["last_topic"] = "nature"
|
582 |
conversation_context["last_response"] = None
|
583 |
+
conversation_context["last_activity"] = "exploring"
|
584 |
return krishna_blessings["forest"]
|
585 |
if "bird" in user_input_lower:
|
586 |
conversation_context["last_topic"] = "nature"
|
587 |
conversation_context["last_response"] = None
|
588 |
+
conversation_context["last_activity"] = None
|
589 |
return krishna_blessings["bird"]
|
590 |
if "sunset" in user_input_lower:
|
591 |
conversation_context["last_topic"] = "nature"
|
592 |
conversation_context["last_response"] = None
|
593 |
+
conversation_context["last_activity"] = None
|
594 |
return krishna_blessings["sunset"]
|
595 |
|
596 |
if "encourage" in user_input_lower or "cheer" in user_input_lower:
|
597 |
conversation_context["last_topic"] = "encourage"
|
598 |
conversation_context["last_response"] = None
|
599 |
+
conversation_context["last_activity"] = None
|
600 |
return krishna_blessings["encourage"]
|
601 |
if "support" in user_input_lower or "uplift" in user_input_lower:
|
602 |
conversation_context["last_topic"] = "encourage"
|
603 |
conversation_context["last_response"] = None
|
604 |
+
conversation_context["last_activity"] = None
|
605 |
return krishna_blessings["support"]
|
606 |
if "inspire" in user_input_lower or "motivate" in user_input_lower:
|
607 |
conversation_context["last_topic"] = "encourage"
|
608 |
conversation_context["last_response"] = None
|
609 |
+
conversation_context["last_activity"] = None
|
610 |
return krishna_blessings["inspire"]
|
611 |
if "strength" in user_input_lower:
|
612 |
conversation_context["last_topic"] = "encourage"
|
613 |
conversation_context["last_response"] = None
|
614 |
+
conversation_context["last_activity"] = None
|
615 |
return krishna_blessings["strength"]
|
616 |
if "hope" in user_input_lower:
|
617 |
conversation_context["last_topic"] = "encourage"
|
618 |
conversation_context["last_response"] = None
|
619 |
+
conversation_context["last_activity"] = None
|
620 |
return krishna_blessings["hope"]
|
621 |
if "believe" in user_input_lower:
|
622 |
conversation_context["last_topic"] = "encourage"
|
623 |
conversation_context["last_response"] = None
|
624 |
+
conversation_context["last_activity"] = None
|
625 |
return krishna_blessings["believe"]
|
626 |
if "shine" in user_input_lower:
|
627 |
conversation_context["last_topic"] = "encourage"
|
628 |
conversation_context["last_response"] = None
|
629 |
+
conversation_context["last_activity"] = None
|
630 |
return krishna_blessings["shine"]
|
631 |
|
632 |
if "friend" in user_input_lower:
|
633 |
conversation_context["last_topic"] = "friend"
|
634 |
conversation_context["last_response"] = None
|
635 |
+
conversation_context["last_activity"] = None
|
636 |
return krishna_blessings["friend"]
|
637 |
if "smile" in user_input_lower:
|
638 |
conversation_context["last_topic"] = "smile"
|
639 |
conversation_context["last_response"] = None
|
640 |
+
conversation_context["last_activity"] = None
|
641 |
return krishna_blessings["smile"]
|
642 |
if "magic" in user_input_lower:
|
643 |
conversation_context["last_topic"] = "magic"
|
644 |
conversation_context["last_response"] = None
|
645 |
+
conversation_context["last_activity"] = None
|
646 |
return krishna_blessings["magic"]
|
647 |
if "adventure" in user_input_lower:
|
648 |
conversation_context["last_topic"] = "adventure"
|
649 |
conversation_context["last_response"] = None
|
650 |
+
conversation_context["last_activity"] = "exploring"
|
651 |
return krishna_blessings["adventure"]
|
652 |
if "song" in user_input_lower:
|
653 |
conversation_context["last_topic"] = "song"
|
654 |
conversation_context["last_response"] = None
|
655 |
+
conversation_context["last_activity"] = None
|
656 |
return krishna_blessings["song"]
|
657 |
if "dream" in user_input_lower:
|
658 |
conversation_context["last_topic"] = "dream"
|
659 |
conversation_context["last_response"] = None
|
660 |
+
conversation_context["last_activity"] = None
|
661 |
return krishna_blessings["dream"]
|
662 |
if "story" in user_input_lower:
|
663 |
conversation_context["last_topic"] = "story"
|
664 |
conversation_context["last_response"] = None
|
665 |
+
conversation_context["last_activity"] = None
|
666 |
return krishna_blessings["story"]
|
667 |
if "surprise" in user_input_lower:
|
668 |
conversation_context["last_topic"] = "surprise"
|
669 |
conversation_context["last_response"] = None
|
670 |
+
conversation_context["last_activity"] = None
|
671 |
return krishna_blessings["surprise"]
|
672 |
if "celebrate" in user_input_lower:
|
673 |
conversation_context["last_topic"] = "celebrate"
|
674 |
conversation_context["last_response"] = None
|
675 |
+
conversation_context["last_activity"] = None
|
676 |
return krishna_blessings["celebrate"]
|
677 |
if "blessing" in user_input_lower:
|
678 |
conversation_context["last_topic"] = "blessing"
|
679 |
conversation_context["last_response"] = None
|
680 |
+
conversation_context["last_activity"] = None
|
681 |
return krishna_blessings["blessing"]
|
682 |
|
683 |
if conversation_context["last_topic"]:
|
684 |
last_topic = conversation_context["last_topic"]
|
685 |
if last_topic in krishna_blessings:
|
686 |
conversation_context["last_response"] = None
|
687 |
+
conversation_context["last_activity"] = None
|
688 |
return krishna_blessings[last_topic] + " What else would you like to talk about, Manavi?"
|
689 |
|
690 |
# Sentiment-based responses (only as a fallback, and avoid repetition)
|
691 |
if sentiment == "negative" and "sad" not in user_input_lower and conversation_context["last_response"] != "Hare Manavi! I see a little cloud over your heart—let’s dance by the Yamuna to bring back your smile!":
|
692 |
response = "Hare Manavi! I see a little cloud over your heart—let’s dance by the Yamuna to bring back your smile!"
|
693 |
conversation_context["last_response"] = response
|
694 |
+
conversation_context["last_activity"] = "dancing"
|
695 |
return response
|
696 |
if sentiment == "positive" and conversation_context["last_response"] != "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?":
|
697 |
response = "Hare Manavi! Your joy lights up Vrindavan—shall we celebrate with a flute melody?"
|
698 |
conversation_context["last_response"] = response
|
699 |
+
conversation_context["last_activity"] = None
|
700 |
return response
|
701 |
|
702 |
# Fallback to multiple open-source AI models if no keywords match
|
|
|
703 |
models_to_try = AI_MODELS.copy()
|
704 |
random.shuffle(models_to_try)
|
705 |
|
|
|
710 |
|
711 |
for model in models_to_try:
|
712 |
try:
|
|
|
713 |
if model["name"] == "Grok by xAI":
|
|
|
714 |
response = (
|
715 |
f"Hare Manavi! I’m Little Krishna, speaking through Grok by xAI. "
|
716 |
f"Let me answer in my playful way: "
|
717 |
)
|
|
|
718 |
if "color" in user_input_lower:
|
719 |
response += "I love the golden yellow of Vrindavan’s butter—it’s as sweet as your smile! What’s your favorite color?"
|
720 |
elif "weather" in user_input_lower:
|
|
|
724 |
else:
|
725 |
response += f"I’m twirling my flute just for you! Shall we share a Vrindavan adventure today?"
|
726 |
conversation_context["last_response"] = None
|
727 |
+
conversation_context["last_activity"] = "exploring" if "adventure" in response else None
|
728 |
return response
|
729 |
|
|
|
730 |
payload = {
|
731 |
"inputs": f"{SYSTEM_PROMPT} '{user_input}'",
|
732 |
"parameters": model["parameters"]
|
|
|
738 |
)
|
739 |
if response.status_code == 200:
|
740 |
result = response.json()
|
|
|
741 |
if isinstance(result, list) and len(result) > 0 and "generated_text" in result[0]:
|
742 |
response_text = result[0]["generated_text"].strip()
|
743 |
elif isinstance(result, dict) and "generated_text" in result:
|
|
|
748 |
print(f"Unexpected response format from {model['name']}: {result}")
|
749 |
continue
|
750 |
conversation_context["last_response"] = None
|
751 |
+
conversation_context["last_activity"] = None
|
752 |
return response_text
|
753 |
else:
|
754 |
print(f"Error with {model['name']}: {response.text}")
|
|
|
757 |
print(f"Error connecting to {model['name']}: {str(e)}")
|
758 |
continue
|
759 |
|
|
|
760 |
conversation_context["last_response"] = None
|
761 |
+
conversation_context["last_activity"] = None
|
762 |
return "Hare Manavi! I seem to be lost in Vrindavan’s magic—let’s try a different tune!"
|