fix system prompt issue
Browse filesFiles changed (5)
33 unmodified lines34353637383940190 unmodified lines23123223323423523623723830 unmodified lines269270271272273274216 unmodified lines49149249349449549633 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)from . import promptsfrom .prompts import (190 unmodified lines# Update system prompts if neededif language == "gradio":update_gradio_system_prompts()elif language == "json":update_json_system_prompts()# Choose system prompt based on context# Special case: If user is asking about model identity, use neutral prompt30 unmodified linessystem_prompt = get_comfyui_system_prompt()else:system_prompt = GENERIC_SYSTEM_PROMPT.format(language=language)messages = history_to_messages(_history, system_prompt)216 unmodified lines# This is a structured thinking chunk, skip it to avoid polluting outputcontinuechunk_content = chunk_strif _current_model["id"] == "gpt-5":# If this chunk is only placeholder thinking, surface a status update without polluting contentif is_placeholder_thinking_only(chunk_content):33 unmodified lines3435363738394041190 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,strip_thinking_tags)from . import promptsfrom .prompts import (190 unmodified lines# Update system prompts if neededif 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 linessystem_prompt = get_comfyui_system_prompt()else:system_prompt = GENERIC_SYSTEM_PROMPT.format(language=language)# Debug: Log system prompt infoprompt_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 outputcontinuechunk_content = chunk_str# Strip thinking tags and tool call markers from all streaming chunkschunk_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 contentif is_placeholder_thinking_only(chunk_content):
15 unmodified lines161718192021348 unmodified lines370371372373374375376377378379380381382383896 unmodified lines1280128112821283128412851286128712881289129012911292129335 unmodified lines13291330133113321333133413351336133715 unmodified linesFASTRTC_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)def fetch_gradio_docs() -> Optional[str]:"""Fetch the latest Gradio documentation from llms.txt"""348 unmodified linesdef update_gradio_system_prompts():"""Update the global Gradio system prompts with latest documentation"""global GRADIO_SYSTEM_PROMPT, GRADIO_SYSTEM_PROMPT_WITH_SEARCHdocs_content = get_gradio_docs_content()fastrtc_content = get_fastrtc_docs_content()# Base system promptbase_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.## Multi-File Application StructureWhen creating complex Gradio applications, organize your code into multiple files for better maintainability:896 unmodified linesbase_prompt += fastrtc_sectionsearch_prompt += fastrtc_section# Update the promptsGRADIO_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"def update_json_system_prompts():"""Update the global JSON system prompts with latest ComfyUI documentation"""global JSON_SYSTEM_PROMPT, JSON_SYSTEM_PROMPT_WITH_SEARCHdocs_content = get_comfyui_docs_content()# Base system prompt for regular JSON35 unmodified linesbase_prompt += comfyui_sectionsearch_prompt += comfyui_section# Update the promptsJSON_SYSTEM_PROMPT = base_promptJSON_SYSTEM_PROMPT_WITH_SEARCH = search_promptdef get_comfyui_system_prompt():"""Get ComfyUI-specific system prompt with enhanced guidance"""15 unmodified lines16171819202122348 unmodified lines371372373374375376377378379380381382383384385386387388896 unmodified lines12851286128712881289129012911292129312941295129635 unmodified lines13321333133413351336133713381339134015 unmodified linesFASTRTC_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 promptsdef fetch_gradio_docs() -> Optional[str]:"""Fetch the latest Gradio documentation from llms.txt"""348 unmodified linesdef update_gradio_system_prompts():"""Update the global Gradio system prompts with latest documentation"""docs_content = get_gradio_docs_content()fastrtc_content = get_fastrtc_docs_content()# Base system promptbase_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 StructureWhen creating complex Gradio applications, organize your code into multiple files for better maintainability:896 unmodified linesbase_prompt += fastrtc_sectionsearch_prompt += fastrtc_section# Update the prompts in the prompts moduleprompts.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"""docs_content = get_comfyui_docs_content()# Base system prompt for regular JSON35 unmodified linesbase_prompt += comfyui_sectionsearch_prompt += comfyui_section# Update the prompts in the prompts moduleprompts.JSON_SYSTEM_PROMPT = base_promptprompts.JSON_SYSTEM_PROMPT_WITH_SEARCH = search_promptdef get_comfyui_system_prompt():"""Get ComfyUI-specific system prompt with enhanced guidance"""
278 unmodified lines279280281282283284278 unmodified lines## React CDN compatibility fixer removed per user preferencedef strip_placeholder_thinking(text: str) -> str:"""Remove placeholder 'Thinking...' status lines from streamed text."""if not text:278 unmodified lines279280281282283284285286287288289290291292293294295296278 unmodified lines## React CDN compatibility fixer removed per user preferencedef strip_thinking_tags(text: str) -> str:"""Strip <think> tags and [TOOL_CALL] markers from streaming output."""if not text:return text# Remove <think> opening tagstext = re.sub(r'<think>', '', text, flags=re.IGNORECASE)# Remove </think> closing tagstext = re.sub(r'</think>', '', text, flags=re.IGNORECASE)# Remove [TOOL_CALL] markerstext = re.sub(r'\[/?TOOL_CALL\]', '', text, flags=re.IGNORECASE)return textdef strip_placeholder_thinking(text: str) -> str:"""Remove placeholder 'Thinking...' status lines from streamed text."""if not text:
15 unmodified lines161718192021222324252615 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."""if not text:return text# Remove [TOOL_CALL] and [/TOOL_CALL] markerstext = re.sub(r'\[/?TOOL_CALL\]', '', text, flags=re.IGNORECASE)# Remove standalone }} that appears with tool calls# Only remove if it's on its own line or at the endtext = re.sub(r'^\s*\}\}\s*$', '', text, flags=re.MULTILINE)15 unmodified lines161718192021222324252627282930313215 unmodified linesHistory = List[Dict[str, str]]def strip_tool_call_markers(text):"""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] markerstext = re.sub(r'\[/?TOOL_CALL\]', '', text, flags=re.IGNORECASE)# Remove <think> and </think> tags and their contenttext = re.sub(r'<think>[\s\S]*?</think>', '', text, flags=re.IGNORECASE)# Remove any remaining unclosed <think> tags at the starttext = re.sub(r'^<think>[\s\S]*?(?=\n|$)', '', text, flags=re.IGNORECASE | re.MULTILINE)# Remove any remaining </think> tagstext = 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 endtext = re.sub(r'^\s*\}\}\s*$', '', text, flags=re.MULTILINE)
520 unmodified lines521522523524525526520 unmodified linesGradioFollowUpSystemPrompt = """You are an expert Gradio developer modifying an existing Gradio application.The user wants to apply changes based on their request.π¨ 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.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