feat: Fix vector indexing stability, add Gitea linking, enhance admin dashboard

This commit is contained in:
2025-12-07 18:42:38 +01:00
parent 7b300d1ba1
commit 9f2e599846
58 changed files with 12197 additions and 503 deletions

View File

@@ -175,21 +175,59 @@ class ChatLogger:
# Get file size
file_size = self.log_file.stat().st_size
# Count by character
# Count stats
character_counts = {}
total_tokens = 0
tokens_by_model = {}
tokens_by_role = {}
context_found_count = 0
# Simple pricing model (Blended average for OpenRouter)
# Input: ~$5/M, Output: ~$15/M -> Avg ~$10/M = $0.00001 per token
PRICE_PER_TOKEN = 0.00001
for line in lines:
try:
entry = json.loads(line)
# Character stats
char_id = entry.get('character', {}).get('id', 'unknown')
character_counts[char_id] = character_counts.get(char_id, 0) + 1
# Token stats
tokens = entry.get('tokens_estimated', 0)
total_tokens += tokens
# Model stats
model = entry.get('ai', {}).get('model', 'unknown')
tokens_by_model[model] = tokens_by_model.get(model, 0) + tokens
# Role stats
tokens_by_role[char_id] = tokens_by_role.get(char_id, 0) + tokens
# RAG stats
if entry.get('rag', {}).get('context_found'):
context_found_count += 1
except json.JSONDecodeError:
continue
total_interactions = len(lines)
context_hit_rate = round((context_found_count / total_interactions * 100), 1) if total_interactions > 0 else 0
estimated_cost = round(total_tokens * PRICE_PER_TOKEN, 4)
return {
"total_interactions": len(lines),
"total_interactions": total_interactions,
"total_tokens_estimated": total_tokens,
"estimated_cost_usd": estimated_cost,
"context_found_count": context_found_count,
"context_hit_rate_percent": context_hit_rate,
"file_size_bytes": file_size,
"file_size_mb": round(file_size / (1024 * 1024), 2),
"characters": character_counts
"characters": character_counts,
"tokens_by_model": tokens_by_model,
"tokens_by_role": tokens_by_role,
"last_updated": datetime.utcnow().isoformat() + "Z"
}
except Exception as e: