Spaces:
Sleeping

netha01 commited on
Commit
2df97ec
·
1 Parent(s): a34321e

Refactor error sanitization

Browse files
Files changed (1) hide show
  1. inference.py +6 -2
inference.py CHANGED
@@ -151,6 +151,10 @@ def model_action(obs, task_key: str) -> dict:
151
  return json.loads(raw_content.strip())
152
 
153
 
 
 
 
 
154
  def run_agent(task_key: str, max_steps: int = 20) -> None:
155
  benchmark_name = "ai-soc-gym"
156
  _, task_cls = TASK_MAP[task_key]
@@ -175,7 +179,7 @@ def run_agent(task_key: str, max_steps: int = 20) -> None:
175
  llm_out = model_action(obs, task_key)
176
  except Exception as model_exc:
177
  llm_out = heuristic_action(obs, task_key)
178
- last_action_error = f"fallback:{str(model_exc).replace('\n', ' ').replace('\r', ' ')}"
179
 
180
  action = Action(**llm_out)
181
  action_str = json.dumps(llm_out, separators=(",", ":"))
@@ -184,7 +188,7 @@ def run_agent(task_key: str, max_steps: int = 20) -> None:
184
  if done and not env._state.data_exfiltrated:
185
  final_success = True
186
  except Exception as exc:
187
- last_action_error = str(exc).replace("\n", " ").replace("\r", " ")
188
  done = True
189
 
190
  all_rewards.append(reward_score)
 
151
  return json.loads(raw_content.strip())
152
 
153
 
154
+ def sanitize_error_message(exc: Exception) -> str:
155
+ return str(exc).replace("\n", " ").replace("\r", " ")
156
+
157
+
158
  def run_agent(task_key: str, max_steps: int = 20) -> None:
159
  benchmark_name = "ai-soc-gym"
160
  _, task_cls = TASK_MAP[task_key]
 
179
  llm_out = model_action(obs, task_key)
180
  except Exception as model_exc:
181
  llm_out = heuristic_action(obs, task_key)
182
+ last_action_error = f"fallback:{sanitize_error_message(model_exc)}"
183
 
184
  action = Action(**llm_out)
185
  action_str = json.dumps(llm_out, separators=(",", ":"))
 
188
  if done and not env._state.data_exfiltrated:
189
  final_success = True
190
  except Exception as exc:
191
+ last_action_error = sanitize_error_message(exc)
192
  done = True
193
 
194
  all_rewards.append(reward_score)