fix
Browse files78 unmodified lines79808182838442 unmodified lines12712812913013113213313413516 unmodified lines15215315415515615715815916078 unmodified linesprint(f"Warning: Failed to fetch Gradio docs from {GRADIO_LLMS_TXT_URL}: {e}")return Nonedef load_cached_gradio_docs() -> str | None:"""Load cached Gradio documentation from file"""try:42 unmodified lineslatest_content = fetch_gradio_docs()if latest_content:_gradio_docs_content = latest_content_gradio_docs_last_fetched = datetime.now()save_gradio_docs_cache(latest_content)update_gradio_system_prompts()print("✅ Gradio documentation updated successfully")return True16 unmodified lineslatest_content = fetch_gradio_docs()if latest_content:_gradio_docs_content = latest_content_gradio_docs_last_fetched = datetime.now()save_gradio_docs_cache(latest_content)print("✅ Gradio documentation updated successfully")else:# Fallback to cached content78 unmodified lines79808182838485868788899091929394959697989910010110210310410510610710810911011142 unmodified lines15415515615715815916016116216316416 unmodified lines18118218318418518618718818919019178 unmodified linesprint(f"Warning: Failed to fetch Gradio docs from {GRADIO_LLMS_TXT_URL}: {e}")return Nonedef filter_problematic_instructions(content: str) -> str:"""Filter out problematic instructions that cause LLM to stop generation prematurely"""if not content:return content# List of problematic phrases that cause early termination when LLM encounters ``` in user codeproblematic_patterns = [r"Output ONLY the code inside a ``` code block, and do not include any explanations or extra text",r"output only the code inside a ```.*?``` code block",r"Always output only the.*?code.*?inside.*?```.*?```.*?block",r"Do NOT add the language name at the top of the code output",r"do not include any explanations or extra text",r"Always output only the.*?code blocks.*?shown above, and do not include any explanations",]# Remove problematic patternsfiltered_content = contentfor pattern in problematic_patterns:# Use case-insensitive matchingfiltered_content = re.sub(pattern, "", filtered_content, flags=re.IGNORECASE | re.DOTALL)# Clean up any double newlines or extra whitespace left by removalsfiltered_content = re.sub(r'\n\s*\n\s*\n', '\n\n', filtered_content)filtered_content = re.sub(r'^\s+', '', filtered_content, flags=re.MULTILINE)return filtered_contentdef load_cached_gradio_docs() -> str | None:"""Load cached Gradio documentation from file"""try:42 unmodified lineslatest_content = fetch_gradio_docs()if latest_content:# Filter out problematic instructions that cause early terminationfiltered_content = filter_problematic_instructions(latest_content)_gradio_docs_content = filtered_content_gradio_docs_last_fetched = datetime.now()save_gradio_docs_cache(filtered_content)update_gradio_system_prompts()print("✅ Gradio documentation updated successfully")return True16 unmodified lineslatest_content = fetch_gradio_docs()if latest_content:# Filter out problematic instructions that cause early terminationfiltered_content = filter_problematic_instructions(latest_content)_gradio_docs_content = filtered_content_gradio_docs_last_fetched = datetime.now()save_gradio_docs_cache(filtered_content)print("✅ Gradio documentation updated successfully")else:# Fallback to cached content
app.py+35-4