Commit
·
7e46b08
1
Parent(s):
0c53202
commit
Browse files
app.py
CHANGED
|
@@ -10,26 +10,48 @@ Your task:
|
|
| 10 |
1. Take the user's rough draft describing an AI code generation agent's desired functionalities
|
| 11 |
2. Transform it into a well-organized, clear system prompt written in second person ("you")
|
| 12 |
3. Ensure all desired functionalities from the original draft are preserved and clearly reflected
|
| 13 |
-
4.
|
| 14 |
-
5.
|
| 15 |
|
| 16 |
Requirements:
|
| 17 |
- Write the system prompt directing the agent in second person
|
| 18 |
- Organize the content logically with clear structure
|
| 19 |
- Maintain all functional requirements from the original draft
|
| 20 |
-
-
|
| 21 |
-
-
|
| 22 |
- Return only the polished system prompt in markdown within a code fence
|
| 23 |
|
| 24 |
Output format: Return the improved system prompt in markdown code fences with no additional commentary."""
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
"""
|
| 28 |
Reformat a rough draft into a polished system prompt using OpenAI API.
|
| 29 |
|
| 30 |
Args:
|
| 31 |
api_key: OpenAI API key
|
| 32 |
rough_draft: The rough draft text to be reformatted
|
|
|
|
| 33 |
|
| 34 |
Returns:
|
| 35 |
Reformatted system prompt or error message
|
|
@@ -40,6 +62,9 @@ def reformat_prompt(api_key: str, rough_draft: str) -> str:
|
|
| 40 |
if not rough_draft.strip():
|
| 41 |
return "Error: Please provide a rough draft to reformat."
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
try:
|
| 44 |
# Initialize OpenAI client with the provided API key
|
| 45 |
client = openai.OpenAI(api_key=api_key)
|
|
@@ -48,7 +73,7 @@ def reformat_prompt(api_key: str, rough_draft: str) -> str:
|
|
| 48 |
response = client.chat.completions.create(
|
| 49 |
model="gpt-4o-mini",
|
| 50 |
messages=[
|
| 51 |
-
{"role": "system", "content":
|
| 52 |
{"role": "user", "content": rough_draft}
|
| 53 |
],
|
| 54 |
temperature=0.1,
|
|
@@ -71,7 +96,7 @@ def create_interface():
|
|
| 71 |
"""Create and configure the Gradio interface."""
|
| 72 |
|
| 73 |
with gr.Blocks(
|
| 74 |
-
title="Code Gen Prompt
|
| 75 |
theme=gr.themes.Soft(),
|
| 76 |
css="""
|
| 77 |
.container {
|
|
@@ -101,8 +126,8 @@ def create_interface():
|
|
| 101 |
|
| 102 |
gr.HTML("""
|
| 103 |
<div class="header">
|
| 104 |
-
<h1>Code Gen Prompt
|
| 105 |
-
<p>
|
| 106 |
</div>
|
| 107 |
""")
|
| 108 |
|
|
@@ -117,6 +142,16 @@ def create_interface():
|
|
| 117 |
info="Your API key is not stored and only used for this session"
|
| 118 |
)
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
rough_draft_input = gr.Textbox(
|
| 121 |
label="Rough Draft",
|
| 122 |
placeholder="Enter your rough draft describing the desired functionalities of the AI code generation agent...",
|
|
@@ -137,47 +172,72 @@ def create_interface():
|
|
| 137 |
interactive=False
|
| 138 |
)
|
| 139 |
|
| 140 |
-
with gr.TabItem("System
|
| 141 |
gr.HTML("""
|
| 142 |
-
<h3>System
|
| 143 |
-
<p>
|
| 144 |
""")
|
| 145 |
|
| 146 |
-
gr.
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
# Event handlers
|
| 171 |
submit_btn.click(
|
| 172 |
fn=reformat_prompt,
|
| 173 |
-
inputs=[api_key_input, rough_draft_input],
|
| 174 |
outputs=output,
|
| 175 |
show_progress=True
|
| 176 |
)
|
| 177 |
|
| 178 |
clear_btn.click(
|
| 179 |
-
fn=lambda: ("", "", ""),
|
| 180 |
-
outputs=[api_key_input, rough_draft_input, output]
|
| 181 |
)
|
| 182 |
|
| 183 |
|
|
|
|
| 10 |
1. Take the user's rough draft describing an AI code generation agent's desired functionalities
|
| 11 |
2. Transform it into a well-organized, clear system prompt written in second person ("you")
|
| 12 |
3. Ensure all desired functionalities from the original draft are preserved and clearly reflected
|
| 13 |
+
4. Include context that the agent will operate as part of an AI agent crew collaborating within a repository/codebase
|
| 14 |
+
5. Inform the agent about its multi-agent environment without prescribing specific collaborative behaviors
|
| 15 |
|
| 16 |
Requirements:
|
| 17 |
- Write the system prompt directing the agent in second person
|
| 18 |
- Organize the content logically with clear structure
|
| 19 |
- Maintain all functional requirements from the original draft
|
| 20 |
+
- Include information about the agent's multi-agent context in the system prompt
|
| 21 |
+
- Let the agent determine how to handle collaboration based on its role
|
| 22 |
- Return only the polished system prompt in markdown within a code fence
|
| 23 |
|
| 24 |
Output format: Return the improved system prompt in markdown code fences with no additional commentary."""
|
| 25 |
|
| 26 |
+
# Alternative system prompt for Claude Code with frontmatter
|
| 27 |
+
CLAUDE_CODE_SYSTEM_PROMPT = """You are a system prompt specialist that converts rough drafts into polished, clear specifications for AI code generation agents designed for use in Claude Code.
|
| 28 |
+
|
| 29 |
+
Your task:
|
| 30 |
+
1. Take the user's rough draft describing an AI code generation agent's desired functionalities
|
| 31 |
+
2. Create appropriate frontmatter following the Claude Code format with name, description, examples, tools, model, and color
|
| 32 |
+
3. Transform the draft into a well-organized system prompt written in second person ("you")
|
| 33 |
+
4. Include context that the agent will operate as part of an AI agent crew collaborating within a repository/codebase
|
| 34 |
+
5. Ensure the frontmatter description and examples clearly show when to use this agent
|
| 35 |
+
|
| 36 |
+
Requirements:
|
| 37 |
+
- Start with properly formatted frontmatter (name, description with examples, tools, model, color)
|
| 38 |
+
- Write the system prompt directing the agent in second person
|
| 39 |
+
- Organize the content logically with clear structure
|
| 40 |
+
- Maintain all functional requirements from the original draft
|
| 41 |
+
- Include information about the agent's multi-agent context
|
| 42 |
+
- Provide realistic usage examples in the frontmatter description
|
| 43 |
+
- Return only the complete prompt with frontmatter in markdown code fences
|
| 44 |
+
|
| 45 |
+
Output format: Return the complete prompt with frontmatter and system prompt in markdown code fences with no additional commentary."""
|
| 46 |
+
|
| 47 |
+
def reformat_prompt(api_key: str, rough_draft: str, prompt_type: str = "standard") -> str:
|
| 48 |
"""
|
| 49 |
Reformat a rough draft into a polished system prompt using OpenAI API.
|
| 50 |
|
| 51 |
Args:
|
| 52 |
api_key: OpenAI API key
|
| 53 |
rough_draft: The rough draft text to be reformatted
|
| 54 |
+
prompt_type: Type of prompt to generate ("standard" or "claude_code")
|
| 55 |
|
| 56 |
Returns:
|
| 57 |
Reformatted system prompt or error message
|
|
|
|
| 62 |
if not rough_draft.strip():
|
| 63 |
return "Error: Please provide a rough draft to reformat."
|
| 64 |
|
| 65 |
+
# Select the appropriate system prompt based on type
|
| 66 |
+
selected_system_prompt = CLAUDE_CODE_SYSTEM_PROMPT if prompt_type == "claude_code" else SYSTEM_PROMPT
|
| 67 |
+
|
| 68 |
try:
|
| 69 |
# Initialize OpenAI client with the provided API key
|
| 70 |
client = openai.OpenAI(api_key=api_key)
|
|
|
|
| 73 |
response = client.chat.completions.create(
|
| 74 |
model="gpt-4o-mini",
|
| 75 |
messages=[
|
| 76 |
+
{"role": "system", "content": selected_system_prompt},
|
| 77 |
{"role": "user", "content": rough_draft}
|
| 78 |
],
|
| 79 |
temperature=0.1,
|
|
|
|
| 96 |
"""Create and configure the Gradio interface."""
|
| 97 |
|
| 98 |
with gr.Blocks(
|
| 99 |
+
title="Code Gen Agent Prompt Assistant",
|
| 100 |
theme=gr.themes.Soft(),
|
| 101 |
css="""
|
| 102 |
.container {
|
|
|
|
| 126 |
|
| 127 |
gr.HTML("""
|
| 128 |
<div class="header">
|
| 129 |
+
<h1>Code Gen Agent Prompt Assistant</h1>
|
| 130 |
+
<p>Transform rough drafts into polished system prompts for AI code generation agents operating within multi-agent crews.</p>
|
| 131 |
</div>
|
| 132 |
""")
|
| 133 |
|
|
|
|
| 142 |
info="Your API key is not stored and only used for this session"
|
| 143 |
)
|
| 144 |
|
| 145 |
+
prompt_type_radio = gr.Radio(
|
| 146 |
+
choices=[
|
| 147 |
+
("Standard Multi-Agent Prompt", "standard"),
|
| 148 |
+
("Claude Code with Frontmatter", "claude_code")
|
| 149 |
+
],
|
| 150 |
+
value="standard",
|
| 151 |
+
label="Prompt Type",
|
| 152 |
+
info="Choose the format for your system prompt"
|
| 153 |
+
)
|
| 154 |
+
|
| 155 |
rough_draft_input = gr.Textbox(
|
| 156 |
label="Rough Draft",
|
| 157 |
placeholder="Enter your rough draft describing the desired functionalities of the AI code generation agent...",
|
|
|
|
| 172 |
interactive=False
|
| 173 |
)
|
| 174 |
|
| 175 |
+
with gr.TabItem("System Prompts"):
|
| 176 |
gr.HTML("""
|
| 177 |
+
<h3>System Prompts Used in Workflow</h3>
|
| 178 |
+
<p>These are the system prompts that guide the AI in reformatting your rough drafts:</p>
|
| 179 |
""")
|
| 180 |
|
| 181 |
+
with gr.Tabs():
|
| 182 |
+
with gr.TabItem("Standard Multi-Agent"):
|
| 183 |
+
gr.Textbox(
|
| 184 |
+
value=SYSTEM_PROMPT,
|
| 185 |
+
label="Standard Multi-Agent System Prompt",
|
| 186 |
+
lines=15,
|
| 187 |
+
max_lines=25,
|
| 188 |
+
show_copy_button=True,
|
| 189 |
+
interactive=False,
|
| 190 |
+
elem_classes=["system-prompt-display"]
|
| 191 |
+
)
|
| 192 |
+
|
| 193 |
+
gr.HTML("""
|
| 194 |
+
<div style="margin-top: 1rem; padding: 1rem; background-color: #e3f2fd; border-radius: 8px;">
|
| 195 |
+
<h4>About This System Prompt</h4>
|
| 196 |
+
<p>This system prompt creates standard prompts that:</p>
|
| 197 |
+
<ul>
|
| 198 |
+
<li>Inform agents about their multi-agent environment context</li>
|
| 199 |
+
<li>Convert rough notes into polished system prompts for code generation agents</li>
|
| 200 |
+
<li>Focus on agents within multi-agent crews working in codebases</li>
|
| 201 |
+
<li>Let agents determine their own collaborative behaviors</li>
|
| 202 |
+
</ul>
|
| 203 |
+
</div>
|
| 204 |
+
""")
|
| 205 |
+
|
| 206 |
+
with gr.TabItem("Claude Code with Frontmatter"):
|
| 207 |
+
gr.Textbox(
|
| 208 |
+
value=CLAUDE_CODE_SYSTEM_PROMPT,
|
| 209 |
+
label="Claude Code System Prompt",
|
| 210 |
+
lines=15,
|
| 211 |
+
max_lines=25,
|
| 212 |
+
show_copy_button=True,
|
| 213 |
+
interactive=False,
|
| 214 |
+
elem_classes=["system-prompt-display"]
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
gr.HTML("""
|
| 218 |
+
<div style="margin-top: 1rem; padding: 1rem; background-color: #fff3e0; border-radius: 8px;">
|
| 219 |
+
<h4>About This System Prompt</h4>
|
| 220 |
+
<p>This system prompt creates Claude Code compatible prompts that:</p>
|
| 221 |
+
<ul>
|
| 222 |
+
<li>Include proper frontmatter with name, description, examples, tools, model, and color</li>
|
| 223 |
+
<li>Provide realistic usage examples in the description</li>
|
| 224 |
+
<li>Create agents designed for Claude Code's multi-agent environment</li>
|
| 225 |
+
<li>Format everything according to Claude Code specifications</li>
|
| 226 |
+
</ul>
|
| 227 |
+
</div>
|
| 228 |
+
""")
|
| 229 |
|
| 230 |
# Event handlers
|
| 231 |
submit_btn.click(
|
| 232 |
fn=reformat_prompt,
|
| 233 |
+
inputs=[api_key_input, rough_draft_input, prompt_type_radio],
|
| 234 |
outputs=output,
|
| 235 |
show_progress=True
|
| 236 |
)
|
| 237 |
|
| 238 |
clear_btn.click(
|
| 239 |
+
fn=lambda: ("", "standard", "", ""),
|
| 240 |
+
outputs=[api_key_input, prompt_type_radio, rough_draft_input, output]
|
| 241 |
)
|
| 242 |
|
| 243 |
|