Upload code/agentic_chat.py with huggingface_hub
Browse files35 unmodified lines3637383940414243444546474849505152535455565758596061626364656667105 unmodified lines17317417517617717817938 unmodified lines21821922022122222322435 unmodified linesdef _ddgs_search_sync(query: str) -> str:results = []try:old_stderr = sys.stderrsys.stderr = open(os.devnull, 'w')try:from ddgs import DDGSexcept ImportError:os.system("pip install --upgrade ddgs nest_asyncio -q")from ddgs import DDGStry:import nest_asyncionest_asyncio.apply()except ImportError:passwith DDGS() as ddgs:results = list(ddgs.text(query, max_results=3))sys.stderr.close()sys.stderr = old_stderrexcept Exception:try:sys.stderr.close()sys.stderr = old_stderrexcept: passreturn "No results found. Search service failed."if not results:return "No results found."105 unmodified linesSEARCH_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)38 unmodified linesif input_ids.size(1) > config.context_length:input_ids = input_ids[:, -config.context_length:]max_new = min(1024, config.context_length)triggered_search = False35 unmodified lines36373839404142434445464748105 unmodified lines15415515615715815916016138 unmodified lines20020120220320420520635 unmodified linesdef _ddgs_search_sync(query: str) -> str:results = []try:from duckduckgo_search import DDGSwith DDGS() as ddgs:results = list(ddgs.text(query, max_results=3))except ImportError:return "Search failed: duckduckgo-search package not installed."except Exception as e:return f"Search failed: {e}"if not results:return "No results found."105 unmodified linesSEARCH_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","india news", "news"]msg_lower = message.lower()needs_search = any(kw in msg_lower for kw in SEARCH_TRIGGERS)38 unmodified linesif input_ids.size(1) > config.context_length:input_ids = input_ids[:, -config.context_length:]max_new = min(1024, max(1, config.context_length - input_ids.size(1)))triggered_search = False
code/agentic_chat.py+8-26