Upload code/agentic_chat.py with huggingface_hub
Browse files168 unmodified lines169170171172173174168 unmodified linescontinueprompt = f"<|user|>\n{message}<|endofturn|>\n<|assistant|>\n"input_ids = tokenizer(prompt, add_special_tokens=False, return_tensors="pt").input_ids.to(device)full_reply_text = ""168 unmodified lines169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200168 unmodified linescontinueprompt = f"<|user|>\n{message}<|endofturn|>\n<|assistant|>\n"# ββ RAG Pre-Search ββββββββββββββββββββββββββββββββββββββββββββββββββββββ# Detect if query needs current/live info. If yes, search BEFORE model# generates so it always has fresh context (bypasses 500M's weak trigger).SEARCH_TRIGGERS = ["today", "current", "latest", "now", "news", "2024", "2025", "2026","who is", "who are", "price", "minister", "president", "prime minister","election", "match", "score", "winner", "recently", "right now","aaj", "abhi", "filhal", "kaun hai",]msg_lower = message.lower()needs_search = any(kw in msg_lower for kw in SEARCH_TRIGGERS)if needs_search:print(f"\n{CYAN}β‘ [Auto-Search Triggered for live query...]{RESET}")pre_result = do_search(message, timeout=12)print(f"{CYAN} Result length: {len(pre_result)} chars{RESET}\n")if pre_result and "No results" not in pre_result and "timed out" not in pre_result:# Inject context directly into the prompt before generationprompt = (f"<|user|>\n{message}<|endofturn|>\n"f"<search_result>\n{pre_result}\n</search_result>\n"f"<|assistant|>\n")# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββinput_ids = tokenizer(prompt, add_special_tokens=False, return_tensors="pt").input_ids.to(device)full_reply_text = ""
code/agentic_chat.py+26