From 819649325839af14d258ff78bd87d64444f922ef Mon Sep 17 00:00:00 2001 From: Leni Aniva Date: Fri, 11 Oct 2024 22:51:07 -0700 Subject: [PATCH] feat: Handle exceptions in tactic generation --- experiments/minif2f/model/llm_agent.py | 36 ++++++++++++++------------ 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/experiments/minif2f/model/llm_agent.py b/experiments/minif2f/model/llm_agent.py index 048242c..14c3b39 100644 --- a/experiments/minif2f/model/llm_agent.py +++ b/experiments/minif2f/model/llm_agent.py @@ -58,23 +58,27 @@ class LLMAgent(Agent): new_state = None for ii in range(self.n_trials): print(f"===============trail {str(ii)}============") - s = select_tactic.run( - server=self.server, - state=state, - goal_id=goal_id, - informal_stmt=self.informal_stmt, - informal_proof=self.informal_proof, - feedback_turns=self.feedback_turns) - tactic, new_state = s.ret_value - for m in s.messages(): - print(m["role"], ":", m["content"]) + try: + s = select_tactic.run( + server=self.server, + state=state, + goal_id=goal_id, + informal_stmt=self.informal_stmt, + informal_proof=self.informal_proof, + feedback_turns=self.feedback_turns) + tactic, new_state = s.ret_value + for m in s.messages(): + print(m["role"], ":", m["content"]) - print("\n-- new state --\n", new_state) - if tactic: - if not isinstance(tactic, Tactic): - print(colored("[Tactic] Failed:", "red"), tactic) - return None - return tactic + print("\n-- new state --\n", new_state) + if tactic: + if not isinstance(tactic, Tactic): + print(colored("[Tactic] Failed:", "red"), tactic) + return None + return tactic + except Exception as e: + print(colored(str(e), "red")) + return None return None else: self.goal_tactic_id_map[key] = i + 1