Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Split LLM and embedding token usage into separate cards and charts on admin stats

Murtaza Nasire41612ed300e
diff --git a/src/api/admin.py b/src/api/admin.py
index 8b0128c8..a5bf692f 100644
--- a/src/api/admin.py
+++ b/src/api/admin.py
@@ -449,20 +449,20 @@ def admin_get_token_stats():
from sqlalchemy import func, extract
from datetime import date
- # Get today's usage
+ # Get today's usage (already split into llm_/embedding_ buckets)
today_usage = token_tracker.get_today_usage()
- # Get current month usage for all users
+ # Get current month usage for all users (also bucketed by the tracker)
monthly_stats = token_tracker.get_monthly_stats(months=1)
- current_month = monthly_stats[-1] if monthly_stats else {'tokens': 0, 'cost': 0}
+ current_month = monthly_stats[-1] if monthly_stats else {
+ 'tokens': 0, 'cost': 0,
+ 'llm_tokens': 0, 'llm_cost': 0,
+ 'embedding_tokens': 0, 'embedding_cost': 0,
+ }
# Get per-user stats for current month
user_stats = token_tracker.get_user_stats()
- # Calculate totals
- total_monthly_tokens = current_month.get('tokens', 0)
- total_monthly_cost = current_month.get('cost', 0)
-
# Per-operation breakdown for the current month so the UI can show
# how the total splits across summarization, chat, embedding, etc.
today = date.today()
@@ -481,6 +481,7 @@ def admin_get_token_stats():
'tokens': int(r.tokens or 0),
'cost': float(r.cost or 0.0),
'requests': int(r.requests or 0),
+ 'is_embedding': token_tracker.is_embedding_op(r.operation_type),
}
for r in op_rows
]
@@ -488,8 +489,12 @@ def admin_get_token_stats():
return jsonify({
'today': today_usage,
'current_month': {
- 'tokens': total_monthly_tokens,
- 'cost': total_monthly_cost,
+ 'tokens': current_month.get('tokens', 0),
+ 'cost': current_month.get('cost', 0),
+ 'llm_tokens': current_month.get('llm_tokens', 0),
+ 'llm_cost': current_month.get('llm_cost', 0),
+ 'embedding_tokens': current_month.get('embedding_tokens', 0),
+ 'embedding_cost': current_month.get('embedding_cost', 0),
'by_operation': by_operation,
},
'user_count_with_usage': len([u for u in user_stats if u['current_usage'] > 0]),
diff --git a/src/services/token_tracking.py b/src/services/token_tracking.py
index d05390da..7bd39a67 100644
--- a/src/services/token_tracking.py
+++ b/src/services/token_tracking.py
@@ -24,9 +24,20 @@ class TokenTracker:
'title_generation',
'event_extraction',
'query_routing',
- 'query_enrichment'
+ 'query_enrichment',
+ 'embedding',
]
+ # Token magnitudes and per-token costs differ by orders of magnitude
+ # between LLM completions and embedding calls, so dashboards must keep
+ # them in separate visualizations. Anything in EMBEDDING_OPERATIONS is
+ # bucketed apart from LLM usage.
+ EMBEDDING_OPERATIONS = frozenset({'embedding'})
+
+ @classmethod
+ def is_embedding_op(cls, operation_type):
+ return operation_type in cls.EMBEDDING_OPERATIONS
+
def record_usage(
self,
user_id: int,
@@ -157,7 +168,12 @@ class TokenTracker:
return (True, 0, None)
def get_daily_stats(self, days: int = 30, user_id: int = None) -> List[Dict]:
- """Get daily token usage for charts."""
+ """Get daily token usage for charts.
+
+ Each entry includes both a combined total and per-bucket totals
+ ('llm_tokens'/'llm_cost' vs 'embedding_tokens'/'embedding_cost') so
+ dashboards can render the two streams as independent series.
+ """
start_date = date.today() - timedelta(days=days - 1)
query = db.session.query(
@@ -177,10 +193,27 @@ class TokenTracker:
for r in results:
date_str = r.date.isoformat()
if date_str not in stats:
- stats[date_str] = {'date': date_str, 'total': 0, 'cost': 0.0, 'by_operation': {}}
- stats[date_str]['total'] += r.tokens or 0
- stats[date_str]['cost'] += r.cost or 0
- stats[date_str]['by_operation'][r.operation_type] = r.tokens or 0
+ stats[date_str] = {
+ 'date': date_str,
+ 'total': 0,
+ 'cost': 0.0,
+ 'llm_tokens': 0,
+ 'llm_cost': 0.0,
+ 'embedding_tokens': 0,
+ 'embedding_cost': 0.0,
+ 'by_operation': {},
+ }
+ tokens = r.tokens or 0
+ cost = r.cost or 0
+ stats[date_str]['total'] += tokens
+ stats[date_str]['cost'] += cost
+ if self.is_embedding_op(r.operation_type):
+ stats[date_str]['embedding_tokens'] += tokens
+ stats[date_str]['embedding_cost'] += cost
+ else:
+ stats[date_str]['llm_tokens'] += tokens
+ stats[date_str]['llm_cost'] += cost
+ stats[date_str]['by_operation'][r.operation_type] = tokens
# Fill in missing dates with zeros
all_dates = []
@@ -188,33 +221,62 @@ class TokenTracker:
while current <= date.today():
date_str = current.isoformat()
if date_str not in stats:
- stats[date_str] = {'date': date_str, 'total': 0, 'cost': 0.0, 'by_operation': {}}
+ stats[date_str] = {
+ 'date': date_str,
+ 'total': 0,
+ 'cost': 0.0,
+ 'llm_tokens': 0,
+ 'llm_cost': 0.0,
+ 'embedding_tokens': 0,
+ 'embedding_cost': 0.0,
+ 'by_operation': {},
+ }
all_dates.append(date_str)
current += timedelta(days=1)
return [stats[d] for d in sorted(all_dates)]
def get_monthly_stats(self, months: int = 12) -> List[Dict]:
- """Get monthly token usage for charts."""
+ """Get monthly token usage for charts.
+
+ Each month includes both combined totals and per-bucket totals
+ (LLM vs embedding) so the two streams can be visualised separately.
+ """
results = db.session.query(
extract('year', TokenUsage.date).label('year'),
extract('month', TokenUsage.date).label('month'),
+ TokenUsage.operation_type,
func.sum(TokenUsage.total_tokens).label('tokens'),
func.sum(TokenUsage.cost).label('cost')
- ).group_by('year', 'month').order_by('year', 'month').all()
+ ).group_by('year', 'month', TokenUsage.operation_type).order_by('year', 'month').all()
- # Get last N months
- monthly_data = [
- {
- 'year': int(r.year),
- 'month': int(r.month),
- 'tokens': r.tokens or 0,
- 'cost': r.cost or 0
- }
- for r in results
- ]
+ buckets = {}
+ for r in results:
+ key = (int(r.year), int(r.month))
+ if key not in buckets:
+ buckets[key] = {
+ 'year': key[0],
+ 'month': key[1],
+ 'tokens': 0,
+ 'cost': 0.0,
+ 'llm_tokens': 0,
+ 'llm_cost': 0.0,
+ 'embedding_tokens': 0,
+ 'embedding_cost': 0.0,
+ }
+ tokens = r.tokens or 0
+ cost = r.cost or 0
+ buckets[key]['tokens'] += tokens
+ buckets[key]['cost'] += cost
+ if self.is_embedding_op(r.operation_type):
+ buckets[key]['embedding_tokens'] += tokens
+ buckets[key]['embedding_cost'] += cost
+ else:
+ buckets[key]['llm_tokens'] += tokens
+ buckets[key]['llm_cost'] += cost
- return monthly_data[-months:] if len(monthly_data) > months else monthly_data
+ ordered = [buckets[k] for k in sorted(buckets.keys())]
+ return ordered[-months:] if len(ordered) > months else ordered
def get_user_stats(self) -> List[Dict]:
"""Get per-user token usage breakdown for current month."""
@@ -247,10 +309,11 @@ class TokenTracker:
]
def get_today_usage(self, user_id: int = None) -> Dict:
- """Get today's token usage."""
+ """Get today's token usage, split into LLM and embedding buckets."""
today = date.today()
query = db.session.query(
+ TokenUsage.operation_type,
func.sum(TokenUsage.total_tokens).label('tokens'),
func.sum(TokenUsage.cost).label('cost')
).filter(TokenUsage.date == today)
@@ -258,12 +321,28 @@ class TokenTracker:
if user_id:
query = query.filter(TokenUsage.user_id == user_id)
- result = query.first()
+ rows = query.group_by(TokenUsage.operation_type).all()
- return {
- 'tokens': result.tokens or 0,
- 'cost': result.cost or 0
+ out = {
+ 'tokens': 0,
+ 'cost': 0.0,
+ 'llm_tokens': 0,
+ 'llm_cost': 0.0,
+ 'embedding_tokens': 0,
+ 'embedding_cost': 0.0,
}
+ for r in rows:
+ tokens = r.tokens or 0
+ cost = r.cost or 0
+ out['tokens'] += tokens
+ out['cost'] += cost
+ if self.is_embedding_op(r.operation_type):
+ out['embedding_tokens'] += tokens
+ out['embedding_cost'] += cost
+ else:
+ out['llm_tokens'] += tokens
+ out['llm_cost'] += cost
+ return out
# Singleton instance
diff --git a/templates/admin.html b/templates/admin.html
index 299465a7..df741cd8 100644
--- a/templates/admin.html
+++ b/templates/admin.html
@@ -409,56 +409,61 @@
<!-- Token Stats and Per-User Usage Side by Side -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6 mb-6">
- <!-- Token Usage Summary Cards (2x2 grid) -->
+ <!-- Token Usage Summary Cards (LLM and Embedding tracked separately) -->
<div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] shadow-sm">
<h5 class="text-md font-medium text-[var(--text-secondary)] mb-3">Usage Summary</h5>
- <div class="grid grid-cols-2 gap-3">
- <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
- <div class="flex items-center">
- <div class="p-2 rounded-full bg-[var(--bg-info-light)] text-[var(--text-info-strong)]">
- <i class="fas fa-calendar-day"></i>
- </div>
- <div class="ml-3">
- <p class="text-xs text-[var(--text-muted)]">Today</p>
- <p class="text-lg font-semibold text-[var(--text-primary)]">${ tokenStats.today?.tokens?.toLocaleString() || 0 }</p>
- </div>
+
+ <!-- LLM bucket (chat, summarization, title, etc.) -->
+ <div class="mb-3">
+ <p class="text-xs uppercase tracking-wide text-[var(--text-muted)] mb-2"><i class="fas fa-robot mr-1"></i> LLM</p>
+ <div class="grid grid-cols-3 gap-3">
+ <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
+ <p class="text-xs text-[var(--text-muted)]">Today</p>
+ <p class="text-lg font-semibold text-[var(--text-primary)]">${ (tokenStats.today?.llm_tokens || 0).toLocaleString() }</p>
</div>
- </div>
- <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
- <div class="flex items-center">
- <div class="p-2 rounded-full bg-[var(--bg-success-light)] text-[var(--text-success-strong)]">
- <i class="fas fa-calendar-alt"></i>
- </div>
- <div class="ml-3">
- <p class="text-xs text-[var(--text-muted)]">This Month</p>
- <p class="text-lg font-semibold text-[var(--text-primary)]">${ tokenStats.current_month?.tokens?.toLocaleString() || 0 }</p>
- </div>
+ <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
+ <p class="text-xs text-[var(--text-muted)]">This Month</p>
+ <p class="text-lg font-semibold text-[var(--text-primary)]">${ (tokenStats.current_month?.llm_tokens || 0).toLocaleString() }</p>
+ </div>
+ <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
+ <p class="text-xs text-[var(--text-muted)]">Monthly Cost</p>
+ <p class="text-lg font-semibold text-[var(--text-primary)]">$${ (tokenStats.current_month?.llm_cost || 0).toFixed(4) }</p>
</div>
</div>
- <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
- <div class="flex items-center">
- <div class="p-2 rounded-full bg-[var(--bg-warn-light)] text-[var(--text-warn-strong)]">
- <i class="fas fa-dollar-sign"></i>
- </div>
- <div class="ml-3">
- <p class="text-xs text-[var(--text-muted)]">Monthly Cost</p>
- <p class="text-lg font-semibold text-[var(--text-primary)]">$${ (tokenStats.current_month?.cost || 0).toFixed(4) }</p>
- </div>
+ </div>
+
+ <!-- Embedding bucket -->
+ <div class="mb-3">
+ <p class="text-xs uppercase tracking-wide text-[var(--text-muted)] mb-2"><i class="fas fa-vector-square mr-1"></i> Embeddings</p>
+ <div class="grid grid-cols-3 gap-3">
+ <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
+ <p class="text-xs text-[var(--text-muted)]">Today</p>
+ <p class="text-lg font-semibold text-[var(--text-primary)]">${ (tokenStats.today?.embedding_tokens || 0).toLocaleString() }</p>
+ </div>
+ <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
+ <p class="text-xs text-[var(--text-muted)]">This Month</p>
+ <p class="text-lg font-semibold text-[var(--text-primary)]">${ (tokenStats.current_month?.embedding_tokens || 0).toLocaleString() }</p>
+ </div>
+ <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
+ <p class="text-xs text-[var(--text-muted)]">Monthly Cost</p>
+ <p class="text-lg font-semibold text-[var(--text-primary)]">$${ (tokenStats.current_month?.embedding_cost || 0).toFixed(4) }</p>
</div>
</div>
- <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
- <div class="flex items-center">
- <div class="p-2 rounded-full" :class="tokenStats.users_at_100_percent > 0 ? 'bg-[var(--bg-danger-light)] text-[var(--text-danger-strong)]' : 'bg-[var(--bg-accent)] text-[var(--text-accent)]'">
- <i class="fas fa-exclamation-triangle"></i>
- </div>
- <div class="ml-3">
- <p class="text-xs text-[var(--text-muted)]">Warnings</p>
- <p class="text-lg font-semibold">
- <span v-if="tokenStats.users_at_100_percent > 0" class="text-[var(--text-danger-strong)]">${ tokenStats.users_at_100_percent } blocked</span>
- <span v-else-if="tokenStats.users_over_80_percent > 0" class="text-[var(--text-warn-strong)]">${ tokenStats.users_over_80_percent } warning</span>
- <span v-else class="text-[var(--text-success-strong)]">None</span>
- </p>
- </div>
+ </div>
+
+ <!-- Budget warnings -->
+ <div class="p-3 bg-[var(--bg-secondary)] rounded-lg border border-[var(--border-primary)]">
+ <div class="flex items-center">
+ <div class="p-2 rounded-full" :class="tokenStats.users_at_100_percent > 0 ? 'bg-[var(--bg-danger-light)] text-[var(--text-danger-strong)]' : 'bg-[var(--bg-accent)] text-[var(--text-accent)]'">
+ <i class="fas fa-exclamation-triangle"></i>
+ </div>
+ <div class="ml-3">
+ <p class="text-xs text-[var(--text-muted)]">Budget Warnings</p>
+ <p class="text-sm font-semibold">
+ <span v-if="tokenStats.users_at_100_percent > 0" class="text-[var(--text-danger-strong)]">${ tokenStats.users_at_100_percent } blocked</span>
+ <span v-else-if="tokenStats.users_over_80_percent > 0" class="text-[var(--text-warn-strong)]">${ tokenStats.users_over_80_percent } warning</span>
+ <span v-else class="text-[var(--text-success-strong)]">None</span>
+ </p>
</div>
</div>
</div>
@@ -523,22 +528,23 @@
</div>
</div>
- <!-- Token Usage Charts -->
+ <!-- Token Usage Charts (LLM and Embeddings shown separately) -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
- <!-- Daily Usage Chart -->
<div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] shadow-sm">
- <h5 class="text-md font-medium text-[var(--text-secondary)] mb-3">Daily Token Usage (Last 30 Days)</h5>
- <div class="h-64">
- <canvas id="dailyTokenChart"></canvas>
- </div>
+ <h5 class="text-md font-medium text-[var(--text-secondary)] mb-3">Daily LLM Tokens (Last 30 Days)</h5>
+ <div class="h-64"><canvas id="dailyTokenChart"></canvas></div>
</div>
-
- <!-- Monthly Usage Chart -->
<div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] shadow-sm">
- <h5 class="text-md font-medium text-[var(--text-secondary)] mb-3">Monthly Token Usage (Last 12 Months)</h5>
- <div class="h-64">
- <canvas id="monthlyTokenChart"></canvas>
- </div>
+ <h5 class="text-md font-medium text-[var(--text-secondary)] mb-3">Daily Embedding Tokens (Last 30 Days)</h5>
+ <div class="h-64"><canvas id="dailyEmbeddingChart"></canvas></div>
+ </div>
+ <div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] shadow-sm">
+ <h5 class="text-md font-medium text-[var(--text-secondary)] mb-3">Monthly LLM Tokens (Last 12 Months)</h5>
+ <div class="h-64"><canvas id="monthlyTokenChart"></canvas></div>
+ </div>
+ <div class="bg-[var(--bg-tertiary)] p-4 rounded-lg border border-[var(--border-primary)] shadow-sm">
+ <h5 class="text-md font-medium text-[var(--text-secondary)] mb-3">Monthly Embedding Tokens (Last 12 Months)</h5>
+ <div class="h-64"><canvas id="monthlyEmbeddingChart"></canvas></div>
</div>
</div>
</div>
@@ -1831,6 +1837,8 @@ Summarization Instructions:
const transcriptionUserStats = ref([]);
const dailyTokenChart = ref(null);
const monthlyTokenChart = ref(null);
+ const dailyEmbeddingChart = ref(null);
+ const monthlyEmbeddingChart = ref(null);
const settings = ref([]);
const isLoadingUsers = ref(true);
const isLoadingSettings = ref(false);
@@ -2026,18 +2034,15 @@ Summarization Instructions:
const loadTokenCharts = async () => {
try {
- // Load daily stats
const dailyResponse = await fetch('/admin/token-stats/daily?days=30');
if (dailyResponse.ok) {
- const dailyData = await dailyResponse.json();
- renderDailyChart(dailyData.stats);
+ const { stats } = await dailyResponse.json();
+ renderDailyChart(stats);
}
-
- // Load monthly stats
const monthlyResponse = await fetch('/admin/token-stats/monthly?months=12');
if (monthlyResponse.ok) {
- const monthlyData = await monthlyResponse.json();
- renderMonthlyChart(monthlyData.stats);
+ const { stats } = await monthlyResponse.json();
+ renderMonthlyChart(stats);
}
} catch (error) {
console.error('Error loading token charts:', error);
@@ -2064,84 +2069,66 @@ Summarization Instructions:
}
};
- const renderDailyChart = (data) => {
- const ctx = document.getElementById('dailyTokenChart');
+ // Shared bar-chart factory: builds either the LLM or embedding
+ // daily chart against its own canvas. LLM and embedding tokens
+ // never share a chart since their magnitudes and per-token
+ // costs differ by orders of magnitude.
+ const _renderDailyBar = (canvasId, ref_, dataField, displayLabel, colorRgb) => {
+ const ctx = document.getElementById(canvasId);
if (!ctx) return;
-
- // Destroy existing chart if any
- if (dailyTokenChart.value) {
- dailyTokenChart.value.destroy();
- }
-
- const labels = data.map(d => d.date);
- const tokens = data.map(d => d.total);
-
- // Detect dark mode
+ if (ref_.value) ref_.value.destroy();
const isDark = document.documentElement.classList.contains('dark');
const textColor = isDark ? '#9ca3af' : '#6b7280';
const gridColor = isDark ? '#374151' : '#e5e7eb';
-
- dailyTokenChart.value = new Chart(ctx, {
+ ref_.value = new Chart(ctx, {
type: 'bar',
data: {
- labels: labels,
+ labels: window._dailyLabels || [],
datasets: [{
- label: 'Tokens',
- data: tokens,
- backgroundColor: isDark ? 'rgba(99, 102, 241, 0.7)' : 'rgba(79, 70, 229, 0.7)',
- borderColor: isDark ? 'rgba(99, 102, 241, 1)' : 'rgba(79, 70, 229, 1)',
+ label: displayLabel,
+ data: window._dailyData ? window._dailyData.map(d => d[dataField] || 0) : [],
+ backgroundColor: `rgba(${colorRgb}, ${isDark ? 0.7 : 0.7})`,
+ borderColor: `rgba(${colorRgb}, 1)`,
borderWidth: 1
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
- plugins: {
- legend: { display: false }
- },
+ plugins: { legend: { display: false } },
scales: {
- x: {
- ticks: { color: textColor, maxRotation: 45, minRotation: 45 },
- grid: { color: gridColor }
- },
- y: {
- beginAtZero: true,
- ticks: { color: textColor },
- grid: { color: gridColor }
- }
+ x: { ticks: { color: textColor, maxRotation: 45, minRotation: 45 }, grid: { color: gridColor } },
+ y: { beginAtZero: true, ticks: { color: textColor }, grid: { color: gridColor } }
}
}
});
};
- const renderMonthlyChart = (data) => {
- const ctx = document.getElementById('monthlyTokenChart');
- if (!ctx) return;
-
- // Destroy existing chart if any
- if (monthlyTokenChart.value) {
- monthlyTokenChart.value.destroy();
- }
-
- const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
- const labels = data.map(d => `${monthNames[d.month - 1]} ${d.year}`);
- const tokens = data.map(d => d.tokens);
+ const renderDailyChart = (data) => {
+ window._dailyLabels = data.map(d => d.date);
+ window._dailyData = data;
+ _renderDailyBar('dailyTokenChart', dailyTokenChart, 'llm_tokens', 'LLM tokens', '79, 70, 229');
+ _renderDailyBar('dailyEmbeddingChart', dailyEmbeddingChart, 'embedding_tokens', 'Embedding tokens', '34, 197, 94');
+ };
- // Detect dark mode
+ // Shared line-chart factory for monthly LLM vs embedding usage.
+ const _renderMonthlyLine = (canvasId, ref_, labels, values, displayLabel, colorRgb) => {
+ const ctx = document.getElementById(canvasId);
+ if (!ctx) return;
+ if (ref_.value) ref_.value.destroy();
const isDark = document.documentElement.classList.contains('dark');
const textColor = isDark ? '#9ca3af' : '#6b7280';
const gridColor = isDark ? '#374151' : '#e5e7eb';
-
- monthlyTokenChart.value = new Chart(ctx, {
+ ref_.value = new Chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
- label: 'Tokens',
- data: tokens,
+ label: displayLabel,
+ data: values,
fill: true,
- backgroundColor: isDark ? 'rgba(34, 197, 94, 0.2)' : 'rgba(22, 163, 74, 0.2)',
- borderColor: isDark ? 'rgba(34, 197, 94, 1)' : 'rgba(22, 163, 74, 1)',
+ backgroundColor: `rgba(${colorRgb}, 0.2)`,
+ borderColor: `rgba(${colorRgb}, 1)`,
borderWidth: 2,
tension: 0.3
}]
@@ -2149,24 +2136,24 @@ Summarization Instructions:
options: {
responsive: true,
maintainAspectRatio: false,
- plugins: {
- legend: { display: false }
- },
+ plugins: { legend: { display: false } },
scales: {
- x: {
- ticks: { color: textColor },
- grid: { color: gridColor }
- },
- y: {
- beginAtZero: true,
- ticks: { color: textColor },
- grid: { color: gridColor }
- }
+ x: { ticks: { color: textColor }, grid: { color: gridColor } },
+ y: { beginAtZero: true, ticks: { color: textColor }, grid: { color: gridColor } }
}
}
});
};
+ const renderMonthlyChart = (data) => {
+ const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
+ const labels = data.map(d => `${monthNames[d.month - 1]} ${d.year}`);
+ const llm = data.map(d => d.llm_tokens || 0);
+ const emb = data.map(d => d.embedding_tokens || 0);
+ _renderMonthlyLine('monthlyTokenChart', monthlyTokenChart, labels, llm, 'LLM tokens', '22, 163, 74');
+ _renderMonthlyLine('monthlyEmbeddingChart', monthlyEmbeddingChart, labels, emb, 'Embedding tokens', '79, 70, 229');
+ };
+
const showEditSettingModal = ref(false);
const editingSetting = ref(null);
const settingNewValue = ref('');