AmineLemsih commited on
Commit
e88760b
·
verified ·
1 Parent(s): 2742d1d

Update Gradio_UI.py

Browse files
Files changed (1) hide show
  1. Gradio_UI.py +6 -3
Gradio_UI.py CHANGED
@@ -140,12 +140,14 @@ def stream_to_gradio(
140
  total_output_tokens = 0
141
 
142
  for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):
143
- # Track tokens if model provides them
144
- if hasattr(agent.model, "last_input_token_count"):
145
  total_input_tokens += agent.model.last_input_token_count
146
- total_output_tokens += agent.model.last_output_token_count
147
  if isinstance(step_log, ActionStep):
148
  step_log.input_token_count = agent.model.last_input_token_count
 
 
 
149
  step_log.output_token_count = agent.model.last_output_token_count
150
 
151
  for message in pull_messages_from_step(
@@ -175,6 +177,7 @@ def stream_to_gradio(
175
  yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
176
 
177
 
 
178
  class GradioUI:
179
  """A one-line interface to launch your agent in Gradio"""
180
 
 
140
  total_output_tokens = 0
141
 
142
  for step_log in agent.run(task, stream=True, reset=reset_agent_memory, additional_args=additional_args):
143
+ # Patch : ne compte les tokens que si la valeur n'est pas None
144
+ if hasattr(agent.model, "last_input_token_count") and agent.model.last_input_token_count is not None:
145
  total_input_tokens += agent.model.last_input_token_count
 
146
  if isinstance(step_log, ActionStep):
147
  step_log.input_token_count = agent.model.last_input_token_count
148
+ if hasattr(agent.model, "last_output_token_count") and agent.model.last_output_token_count is not None:
149
+ total_output_tokens += agent.model.last_output_token_count
150
+ if isinstance(step_log, ActionStep):
151
  step_log.output_token_count = agent.model.last_output_token_count
152
 
153
  for message in pull_messages_from_step(
 
177
  yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
178
 
179
 
180
+
181
  class GradioUI:
182
  """A one-line interface to launch your agent in Gradio"""
183