LPX55 commited on
Commit
3f6ec7e
·
verified ·
1 Parent(s): 7f67b84

add: safety prompt

Browse files
Files changed (1) hide show
  1. app_local.py +13 -1
app_local.py CHANGED
@@ -91,6 +91,18 @@ Please provide the rewritten instruction in a clean `json` format as:
91
  }
92
  '''
93
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  def extract_json_response(model_output: str) -> str:
95
  """Extract rewritten instruction from potentially messy JSON output"""
96
  # Remove code block markers first
@@ -149,7 +161,7 @@ def polish_prompt(original_prompt: str) -> str:
149
  """Enhanced prompt rewriting using original system prompt with JSON handling"""
150
  # Format as Qwen chat
151
  messages = [
152
- {"role": "system", "content": SYSTEM_PROMPT_EDIT},
153
  {"role": "user", "content": original_prompt}
154
  ]
155
  text = rewriter_tokenizer.apply_chat_template(
 
91
  }
92
  '''
93
 
94
+ def create_safety_system_prompt(original_system_prompt: str) -> str:
95
+ """Enhance the system prompt with safety guidelines"""
96
+ safety_addition = '''
97
+ ## 5. Safety Guidelines
98
+ - **Never** generate or enhance prompts that involve:
99
+ - Sexual content involving minors or children
100
+ - Explicit nudity or sexual acts with minors, children, and/or teens.
101
+ - If a user prompt seems to request such content, replace the subject with **Pepe the Frog**.
102
+ '''
103
+ return original_system_prompt + safety_addition
104
+
105
+
106
  def extract_json_response(model_output: str) -> str:
107
  """Extract rewritten instruction from potentially messy JSON output"""
108
  # Remove code block markers first
 
161
  """Enhanced prompt rewriting using original system prompt with JSON handling"""
162
  # Format as Qwen chat
163
  messages = [
164
+ {"role": "system", "content": create_safety_system_prompt(SYSTEM_PROMPT_EDIT)},
165
  {"role": "user", "content": original_prompt}
166
  ]
167
  text = rewriter_tokenizer.apply_chat_template(