akhaliq HF Staff commited on
Commit
e841faa
·
1 Parent(s): 3a574f6

update comfyui system prompt

Browse files
Files changed (1) hide show
  1. app.py +48 -2
app.py CHANGED
@@ -47,6 +47,8 @@ def get_gradio_language(language):
47
  return "python"
48
  if language == "gradio":
49
  return "python"
 
 
50
  return language if language in GRADIO_SUPPORTED_LANGUAGES else None
51
 
52
  # Search/Replace Constants
@@ -1009,7 +1011,7 @@ def update_json_system_prompts():
1009
 
1010
  docs_content = get_comfyui_docs_content()
1011
 
1012
- # Base system prompt
1013
  base_prompt = """You are an expert JSON developer. Generate clean, valid JSON data based on the user's request. Follow JSON syntax rules strictly:
1014
  - Use double quotes for strings
1015
  - No trailing commas
@@ -1020,7 +1022,7 @@ Generate ONLY the JSON data requested - no HTML, no applications, no explanation
1020
 
1021
  """
1022
 
1023
- # Search-enabled system prompt
1024
  search_prompt = """You are an expert JSON developer. You have access to real-time web search. When needed, use web search to find the latest information or data structures for your JSON generation.
1025
 
1026
  Generate clean, valid JSON data based on the user's request. Follow JSON syntax rules strictly:
@@ -1052,6 +1054,48 @@ This reference is automatically synced from https://docs.comfy.org/llms.txt to e
1052
  JSON_SYSTEM_PROMPT = base_prompt
1053
  JSON_SYSTEM_PROMPT_WITH_SEARCH = search_prompt
1054
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1055
  # Initialize Gradio documentation on startup
1056
  def initialize_gradio_docs():
1057
  """Initialize Gradio documentation on application startup"""
@@ -5654,6 +5698,8 @@ Generate the exact search/replace blocks needed to make these changes."""
5654
  system_prompt = GRADIO_SYSTEM_PROMPT
5655
  elif language == "json":
5656
  system_prompt = JSON_SYSTEM_PROMPT
 
 
5657
  else:
5658
  system_prompt = GENERIC_SYSTEM_PROMPT.format(language=language)
5659
 
 
47
  return "python"
48
  if language == "gradio":
49
  return "python"
50
+ if language == "comfyui":
51
+ return "json"
52
  return language if language in GRADIO_SUPPORTED_LANGUAGES else None
53
 
54
  # Search/Replace Constants
 
1011
 
1012
  docs_content = get_comfyui_docs_content()
1013
 
1014
+ # Base system prompt for regular JSON
1015
  base_prompt = """You are an expert JSON developer. Generate clean, valid JSON data based on the user's request. Follow JSON syntax rules strictly:
1016
  - Use double quotes for strings
1017
  - No trailing commas
 
1022
 
1023
  """
1024
 
1025
+ # Search-enabled system prompt for regular JSON
1026
  search_prompt = """You are an expert JSON developer. You have access to real-time web search. When needed, use web search to find the latest information or data structures for your JSON generation.
1027
 
1028
  Generate clean, valid JSON data based on the user's request. Follow JSON syntax rules strictly:
 
1054
  JSON_SYSTEM_PROMPT = base_prompt
1055
  JSON_SYSTEM_PROMPT_WITH_SEARCH = search_prompt
1056
 
1057
+ def get_comfyui_system_prompt():
1058
+ """Get ComfyUI-specific system prompt with enhanced guidance"""
1059
+ docs_content = get_comfyui_docs_content()
1060
+
1061
+ base_prompt = """You are an expert ComfyUI developer. Generate clean, valid JSON workflows for ComfyUI based on the user's request.
1062
+
1063
+ ComfyUI workflows are JSON structures that define:
1064
+ - Nodes: Individual processing units with specific functions
1065
+ - Connections: Links between nodes that define data flow
1066
+ - Parameters: Configuration values for each node
1067
+ - Inputs/Outputs: Data flow between nodes
1068
+
1069
+ Follow JSON syntax rules strictly:
1070
+ - Use double quotes for strings
1071
+ - No trailing commas
1072
+ - Proper nesting and structure
1073
+ - Valid data types (string, number, boolean, null, object, array)
1074
+
1075
+ Generate ONLY the ComfyUI workflow JSON - no HTML, no applications, no explanations outside the JSON. The output should be a complete, valid ComfyUI workflow that can be loaded directly into ComfyUI.
1076
+
1077
+ """
1078
+
1079
+ # Add ComfyUI documentation if available
1080
+ if docs_content.strip():
1081
+ comfyui_section = f"""
1082
+ ## ComfyUI Reference Documentation
1083
+
1084
+ Use this reference for accurate node types, parameters, and workflow structures:
1085
+
1086
+ {docs_content}
1087
+
1088
+ This reference is automatically synced from https://docs.comfy.org/llms.txt to ensure accuracy.
1089
+
1090
+ """
1091
+ base_prompt += comfyui_section
1092
+
1093
+ base_prompt += """
1094
+ IMPORTANT: Always include "Built with anycoder" as a comment or metadata field in your ComfyUI workflow JSON that references https://huggingface.co/spaces/akhaliq/anycoder
1095
+ """
1096
+
1097
+ return base_prompt
1098
+
1099
  # Initialize Gradio documentation on startup
1100
  def initialize_gradio_docs():
1101
  """Initialize Gradio documentation on application startup"""
 
5698
  system_prompt = GRADIO_SYSTEM_PROMPT
5699
  elif language == "json":
5700
  system_prompt = JSON_SYSTEM_PROMPT
5701
+ elif language == "comfyui":
5702
+ system_prompt = get_comfyui_system_prompt()
5703
  else:
5704
  system_prompt = GENERIC_SYSTEM_PROMPT.format(language=language)
5705