Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files138 unmodified lines139140141142142143144145146147144145146147148149150151152153154150151152153154155156156157158158159160160161162163164165166167168169170171172162163164165166167168169170171172173174175138 unmodified lines total_input_tokens = 0 total_output_tokens = 0
for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):# for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args): # Track tokens if model provides them if hasattr(agent.model, "last_input_token_count") and agent.model.last_input_token_count is not None: total_input_tokens += agent.model.last_input_token_count if hasattr(agent.model, "last_output_token_count") and agent.model.last_output_token_count is not None: total_output_tokens += agent.model.last_output_token_count# if hasattr(agent.model, "last_input_token_count") and agent.model.last_input_token_count is not None:# total_input_tokens += agent.model.last_input_token_count# if hasattr(agent.model, "last_output_token_count") and agent.model.last_output_token_count is not None:# total_output_tokens += agent.model.last_output_token_count # Handle step logs for actions and token counts if isinstance(step_log, ActionStep): if hasattr(agent.model, "last_input_token_count") and agent.model.last_input_token_count is not None: step_log.input_token_count = agent.model.last_input_token_count if hasattr(agent.model, "last_output_token_count") and agent.model.last_output_token_count is not None: step_log.output_token_count = agent.model.last_output_token_count# if isinstance(step_log, ActionStep):# if hasattr(agent.model, "last_input_token_count") and agent.model.last_input_token_count is not None:# step_log.input_token_count = agent.model.last_input_token_count# if hasattr(agent.model, "last_output_token_count") and agent.model.last_output_token_count is not None:# step_log.output_token_count = agent.model.last_output_token_count
for message in pull_messages_from_step(step_log):# for message in pull_messages_from_step(step_log): # Continue with your message processing logic pass# pass
# for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args): for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args): # Track tokens if model provides them# if hasattr(agent.model, "last_input_token_count"):# total_input_tokens += agent.model.last_input_token_count# total_output_tokens += agent.model.last_output_token_count# if isinstance(step_log, ActionStep):# step_log.input_token_count = agent.model.last_input_token_count# step_log.output_token_count = agent.model.last_output_token_count
# for message in pull_messages_from_step(# step_log,# ):# yield message if hasattr(agent.model, "last_input_token_count") and agent.model.last_input_token_count is not None: total_input_tokens += agent.model.last_input_token_count total_output_tokens += agent.model.last_output_token_count if isinstance(step_log, ActionStep): step_log.input_token_count = agent.model.last_input_token_count step_log.output_token_count = agent.model.last_output_token_count
for message in pull_messages_from_step( step_log, ): yield message
final_answer = step_log # Last log is the run's final_answer final_answer = handle_agent_output_types(final_answer)Gradio_UI.py+24-24