akhaliq HF Staff commited on
Commit
e13574c
Β·
1 Parent(s): 9de4a40

Use full system prompts with Gradio dependencies

Browse files

Now that Gradio dependencies are installed in requirements.txt,
we can directly import and use the full expert-level prompts from
anycoder_app without fallbacks.

Changes:
- Remove all try/except fallback logic
- Directly import prompts from anycoder_app.prompts
- Initialize Gradio and ComfyUI prompts with update_gradio_system_prompts()
- Load full API documentation into prompts at startup
- Clean, simple imports with detailed startup logging

The backend now uses the complete, expert-level system prompts:
βœ… HTML_SYSTEM_PROMPT - Full HTML/CSS/JS guidelines
βœ… GRADIO_SYSTEM_PROMPT - Complete Gradio API docs from gradio.app/llms.txt
βœ… STREAMLIT_SYSTEM_PROMPT - Streamlit with Docker requirements
βœ… REACT_SYSTEM_PROMPT - Next.js with Tailwind guidelines
βœ… TRANSFORMERS_JS_SYSTEM_PROMPT - Transformers.js patterns
βœ… JSON_SYSTEM_PROMPT - ComfyUI API docs from docs.comfy.org/llms.txt
βœ… All prompts include 'Built with anycoder' attribution rules

Files changed (1) hide show
  1. backend_api.py +19 -41
backend_api.py CHANGED
@@ -19,47 +19,25 @@ import os
19
  from huggingface_hub import InferenceClient
20
  import httpx
21
 
22
- # Import system prompts for code generation - use fallback if imports fail
23
- try:
24
- from anycoder_app.prompts import (
25
- HTML_SYSTEM_PROMPT,
26
- TRANSFORMERS_JS_SYSTEM_PROMPT,
27
- STREAMLIT_SYSTEM_PROMPT,
28
- REACT_SYSTEM_PROMPT,
29
- GENERIC_SYSTEM_PROMPT
30
- )
31
- # Try to import and initialize dynamic prompts (Gradio, ComfyUI)
32
- try:
33
- from anycoder_app.docs_manager import update_gradio_system_prompts, update_json_system_prompts
34
- from anycoder_app.prompts import GRADIO_SYSTEM_PROMPT, JSON_SYSTEM_PROMPT
35
- print("[Startup] Initializing Gradio and ComfyUI system prompts...")
36
- update_gradio_system_prompts()
37
- update_json_system_prompts()
38
- # Re-import to get updated prompts
39
- from anycoder_app.prompts import GRADIO_SYSTEM_PROMPT as GRADIO_PROMPT_UPDATED
40
- from anycoder_app.prompts import JSON_SYSTEM_PROMPT as JSON_PROMPT_UPDATED
41
- GRADIO_SYSTEM_PROMPT = GRADIO_PROMPT_UPDATED
42
- JSON_SYSTEM_PROMPT = JSON_PROMPT_UPDATED
43
- print("[Startup] System prompts initialized successfully")
44
- except Exception as e:
45
- print(f"[Startup] Warning: Could not initialize dynamic prompts: {e}")
46
- # Use fallback prompts
47
- GRADIO_SYSTEM_PROMPT = "You are an expert Gradio developer. Create complete, working Gradio applications."
48
- JSON_SYSTEM_PROMPT = "You are an expert at generating JSON configurations. Create valid, well-structured JSON."
49
-
50
- print("[Startup] System prompts loaded successfully")
51
-
52
- except Exception as e:
53
- print(f"[Startup] ERROR: Could not import prompts from anycoder_app: {e}")
54
- print("[Startup] Using basic fallback prompts")
55
- # Define minimal fallback prompts
56
- HTML_SYSTEM_PROMPT = "You are an expert web developer. Create complete HTML applications with CSS and JavaScript."
57
- TRANSFORMERS_JS_SYSTEM_PROMPT = "You are an expert at creating transformers.js applications. Generate complete working code."
58
- STREAMLIT_SYSTEM_PROMPT = "You are an expert Streamlit developer. Create complete Streamlit applications."
59
- REACT_SYSTEM_PROMPT = "You are an expert React developer. Create complete React applications with Next.js."
60
- GRADIO_SYSTEM_PROMPT = "You are an expert Gradio developer. Create complete, working Gradio applications."
61
- JSON_SYSTEM_PROMPT = "You are an expert at generating JSON configurations. Create valid, well-structured JSON."
62
- GENERIC_SYSTEM_PROMPT = "You are an expert {language} developer. Create complete, working {language} applications."
63
 
64
  # Define models and languages here to avoid importing Gradio UI
65
  AVAILABLE_MODELS = [
 
19
  from huggingface_hub import InferenceClient
20
  import httpx
21
 
22
+ # Import system prompts for code generation
23
+ # These come from anycoder_app which has all the detailed prompts
24
+ from anycoder_app.prompts import (
25
+ HTML_SYSTEM_PROMPT,
26
+ TRANSFORMERS_JS_SYSTEM_PROMPT,
27
+ STREAMLIT_SYSTEM_PROMPT,
28
+ REACT_SYSTEM_PROMPT,
29
+ GENERIC_SYSTEM_PROMPT
30
+ )
31
+
32
+ # Initialize dynamic Gradio and ComfyUI system prompts with full API docs
33
+ from anycoder_app.docs_manager import update_gradio_system_prompts, update_json_system_prompts
34
+ print("[Startup] Initializing Gradio and ComfyUI system prompts with API documentation...")
35
+ update_gradio_system_prompts()
36
+ update_json_system_prompts()
37
+
38
+ # Import the now-populated prompts
39
+ from anycoder_app.prompts import GRADIO_SYSTEM_PROMPT, JSON_SYSTEM_PROMPT
40
+ print("[Startup] βœ… All system prompts loaded successfully with full API documentation")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # Define models and languages here to avoid importing Gradio UI
43
  AVAILABLE_MODELS = [