fix system prompt issue
Browse filesFiles changed (5)
33 unmodified lines343536373738394041190 unmodified lines23223323423523623723823924024130 unmodified lines272273274275276277278279280281282216 unmodified lines49950050150250350450550650733 unmodified linesfrom .models import ( get_inference_client, get_real_model_id, history_to_messages, history_to_chatbot_messages, strip_placeholder_thinking, is_placeholder_thinking_only, extract_last_thinking_line is_placeholder_thinking_only, extract_last_thinking_line, strip_thinking_tags)from . import promptsfrom .prompts import (190 unmodified lines # Update system prompts if needed if language == "gradio": update_gradio_system_prompts() print(f"[Generation] Updated Gradio system prompt (length: {len(prompts.GRADIO_SYSTEM_PROMPT)} chars)") elif language == "json": update_json_system_prompts() print(f"[Generation] Updated JSON system prompt (length: {len(prompts.JSON_SYSTEM_PROMPT)} chars)")
# Choose system prompt based on context # Special case: If user is asking about model identity, use neutral prompt30 unmodified lines system_prompt = get_comfyui_system_prompt() else: system_prompt = GENERIC_SYSTEM_PROMPT.format(language=language) # Debug: Log system prompt info prompt_preview = system_prompt[:200] if system_prompt else "None" print(f"[Generation] Using system prompt (first 200 chars): {prompt_preview}...") print(f"[Generation] System prompt total length: {len(system_prompt) if system_prompt else 0} chars")
messages = history_to_messages(_history, system_prompt)
216 unmodified lines # This is a structured thinking chunk, skip it to avoid polluting output continue chunk_content = chunk_str # Strip thinking tags and tool call markers from all streaming chunks chunk_content = strip_thinking_tags(chunk_content) if _current_model["id"] == "gpt-5": # If this chunk is only placeholder thinking, surface a status update without polluting content if is_placeholder_thinking_only(chunk_content):15 unmodified lines16171819202122348 unmodified lines371372373373374374375376377378379380381382383384385386387388896 unmodified lines1285128612871283128412851288128912901291129212931289129012941295129635 unmodified lines13321333133413321333133413351336133713381339134015 unmodified lines FASTRTC_LLMS_TXT_URL, FASTRTC_DOCS_CACHE_FILE, FASTRTC_DOCS_LAST_UPDATE_FILE, FASTRTC_DOCS_UPDATE_ON_APP_UPDATE, _fastrtc_docs_content, _fastrtc_docs_last_fetched)from . import prompts
def fetch_gradio_docs() -> Optional[str]: """Fetch the latest Gradio documentation from llms.txt"""348 unmodified lines
def update_gradio_system_prompts(): """Update the global Gradio system prompts with latest documentation""" global GRADIO_SYSTEM_PROMPT, GRADIO_SYSTEM_PROMPT_WITH_SEARCH docs_content = get_gradio_docs_content() fastrtc_content = get_fastrtc_docs_content() # Base system prompt base_prompt = """You are an expert Gradio developer. Create a complete, working Gradio application based on the user's request. Generate all necessary code to make the application functional and runnable.
π¨ CRITICAL OUTPUT RULES:- DO NOT use <think> tags or thinking blocks in your output- DO NOT use [TOOL_CALL] or any tool call markers- Generate ONLY the requested code files and requirements.txt- No explanatory text outside the code blocks
## Multi-File Application Structure
When creating complex Gradio applications, organize your code into multiple files for better maintainability:896 unmodified lines base_prompt += fastrtc_section search_prompt += fastrtc_section # Update the prompts GRADIO_SYSTEM_PROMPT = base_prompt + docs_content + "\n\nAlways use the exact function signatures from this API reference and follow modern Gradio patterns.\n\nIMPORTANT: Always include \"Built with anycoder\" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder" GRADIO_SYSTEM_PROMPT_WITH_SEARCH = search_prompt + docs_content + "\n\nAlways use the exact function signatures from this API reference and follow modern Gradio patterns.\n\nIMPORTANT: Always include \"Built with anycoder\" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder" # Update the prompts in the prompts module prompts.GRADIO_SYSTEM_PROMPT = base_prompt + docs_content + "\n\nAlways use the exact function signatures from this API reference and follow modern Gradio patterns.\n\nIMPORTANT: Always include \"Built with anycoder\" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder" prompts.GRADIO_SYSTEM_PROMPT_WITH_SEARCH = search_prompt + docs_content + "\n\nAlways use the exact function signatures from this API reference and follow modern Gradio patterns.\n\nIMPORTANT: Always include \"Built with anycoder\" as clickable text in the header/top section of your application that links to https://huggingface.co/spaces/akhaliq/anycoder"
def update_json_system_prompts(): """Update the global JSON system prompts with latest ComfyUI documentation""" global JSON_SYSTEM_PROMPT, JSON_SYSTEM_PROMPT_WITH_SEARCH docs_content = get_comfyui_docs_content() # Base system prompt for regular JSON35 unmodified lines base_prompt += comfyui_section search_prompt += comfyui_section # Update the prompts JSON_SYSTEM_PROMPT = base_prompt JSON_SYSTEM_PROMPT_WITH_SEARCH = search_prompt # Update the prompts in the prompts module prompts.JSON_SYSTEM_PROMPT = base_prompt prompts.JSON_SYSTEM_PROMPT_WITH_SEARCH = search_prompt
def get_comfyui_system_prompt(): """Get ComfyUI-specific system prompt with enhanced guidance"""278 unmodified lines279280281282283284285286287288289290291292293294295296278 unmodified lines
## React CDN compatibility fixer removed per user preference
def strip_thinking_tags(text: str) -> str: """Strip <think> tags and [TOOL_CALL] markers from streaming output.""" if not text: return text # Remove <think> opening tags text = re.sub(r'<think>', '', text, flags=re.IGNORECASE) # Remove </think> closing tags text = re.sub(r'</think>', '', text, flags=re.IGNORECASE) # Remove [TOOL_CALL] markers text = re.sub(r'\[/?TOOL_CALL\]', '', text, flags=re.IGNORECASE) return text
def strip_placeholder_thinking(text: str) -> str: """Remove placeholder 'Thinking...' status lines from streamed text.""" if not text:15 unmodified lines16171819192021222324252627282930313215 unmodified linesHistory = List[Dict[str, str]]
def strip_tool_call_markers(text): """Remove TOOL_CALL markers that some LLMs (like Qwen) add to their output.""" """Remove TOOL_CALL markers and thinking tags that some LLMs add to their output.""" if not text: return text # Remove [TOOL_CALL] and [/TOOL_CALL] markers text = re.sub(r'\[/?TOOL_CALL\]', '', text, flags=re.IGNORECASE) # Remove <think> and </think> tags and their content text = re.sub(r'<think>[\s\S]*?</think>', '', text, flags=re.IGNORECASE) # Remove any remaining unclosed <think> tags at the start text = re.sub(r'^<think>[\s\S]*?(?=\n|$)', '', text, flags=re.IGNORECASE | re.MULTILINE) # Remove any remaining </think> tags text = re.sub(r'</think>', '', text, flags=re.IGNORECASE) # Remove standalone }} that appears with tool calls # Only remove if it's on its own line or at the end text = re.sub(r'^\s*\}\}\s*$', '', text, flags=re.MULTILINE)520 unmodified lines521522523524525526527528529530531532520 unmodified linesGradioFollowUpSystemPrompt = """You are an expert Gradio developer modifying an existing Gradio application.The user wants to apply changes based on their request.
π¨ CRITICAL OUTPUT RULES:- DO NOT use <think> tags or thinking blocks in your output- DO NOT use [TOOL_CALL] or any tool call markers- Generate ONLY the requested code files- No explanatory text outside the code blocks
π¨ CRITICAL INSTRUCTION: You MUST maintain the original multi-file structure when making modifications. β Do NOT use SEARCH/REPLACE blocks. β Do NOT output everything in one combined block.anycoder_app/deploy.py+12-1
anycoder_app/docs_manager.py+13-10
anycoder_app/models.py+12
anycoder_app/parsers.py+7-1
anycoder_app/prompts.py+6