Upload code/agentic_chat.py with huggingface_hub
Browse files167 unmodified lines1681691701711721731741751761771781791801811821833 unmodified lines187188189190191192193194195196197198199200201202203204205167 unmodified linesif not message:continueprompt = f"<|user|>\n{message}<|endofturn|>\n<|assistant|>\n[THINK]\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)3 unmodified linespre_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 generation# Inject context AFTER <|assistant|> to match V4 training formatprompt = (f"<|user|>\n{message}<|endofturn|>\n"f"<|assistant|>\n[THINK]\n"f"<search>{message}</search>\n"f"<search_result>\n{pre_result}\n</search_result>\n")# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββinput_ids = tokenizer(prompt, add_special_tokens=False, return_tensors="pt").input_ids.to(device)full_reply_text = "[THINK]\n"print(f"\nπ€ ViuAI:")current_color = RESETsearch_count = 0167 unmodified lines1681691701711721731741751761771781793 unmodified lines183184185186187188189190191192193194195196197198199200201202203204205167 unmodified linesif not message:continue# ββ RAG Pre-Search ββββββββββββββββββββββββββββββββββββββββββββββββββββββ# Detect if query needs current/live info. Only trigger for explicit news/live queries.SEARCH_TRIGGERS = ["latest news", "current news", "today news", "news today", "latest phone","price of", "stock price", "weather today", "score today", "match result","who is the current", "who is the present", "aaj ki khabar", "aaj ka mausam"]msg_lower = message.lower()needs_search = any(kw in msg_lower for kw in SEARCH_TRIGGERS)3 unmodified linespre_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:# Match V5 RAG Training format EXACTLY: <|assistant|>\n<search>query</search>\n<search_result>...prompt = (f"<|user|>\n{message}<|endofturn|>\n"f"<|assistant|>\n"f"<search>{message}</search>\n"f"<search_result>\n{pre_result}\n</search_result>\n")full_reply_text = ""else:prompt = f"<|user|>\n{message}<|endofturn|>\n<|assistant|>\n"full_reply_text = ""else:prompt = f"<|user|>\n{message}<|endofturn|>\n<|assistant|>\n"full_reply_text = ""# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββinput_ids = tokenizer(prompt, add_special_tokens=False, return_tensors="pt").input_ids.to(device)print(f"\nπ€ ViuAI:")current_color = RESETsearch_count = 0
code/agentic_chat.py+13-13