-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprompt_optimazation.py
More file actions
35 lines (29 loc) · 925 Bytes
/
prompt_optimazation.py
File metadata and controls
35 lines (29 loc) · 925 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def optimize_prompt(prompt: str) -> str:
"""
Apply common prompt optimizations.
NOT a replacement for manual review - just catches obvious bloat.
"""
# Remove common filler phrases
fillers = [
"I want you to",
"You are a highly intelligent",
"Please note that",
"It's important to remember that",
"In your response, make sure to",
"As an AI assistant,",
]
result = prompt
for filler in fillers:
result = result.replace(filler, "")
# Remove excessive whitespace
result = " ".join(result.split())
# Remove repeated instructions
lines = result.split(".")
seen = set()
unique_lines = []
for line in lines:
normalized = line.strip().lower()
if normalized and normalized not in seen:
seen.add(normalized)
unique_lines.append(line)
return ". ".join(unique_lines)