Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,12 +35,19 @@ def analyze_prompt(user_prompt):
|
|
| 35 |
|
| 36 |
analysis = detection_response.choices[0].message.content.strip()
|
| 37 |
|
|
|
|
| 38 |
rewrite_prompt = f"""
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
| 43 |
{user_prompt}
|
|
|
|
|
|
|
| 44 |
"""
|
| 45 |
|
| 46 |
rewrite_response = client.chat.completions.create(
|
|
|
|
| 35 |
|
| 36 |
analysis = detection_response.choices[0].message.content.strip()
|
| 37 |
|
| 38 |
+
# Step 2: Suggest a safer reformulation of the prompt (conditional)
|
| 39 |
rewrite_prompt = f"""
|
| 40 |
+
You are an AI security assistant.
|
| 41 |
+
Based on the following analysis of a user prompt, output a safer version of the prompt ONLY if it is risky.
|
| 42 |
+
If the analysis indicates no risk, simply return the original prompt as-is.
|
| 43 |
|
| 44 |
+
Analysis Result:
|
| 45 |
+
{analysis}
|
| 46 |
+
|
| 47 |
+
Original Prompt:
|
| 48 |
{user_prompt}
|
| 49 |
+
|
| 50 |
+
Output ONLY the rewritten prompt text (or the original prompt if safe), without explanations, notes, or extra words.
|
| 51 |
"""
|
| 52 |
|
| 53 |
rewrite_response = client.chat.completions.create(
|