tc043 commited on
Commit
043aa6b
·
1 Parent(s): 20eda77

fix: refine system prompts to enforce physical actions and single-sentence output while adding repetition detection for model responses

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -83,7 +83,7 @@ async def generate_atomic_task(goal: str, previous_failures: int, history: list
83
  if previous_failures > 0 and rejected_task:
84
  print(f"TASK WAS REJECTED ('{rejected_task}'). ROUTING TO MINICPM FOR SUB-STEP BREAKDOWN...", flush=True)
85
  messages = [
86
- {"role": "system", "content": "You are a cognitive pacemaker. When a task is too hard, break it down into a single, even simpler, tiny physical starting action under 8 words. Return ONLY the starting action."},
87
  {"role": "user", "content": f"The task '{rejected_task}' was too hard. Break it down into a single, even simpler physical starting action."}
88
  ]
89
  fallback_res = await run_blocking(
@@ -131,11 +131,13 @@ async def generate_atomic_task(goal: str, previous_failures: int, history: list
131
  content = line
132
  break
133
 
134
- # Check if output is empty
135
  is_invalid = not content
 
 
136
 
137
  if is_invalid:
138
- print(f"NEMOTRON OUTPUT INVALID ('{raw_content}'). FALLING BACK TO MINICPM...", flush=True)
139
  messages = [
140
  {"role": "system", "content": "You are a cognitive pacemaker. Focus strictly on the physical goal and break it down into an extremely tiny, atomic physical action under 8 words. Ignore mental blocks or feelings of being stuck and output ONLY the single physical action step."},
141
  {"role": "user", "content": f"Goal: {goal}\nCompleted Tasks: {history_str}\nFailures: {previous_failures}\nOutput the NEXT step."}
@@ -174,7 +176,7 @@ async def apply_activation_style(task: str, style="direct") -> str:
174
  "RULES:\n"
175
  "1. Keep it as an action/command the user MUST do now. Start or end with an encouraging phrase like 'You got this!', 'Let's do it!', or 'Go ahead and...'.\n"
176
  "2. Do NOT write in the past tense, do NOT congratulate the user, and do NOT treat the task as already completed.\n"
177
- "3. Keep it brief (under 12 words) and output ONLY the final rewritten task."
178
  )
179
  elif style == "calm":
180
  system_prompt = (
@@ -182,7 +184,7 @@ async def apply_activation_style(task: str, style="direct") -> str:
182
  "RULES:\n"
183
  "1. Keep it as an action/command. Use gentle prefixes like 'When you are ready, ...' or 'Take your time and ...'.\n"
184
  "2. Do NOT write in the past tense and do NOT congratulate the user.\n"
185
- "3. Keep it brief (under 12 words) and output ONLY the final rewritten task."
186
  )
187
  else:
188
  system_prompt = (
@@ -190,7 +192,7 @@ async def apply_activation_style(task: str, style="direct") -> str:
190
  "RULES:\n"
191
  "1. Keep it as an action/command the user MUST do now.\n"
192
  "2. Do NOT write in the past tense, do NOT congratulate the user, and do NOT treat the task as already completed.\n"
193
- "3. Keep it brief (under 12 words) and output ONLY the final rewritten task."
194
  )
195
 
196
  messages = [
 
83
  if previous_failures > 0 and rejected_task:
84
  print(f"TASK WAS REJECTED ('{rejected_task}'). ROUTING TO MINICPM FOR SUB-STEP BREAKDOWN...", flush=True)
85
  messages = [
86
+ {"role": "system", "content": "You are a cognitive pacemaker. When a task is too hard, break it down into a single, even simpler, tiny physical starting action under 8 words. Return ONLY the starting action. CRITICAL: Focus strictly on the physical movement. Do NOT suggest thinking, planning, or remembering."},
87
  {"role": "user", "content": f"The task '{rejected_task}' was too hard. Break it down into a single, even simpler physical starting action."}
88
  ]
89
  fallback_res = await run_blocking(
 
131
  content = line
132
  break
133
 
134
+ # Check if output is empty or a repetition
135
  is_invalid = not content
136
+ if content and history and content.strip().lower() == history[-1].strip().lower():
137
+ is_invalid = True
138
 
139
  if is_invalid:
140
+ print(f"NEMOTRON OUTPUT INVALID OR REPETITION ('{raw_content}'). FALLING BACK TO MINICPM...", flush=True)
141
  messages = [
142
  {"role": "system", "content": "You are a cognitive pacemaker. Focus strictly on the physical goal and break it down into an extremely tiny, atomic physical action under 8 words. Ignore mental blocks or feelings of being stuck and output ONLY the single physical action step."},
143
  {"role": "user", "content": f"Goal: {goal}\nCompleted Tasks: {history_str}\nFailures: {previous_failures}\nOutput the NEXT step."}
 
176
  "RULES:\n"
177
  "1. Keep it as an action/command the user MUST do now. Start or end with an encouraging phrase like 'You got this!', 'Let's do it!', or 'Go ahead and...'.\n"
178
  "2. Do NOT write in the past tense, do NOT congratulate the user, and do NOT treat the task as already completed.\n"
179
+ "3. Limit your response to EXACTLY ONE short sentence (under 12 words) and output ONLY the final rewritten task."
180
  )
181
  elif style == "calm":
182
  system_prompt = (
 
184
  "RULES:\n"
185
  "1. Keep it as an action/command. Use gentle prefixes like 'When you are ready, ...' or 'Take your time and ...'.\n"
186
  "2. Do NOT write in the past tense and do NOT congratulate the user.\n"
187
+ "3. Limit your response to EXACTLY ONE short sentence (under 12 words) and output ONLY the final rewritten task."
188
  )
189
  else:
190
  system_prompt = (
 
192
  "RULES:\n"
193
  "1. Keep it as an action/command the user MUST do now.\n"
194
  "2. Do NOT write in the past tense, do NOT congratulate the user, and do NOT treat the task as already completed.\n"
195
+ "3. Limit your response to EXACTLY ONE short sentence (under 12 words) and output ONLY the final rewritten task."
196
  )
197
 
198
  messages = [