Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files138 unmodified lines139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175138 unmodified linestotal_input_tokens = 0total_output_tokens = 0for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):# Track tokens if model provides themif 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_countif 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 countsif 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_countif 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_countfor message in pull_messages_from_step(step_log):# Continue with your message processing logicpass# 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 messagefinal_answer = step_log # Last log is the run's final_answerfinal_answer = handle_agent_output_types(final_answer)138 unmodified lines139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175138 unmodified linestotal_input_tokens = 0total_output_tokens = 0# 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# 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# for message in pull_messages_from_step(step_log):# Continue with your message processing logic# passfor step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):# Track tokens if model provides themif 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_counttotal_output_tokens += agent.model.last_output_token_countif isinstance(step_log, ActionStep):step_log.input_token_count = agent.model.last_input_token_countstep_log.output_token_count = agent.model.last_output_token_countfor message in pull_messages_from_step(step_log,):yield messagefinal_answer = step_log # Last log is the run's final_answerfinal_answer = handle_agent_output_types(final_answer)
Gradio_UI.py+24-24