Spaces:
Running
Running
Commit Β·
3ea5812
1
Parent(s): a46052d
LLM: show full script+bugs in initial prompt, clearer error feedback
Browse files- gradio_app.py +22 -10
gradio_app.py
CHANGED
|
@@ -1051,24 +1051,34 @@ CRITICAL RULES:
|
|
| 1051 |
|
| 1052 |
def _obs_to_prompt(obs):
|
| 1053 |
parts = [f"Stage {obs.current_stage} | step {obs.stage_step_number}"]
|
|
|
|
|
|
|
| 1054 |
if obs.last_run_error:
|
| 1055 |
-
parts.append(f"\
|
| 1056 |
if obs.last_run_output:
|
| 1057 |
-
parts.append(f"\
|
| 1058 |
if obs.actor_feedback:
|
| 1059 |
-
parts.append(f"\nREVIEWER
|
| 1060 |
-
if obs.script_content:
|
| 1061 |
-
parts.append(f"\nCURRENT SCRIPT:\n{obs.script_content[:800]}")
|
| 1062 |
return "\n".join(parts)
|
| 1063 |
|
| 1064 |
_env = DataEngEnvironment()
|
| 1065 |
init_obs = _env.reset()
|
| 1066 |
yield emit(" β Private env initialised β Stage 1\n")
|
| 1067 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1068 |
LABELS = {1:"Data Repair",2:"Training Monitor",3:"Eval Validation",4:"Deploy Gate"}
|
| 1069 |
msgs = [
|
| 1070 |
{"role": "system", "content": _SYS},
|
| 1071 |
-
{"role": "user", "content":
|
| 1072 |
]
|
| 1073 |
cur_stage = 1
|
| 1074 |
step = 0
|
|
@@ -1142,13 +1152,15 @@ CRITICAL RULES:
|
|
| 1142 |
msgs.append({"role": "assistant", "content": json.dumps(action)})
|
| 1143 |
feedback = _obs_to_prompt(obs)
|
| 1144 |
if atype == "run_script" and obs.last_run_error:
|
| 1145 |
-
feedback += "\n\nScript errored. Use edit_script with a FULL replacement
|
| 1146 |
elif atype == "run_script" and not obs.last_run_error:
|
| 1147 |
-
feedback += "\n\nClean run β
|
| 1148 |
elif atype == "edit_script":
|
| 1149 |
-
feedback += "\n\nScript replaced.
|
| 1150 |
elif atype == "query_actor":
|
| 1151 |
-
feedback += "\n\nReviewer
|
|
|
|
|
|
|
| 1152 |
msgs.append({"role": "user", "content": feedback})
|
| 1153 |
if len(msgs) > 16:
|
| 1154 |
msgs = [msgs[0]] + msgs[1:3] + msgs[-10:]
|
|
|
|
| 1051 |
|
| 1052 |
def _obs_to_prompt(obs):
|
| 1053 |
parts = [f"Stage {obs.current_stage} | step {obs.stage_step_number}"]
|
| 1054 |
+
if obs.script_content:
|
| 1055 |
+
parts.append(f"\nCURRENT SCRIPT:\n{obs.script_content[:1000]}")
|
| 1056 |
if obs.last_run_error:
|
| 1057 |
+
parts.append(f"\nRUN ERROR:\n{obs.last_run_error[:500]}")
|
| 1058 |
if obs.last_run_output:
|
| 1059 |
+
parts.append(f"\nRUN OUTPUT:\n{obs.last_run_output[:300]}")
|
| 1060 |
if obs.actor_feedback:
|
| 1061 |
+
parts.append(f"\nREVIEWER:\n{obs.actor_feedback[:300]}")
|
|
|
|
|
|
|
| 1062 |
return "\n".join(parts)
|
| 1063 |
|
| 1064 |
_env = DataEngEnvironment()
|
| 1065 |
init_obs = _env.reset()
|
| 1066 |
yield emit(" β Private env initialised β Stage 1\n")
|
| 1067 |
|
| 1068 |
+
# Build the initial user message with full broken script visible
|
| 1069 |
+
_init_prompt = _obs_to_prompt(init_obs)
|
| 1070 |
+
# Hint: show exactly what needs to change so LLM doesn't hallucinate
|
| 1071 |
+
_init_prompt += (
|
| 1072 |
+
"\n\nThe script above has TWO bugs:\n"
|
| 1073 |
+
"1. Line uses 'age_years' but the column is named 'age' β fix the column name\n"
|
| 1074 |
+
"2. No missing-value handling β add df.dropna() before feature selection\n"
|
| 1075 |
+
"Write a FULL replacement script fixing BOTH bugs, then call run_script."
|
| 1076 |
+
)
|
| 1077 |
+
|
| 1078 |
LABELS = {1:"Data Repair",2:"Training Monitor",3:"Eval Validation",4:"Deploy Gate"}
|
| 1079 |
msgs = [
|
| 1080 |
{"role": "system", "content": _SYS},
|
| 1081 |
+
{"role": "user", "content": _init_prompt},
|
| 1082 |
]
|
| 1083 |
cur_stage = 1
|
| 1084 |
step = 0
|
|
|
|
| 1152 |
msgs.append({"role": "assistant", "content": json.dumps(action)})
|
| 1153 |
feedback = _obs_to_prompt(obs)
|
| 1154 |
if atype == "run_script" and obs.last_run_error:
|
| 1155 |
+
feedback += "\n\nScript errored (see RUN ERROR above). Use edit_script with a FULL script replacement β include ALL imports and fix EVERY bug shown in the error."
|
| 1156 |
elif atype == "run_script" and not obs.last_run_error:
|
| 1157 |
+
feedback += "\n\nClean run β script printed output with no error. Call submit NOW."
|
| 1158 |
elif atype == "edit_script":
|
| 1159 |
+
feedback += "\n\nScript replaced. Call run_script to verify the fix."
|
| 1160 |
elif atype == "query_actor":
|
| 1161 |
+
feedback += "\n\nReviewer responded above. Use edit_script with full script to apply the fix, then run_script."
|
| 1162 |
+
elif atype == "submit":
|
| 1163 |
+
feedback += "\n\nStage not yet passing. Review the current script and error carefully, then edit_script to fix remaining bugs."
|
| 1164 |
msgs.append({"role": "user", "content": feedback})
|
| 1165 |
if len(msgs) > 16:
|
| 1166 |
msgs = [msgs[0]] + msgs[1:3] + msgs[-10:]
|