Mandark-droid commited on
Commit
cb00de6
·
1 Parent(s): 26a1db5

Fix NoneType error in thought graph token calculation

Browse files

- Handle None values for prompt_tokens and completion_tokens
- Use 'or 0' to ensure numeric value even when field is None
- Prevents TypeError when adding None + int

Files changed (1) hide show
  1. components/thought_graph.py +2 -2
components/thought_graph.py CHANGED
@@ -196,8 +196,8 @@ def create_thought_graph(spans: List[Dict[str, Any]], trace_id: str = "Unknown")
196
  if 'tool_name' in node_data:
197
  hover += f"Tool: {node_data['tool_name']}<br>"
198
  if 'prompt_tokens' in node_data or 'completion_tokens' in node_data:
199
- prompt = node_data.get('prompt_tokens', 0)
200
- completion = node_data.get('completion_tokens', 0)
201
  hover += f"Tokens: {prompt + completion} (p:{prompt}, c:{completion})<br>"
202
  if 'cost' in node_data and node_data['cost'] is not None:
203
  hover += f"Cost: ${node_data['cost']:.6f}<br>"
 
196
  if 'tool_name' in node_data:
197
  hover += f"Tool: {node_data['tool_name']}<br>"
198
  if 'prompt_tokens' in node_data or 'completion_tokens' in node_data:
199
+ prompt = node_data.get('prompt_tokens', 0) or 0 # Handle None values
200
+ completion = node_data.get('completion_tokens', 0) or 0 # Handle None values
201
  hover += f"Tokens: {prompt + completion} (p:{prompt}, c:{completion})<br>"
202
  if 'cost' in node_data and node_data['cost'] is not None:
203
  hover += f"Cost: ${node_data['cost']:.6f}<br>"