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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
def reformat_system_prompt(input_text):
|
| 5 |
+
"""
|
| 6 |
+
Reformats system prompts according to the specified guidelines
|
| 7 |
+
"""
|
| 8 |
+
if not input_text.strip():
|
| 9 |
+
return "Please provide a system prompt to reformat.", "", ""
|
| 10 |
+
|
| 11 |
+
# Apply reformatting logic
|
| 12 |
+
reformatted = input_text.strip()
|
| 13 |
+
|
| 14 |
+
# Convert first person to second person
|
| 15 |
+
reformatted = re.sub(r'\bI am\b', 'You are', reformatted, flags=re.IGNORECASE)
|
| 16 |
+
reformatted = re.sub(r'\bI will\b', 'You will', reformatted, flags=re.IGNORECASE)
|
| 17 |
+
reformatted = re.sub(r'\bI should\b', 'You should', reformatted, flags=re.IGNORECASE)
|
| 18 |
+
reformatted = re.sub(r'\bI can\b', 'You can', reformatted, flags=re.IGNORECASE)
|
| 19 |
+
reformatted = re.sub(r'\bI must\b', 'You must', reformatted, flags=re.IGNORECASE)
|
| 20 |
+
reformatted = re.sub(r'\bmy task\b', 'your task', reformatted, flags=re.IGNORECASE)
|
| 21 |
+
reformatted = re.sub(r'\bmy role\b', 'your role', reformatted, flags=re.IGNORECASE)
|
| 22 |
+
reformatted = re.sub(r'\bmy purpose\b', 'your purpose', reformatted, flags=re.IGNORECASE)
|
| 23 |
+
reformatted = re.sub(r'\bmy job\b', 'your job', reformatted, flags=re.IGNORECASE)
|
| 24 |
+
reformatted = re.sub(r'\bmy goal\b', 'your goal', reformatted, flags=re.IGNORECASE)
|
| 25 |
+
|
| 26 |
+
# Make ecosystem-agnostic
|
| 27 |
+
reformatted = re.sub(r'custom GPT', 'assistant', reformatted, flags=re.IGNORECASE)
|
| 28 |
+
reformatted = re.sub(r'ChatGPT', 'assistant', reformatted, flags=re.IGNORECASE)
|
| 29 |
+
reformatted = re.sub(r'GPT-4', 'assistant', reformatted, flags=re.IGNORECASE)
|
| 30 |
+
reformatted = re.sub(r'GPT model', 'assistant', reformatted, flags=re.IGNORECASE)
|
| 31 |
+
reformatted = re.sub(r'OpenAI', 'AI', reformatted, flags=re.IGNORECASE)
|
| 32 |
+
|
| 33 |
+
# Generalize user-specific language
|
| 34 |
+
reformatted = re.sub(r'help [A-Z][a-z]+ ', 'help the user ', reformatted)
|
| 35 |
+
reformatted = re.sub(r'assist [A-Z][a-z]+ ', 'assist the user ', reformatted)
|
| 36 |
+
reformatted = re.sub(r'for [A-Z][a-z]+\'s', 'for the user\'s', reformatted)
|
| 37 |
+
|
| 38 |
+
# Generate assistant name (extract main functionality)
|
| 39 |
+
name = extract_assistant_name(reformatted)
|
| 40 |
+
|
| 41 |
+
# Generate description
|
| 42 |
+
description = extract_description(reformatted)
|
| 43 |
+
|
| 44 |
+
return f"```\n{reformatted}\n```", name, description
|
| 45 |
+
|
| 46 |
+
def extract_assistant_name(text):
|
| 47 |
+
"""
|
| 48 |
+
Extract a name for the assistant based on its functionality
|
| 49 |
+
"""
|
| 50 |
+
# Look for key phrases that indicate functionality
|
| 51 |
+
if 'travel' in text.lower() and 'quiet' in text.lower():
|
| 52 |
+
return "Quiet Study Finder"
|
| 53 |
+
elif 'system prompt' in text.lower() and 'reformat' in text.lower():
|
| 54 |
+
return "System Prompt Reformatter"
|
| 55 |
+
elif 'code' in text.lower() and 'review' in text.lower():
|
| 56 |
+
return "Code Reviewer"
|
| 57 |
+
elif 'writing' in text.lower() and 'assistant' in text.lower():
|
| 58 |
+
return "Writing Assistant"
|
| 59 |
+
elif 'travel' in text.lower():
|
| 60 |
+
return "Travel Assistant"
|
| 61 |
+
elif 'restaurant' in text.lower():
|
| 62 |
+
return "Restaurant Finder"
|
| 63 |
+
elif 'recipe' in text.lower() or 'cooking' in text.lower():
|
| 64 |
+
return "Recipe Assistant"
|
| 65 |
+
elif 'learning' in text.lower() or 'tutor' in text.lower():
|
| 66 |
+
return "Learning Assistant"
|
| 67 |
+
elif 'email' in text.lower():
|
| 68 |
+
return "Email Assistant"
|
| 69 |
+
elif 'schedule' in text.lower() or 'calendar' in text.lower():
|
| 70 |
+
return "Schedule Assistant"
|
| 71 |
+
else:
|
| 72 |
+
return "AI Assistant"
|
| 73 |
+
|
| 74 |
+
def extract_description(text):
|
| 75 |
+
"""
|
| 76 |
+
Generate a single-sentence description of the assistant's function
|
| 77 |
+
"""
|
| 78 |
+
# Try to find purpose statements
|
| 79 |
+
if 'purpose' in text.lower():
|
| 80 |
+
match = re.search(r'purpose is to ([^.]+)', text.lower())
|
| 81 |
+
if match:
|
| 82 |
+
return f"Helps users {match.group(1).strip()}."
|
| 83 |
+
|
| 84 |
+
if 'help' in text.lower():
|
| 85 |
+
match = re.search(r'help.*?users?.*?(?:to )?([^.]+)', text.lower())
|
| 86 |
+
if match:
|
| 87 |
+
return f"Helps users {match.group(1).strip()}."
|
| 88 |
+
|
| 89 |
+
if 'assist' in text.lower():
|
| 90 |
+
match = re.search(r'assist.*?users?.*?(?:with|in) ([^.]+)', text.lower())
|
| 91 |
+
if match:
|
| 92 |
+
return f"Assists users with {match.group(1).strip()}."
|
| 93 |
+
|
| 94 |
+
# Fallback generic description
|
| 95 |
+
return "Provides AI assistance for various tasks."
|
| 96 |
+
|
| 97 |
+
# Create the Gradio interface
|
| 98 |
+
with gr.Blocks(title="System Prompt Reformatter", theme=gr.themes.Soft()) as demo:
|
| 99 |
+
gr.HTML("<h1 style='text-align: center;'>📚 System Prompt Reformatter</h1>")
|
| 100 |
+
gr.HTML("<p style='text-align: center;'>Transform system prompts to second person and make them ecosystem-agnostic</p>")
|
| 101 |
+
|
| 102 |
+
with gr.Tabs():
|
| 103 |
+
with gr.Tab("Reformatter"):
|
| 104 |
+
with gr.Row():
|
| 105 |
+
with gr.Column(scale=1):
|
| 106 |
+
input_text = gr.Textbox(
|
| 107 |
+
label="Original System Prompt",
|
| 108 |
+
placeholder="Paste your system prompt here...",
|
| 109 |
+
lines=10,
|
| 110 |
+
max_lines=20
|
| 111 |
+
)
|
| 112 |
+
submit_btn = gr.Button("Reformat Prompt", variant="primary")
|
| 113 |
+
|
| 114 |
+
with gr.Column(scale=1):
|
| 115 |
+
output_text = gr.Textbox(
|
| 116 |
+
label="Reformatted System Prompt",
|
| 117 |
+
lines=10,
|
| 118 |
+
max_lines=20,
|
| 119 |
+
interactive=False
|
| 120 |
+
)
|
| 121 |
+
assistant_name = gr.Textbox(
|
| 122 |
+
label="Assistant Name",
|
| 123 |
+
interactive=False
|
| 124 |
+
)
|
| 125 |
+
description = gr.Textbox(
|
| 126 |
+
label="Description",
|
| 127 |
+
interactive=False
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
submit_btn.click(
|
| 131 |
+
fn=reformat_system_prompt,
|
| 132 |
+
inputs=[input_text],
|
| 133 |
+
outputs=[output_text, assistant_name, description]
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
# Add example
|
| 137 |
+
gr.Examples(
|
| 138 |
+
examples=[
|
| 139 |
+
["I am a travel assistant. My purpose is to help Daniel find quiet places to study in busy cities. I should provide recommendations for libraries, cafes, and other quiet spaces."]
|
| 140 |
+
],
|
| 141 |
+
inputs=input_text,
|
| 142 |
+
label="Example"
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
with gr.Tab("About"):
|
| 146 |
+
gr.Markdown("""
|
| 147 |
+
# System Prompt Reformatter
|
| 148 |
+
|
| 149 |
+
This tool reformats system prompts for AI assistants to follow specific stylistic conventions.
|
| 150 |
+
|
| 151 |
+
## The System Prompt Used by This Tool
|
| 152 |
+
|
| 153 |
+
```
|
| 154 |
+
Your task is to lightly edit system prompts for AI tools to comply with a specific stylistic convention.
|
| 155 |
+
|
| 156 |
+
## Workflow
|
| 157 |
+
|
| 158 |
+
You will receive the prompt from the user which will contain the system prompt to be edited. Upon receiving it, you must apply the edits and return the edited system prompt back to the user (without any other text).
|
| 159 |
+
|
| 160 |
+
## Editing Instructions
|
| 161 |
+
|
| 162 |
+
- The system prompts should be written in the second person, instructing the assistant, for example, as you or your task.
|
| 163 |
+
- There should be spaces to organize the system prompt into paragraphs and headers can be used in markdown to signify and many more
|
| 164 |
+
- The system prompts should be "ecosystem-agnostic." For example: if the system prompt includes verbiage like "you are a custom GPT" you would replace with "you are an assistant."
|
| 165 |
+
- The system prompts should be suitable for use by any user. If you encounter language that makes the system prompt specific to one user, generalise it. For example if a system prompt contains: "your purpose is to help Daniel find restaurant recommendations," you would rewrite this as "your purpose is to help the user find restaurant recommendaitons."
|
| 166 |
+
|
| 167 |
+
## Additional Outputs
|
| 168 |
+
|
| 169 |
+
In addition to the edited system prompt, also provide:
|
| 170 |
+
|
| 171 |
+
- A name for the assistant encapsulating its main functionality
|
| 172 |
+
|
| 173 |
+
- A short single-sentence description describing the assistant's function (you don't need to mention that it's an AI tool!)
|
| 174 |
+
|
| 175 |
+
Provide the edited system prompt wrapped within a codefence.
|
| 176 |
+
|
| 177 |
+
## Example
|
| 178 |
+
|
| 179 |
+
Here's an example to show the desired output format, demonstrating the 3 elements that you should provide in response to the user prompt:
|
| 180 |
+
|
| 181 |
+
## Assistant Name
|
| 182 |
+
|
| 183 |
+
```
|
| 184 |
+
Quiet, Please
|
| 185 |
+
```
|
| 186 |
+
|
| 187 |
+
## Description
|
| 188 |
+
|
| 189 |
+
```
|
| 190 |
+
Helps user to locate quite study places in busy cities
|
| 191 |
+
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
## System Prompt
|
| 195 |
+
|
| 196 |
+
```
|
| 197 |
+
You are a travel assistant helping the user to locate quiet places to study in busy cities.
|
| 198 |
+
|
| 199 |
+
## Workflow
|
| 200 |
+
|
| 201 |
+
You assist the user in the following manner.
|
| 202 |
+
```
|
| 203 |
+
```
|
| 204 |
+
|
| 205 |
+
## How It Works
|
| 206 |
+
|
| 207 |
+
1. **Second Person Conversion**: Converts first-person language ("I am", "my task") to second-person ("You are", "your task")
|
| 208 |
+
2. **Ecosystem Agnostic**: Replaces platform-specific terms like "custom GPT" with generic "assistant"
|
| 209 |
+
3. **User Generalization**: Changes user-specific references to general "user" language
|
| 210 |
+
4. **Name Generation**: Creates an appropriate assistant name based on functionality
|
| 211 |
+
5. **Description Creation**: Generates a concise description of the assistant's purpose
|
| 212 |
+
|
| 213 |
+
## Usage Tips
|
| 214 |
+
|
| 215 |
+
- Paste your original system prompt in the left text area
|
| 216 |
+
- Click "Reformat Prompt" to process it
|
| 217 |
+
- Copy the results from the right side
|
| 218 |
+
- The reformatted prompt will be ready to use in any AI system
|
| 219 |
+
""")
|
| 220 |
+
|
| 221 |
+
if __name__ == "__main__":
|
| 222 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio==5.47.2
|