Spaces:
Sleeping
Sleeping
Update Gradio_UI.py
Browse files- Gradio_UI.py +19 -10
Gradio_UI.py
CHANGED
|
@@ -140,18 +140,27 @@ 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 (some backends return None)
|
| 144 |
-
in_tok = getattr(agent.model, "last_input_token_count", None)
|
| 145 |
-
out_tok = getattr(agent.model, "last_output_token_count", None)
|
| 146 |
|
| 147 |
-
if isinstance(in_tok, int):
|
| 148 |
-
|
| 149 |
-
if isinstance(out_tok, int):
|
| 150 |
-
|
| 151 |
|
| 152 |
-
if isinstance(step_log, ActionStep):
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
for message in pull_messages_from_step(
|
| 157 |
step_log,
|
|
|
|
| 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 (some backends return None)
|
| 144 |
+
# in_tok = getattr(agent.model, "last_input_token_count", None)
|
| 145 |
+
# out_tok = getattr(agent.model, "last_output_token_count", None)
|
| 146 |
|
| 147 |
+
# if isinstance(in_tok, int):
|
| 148 |
+
# total_input_tokens += in_tok
|
| 149 |
+
# if isinstance(out_tok, int):
|
| 150 |
+
# total_output_tokens += out_tok
|
| 151 |
|
| 152 |
+
# if isinstance(step_log, ActionStep):
|
| 153 |
+
# step_log.input_token_count = in_tok if isinstance(in_tok, int) else 0
|
| 154 |
+
# step_log.output_token_count = out_tok if isinstance(out_tok, int) else 0
|
| 155 |
+
|
| 156 |
+
# Track tokens if model provides them
|
| 157 |
+
if hasattr(agent.model, "last_input_token_count"):
|
| 158 |
+
total_input_tokens += agent.model.last_input_token_count
|
| 159 |
+
total_output_tokens += agent.model.last_output_token_count
|
| 160 |
+
if isinstance(step_log, ActionStep):
|
| 161 |
+
step_log.input_token_count = agent.model.last_input_token_count
|
| 162 |
+
step_log.output_token_count = agent.model.last_output_token_count
|
| 163 |
+
|
| 164 |
|
| 165 |
for message in pull_messages_from_step(
|
| 166 |
step_log,
|