Skip to content

Commit

Permalink
Fix last step missing duration
Browse files Browse the repository at this point in the history
  • Loading branch information
aymeric-roucher committed Nov 11, 2024
1 parent a131fd0 commit c73eeb7
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/transformers/agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ def stream_run(self, task: str):
self.logger.error(error_message, exc_info=1)
final_answer = self.provide_final_answer(task)
final_step_log["final_answer"] = final_answer
final_step_log["step_duration"] = 0
for callback in self.step_callbacks:
callback(final_step_log)
yield final_step_log
Expand Down Expand Up @@ -874,6 +875,7 @@ def direct_run(self, task: str):
self.logger.error(error_message, exc_info=1)
final_answer = self.provide_final_answer(task)
final_step_log["final_answer"] = final_answer
final_step_log["step_duration"] = 0
for callback in self.step_callbacks:
callback(final_step_log)

Expand Down
2 changes: 1 addition & 1 deletion src/transformers/agents/monitoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def __init__(self, tracked_llm_engine):
self.total_output_token_count = 0

def update_metrics(self, step_log):
step_duration = step_log.get("step_duration", None)
step_duration = step_log["step_duration"]
self.step_durations.append(step_duration)
logger.info(f"Step {len(self.step_durations)}:")
logger.info(f"- Time taken: {step_duration:.2f} seconds (valid only if step succeeded)")
Expand Down

0 comments on commit c73eeb7

Please sign in to comment.