aggregating token_counts for stats over all endpoints and adjusting the color mapping

This commit is contained in:
Alpha Nerd 2025-11-20 09:22:45 +01:00
parent 3f77a8ec62
commit e0c6861f2f
2 changed files with 56 additions and 25 deletions

20
db.py
View file

@ -134,15 +134,23 @@ class TokenDatabase:
}
async def get_token_counts_for_model(self, model):
"""Get token counts for a specific model."""
"""Get token counts for a specific model, aggregated across all endpoints."""
async with aiosqlite.connect(self.db_path) as db:
async with db.execute('SELECT endpoint, model, input_tokens, output_tokens, total_tokens FROM token_counts WHERE model = ?', (model,)) as cursor:
total_input = 0
total_output = 0
total_tokens = 0
async for row in cursor:
total_input += row[2]
total_output += row[3]
total_tokens += row[4]
if total_input > 0 or total_output > 0:
return {
'endpoint': row[0],
'model': row[1],
'input_tokens': row[2],
'output_tokens': row[3],
'total_tokens': row[4]
'endpoint': 'aggregated',
'model': model,
'input_tokens': total_input,
'output_tokens': total_output,
'total_tokens': total_tokens
}
return None