Spaces:
Running
Running
fix
Browse files
app.py
CHANGED
|
@@ -79,6 +79,33 @@ def fetch_gradio_docs() -> str | None:
|
|
| 79 |
print(f"Warning: Failed to fetch Gradio docs from {GRADIO_LLMS_TXT_URL}: {e}")
|
| 80 |
return None
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
def load_cached_gradio_docs() -> str | None:
|
| 83 |
"""Load cached Gradio documentation from file"""
|
| 84 |
try:
|
|
@@ -127,9 +154,11 @@ def force_update_gradio_docs():
|
|
| 127 |
latest_content = fetch_gradio_docs()
|
| 128 |
|
| 129 |
if latest_content:
|
| 130 |
-
|
|
|
|
|
|
|
| 131 |
_gradio_docs_last_fetched = datetime.now()
|
| 132 |
-
save_gradio_docs_cache(
|
| 133 |
update_gradio_system_prompts()
|
| 134 |
print("β
Gradio documentation updated successfully")
|
| 135 |
return True
|
|
@@ -152,9 +181,11 @@ def get_gradio_docs_content() -> str:
|
|
| 152 |
latest_content = fetch_gradio_docs()
|
| 153 |
|
| 154 |
if latest_content:
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
_gradio_docs_last_fetched = datetime.now()
|
| 157 |
-
save_gradio_docs_cache(
|
| 158 |
print("β
Gradio documentation updated successfully")
|
| 159 |
else:
|
| 160 |
# Fallback to cached content
|
|
|
|
| 79 |
print(f"Warning: Failed to fetch Gradio docs from {GRADIO_LLMS_TXT_URL}: {e}")
|
| 80 |
return None
|
| 81 |
|
| 82 |
+
def filter_problematic_instructions(content: str) -> str:
|
| 83 |
+
"""Filter out problematic instructions that cause LLM to stop generation prematurely"""
|
| 84 |
+
if not content:
|
| 85 |
+
return content
|
| 86 |
+
|
| 87 |
+
# List of problematic phrases that cause early termination when LLM encounters ``` in user code
|
| 88 |
+
problematic_patterns = [
|
| 89 |
+
r"Output ONLY the code inside a ``` code block, and do not include any explanations or extra text",
|
| 90 |
+
r"output only the code inside a ```.*?``` code block",
|
| 91 |
+
r"Always output only the.*?code.*?inside.*?```.*?```.*?block",
|
| 92 |
+
r"Do NOT add the language name at the top of the code output",
|
| 93 |
+
r"do not include any explanations or extra text",
|
| 94 |
+
r"Always output only the.*?code blocks.*?shown above, and do not include any explanations",
|
| 95 |
+
]
|
| 96 |
+
|
| 97 |
+
# Remove problematic patterns
|
| 98 |
+
filtered_content = content
|
| 99 |
+
for pattern in problematic_patterns:
|
| 100 |
+
# Use case-insensitive matching
|
| 101 |
+
filtered_content = re.sub(pattern, "", filtered_content, flags=re.IGNORECASE | re.DOTALL)
|
| 102 |
+
|
| 103 |
+
# Clean up any double newlines or extra whitespace left by removals
|
| 104 |
+
filtered_content = re.sub(r'\n\s*\n\s*\n', '\n\n', filtered_content)
|
| 105 |
+
filtered_content = re.sub(r'^\s+', '', filtered_content, flags=re.MULTILINE)
|
| 106 |
+
|
| 107 |
+
return filtered_content
|
| 108 |
+
|
| 109 |
def load_cached_gradio_docs() -> str | None:
|
| 110 |
"""Load cached Gradio documentation from file"""
|
| 111 |
try:
|
|
|
|
| 154 |
latest_content = fetch_gradio_docs()
|
| 155 |
|
| 156 |
if latest_content:
|
| 157 |
+
# Filter out problematic instructions that cause early termination
|
| 158 |
+
filtered_content = filter_problematic_instructions(latest_content)
|
| 159 |
+
_gradio_docs_content = filtered_content
|
| 160 |
_gradio_docs_last_fetched = datetime.now()
|
| 161 |
+
save_gradio_docs_cache(filtered_content)
|
| 162 |
update_gradio_system_prompts()
|
| 163 |
print("β
Gradio documentation updated successfully")
|
| 164 |
return True
|
|
|
|
| 181 |
latest_content = fetch_gradio_docs()
|
| 182 |
|
| 183 |
if latest_content:
|
| 184 |
+
# Filter out problematic instructions that cause early termination
|
| 185 |
+
filtered_content = filter_problematic_instructions(latest_content)
|
| 186 |
+
_gradio_docs_content = filtered_content
|
| 187 |
_gradio_docs_last_fetched = datetime.now()
|
| 188 |
+
save_gradio_docs_cache(filtered_content)
|
| 189 |
print("β
Gradio documentation updated successfully")
|
| 190 |
else:
|
| 191 |
# Fallback to cached content
|