Skip to content

Commit 1cd5230

Browse files
author
Maxime Brugel
committed
fix: final var
1 parent 76db8de commit 1cd5230

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎rlm/core/rlm.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,19 @@ def completion(
180180
)
181181

182182
# Check if RLM is done and has a final answer.
183-
final_answer = find_final_answer(iteration.response)
183+
final_answer_match = find_final_answer(iteration.response)
184+
final_answer: str | None = None
185+
if final_answer_match is not None:
186+
answer_type, content = final_answer_match
187+
if answer_type == "FINAL":
188+
final_answer = content
189+
elif answer_type == "FINAL_VAR":
190+
variable_name = content.strip().strip('"').strip("'")
191+
result = environment.execute_code(f"print(FINAL_VAR({variable_name!r}))")
192+
final_answer = result.stdout.strip()
193+
if final_answer == "":
194+
final_answer = result.stderr.strip() or ""
195+
184196
iteration.final_answer = final_answer
185197

186198
# If logger is used, log the iteration.
@@ -190,7 +202,7 @@ def completion(
190202
# Verbose output for this iteration
191203
self.verbose.print_iteration(iteration, i + 1)
192204

193-
if final_answer:
205+
if final_answer is not None:
194206
time_end = time.perf_counter()
195207
usage = lm_handler.get_usage_summary()
196208
self.verbose.print_final_answer(final_answer)

0 commit comments

Comments
 (0)