Skip to content

Commit f4f6176

Browse files
committed
fix: correct thresholds in llm analysis bar chart
1 parent befd11c commit f4f6176

File tree

3 files changed

+88
-28
lines changed

3 files changed

+88
-28
lines changed

src/llmAnalysis.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface ModelCardResponse {
3535
higher_is_better: boolean,
3636
score: number,
3737
thresholds: {
38-
name: string,
38+
impact: 'no_measurable' | 'very_low' | 'low' | 'moderate' | 'high' | 'severe',
3939
category: number,
4040
interpretation: string,
4141
upper: number,

src/llmAnalysisReport.hbs

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,27 @@
517517
font-weight: 600;
518518
}
519519
520-
.impact-high {
521-
background: #f8d7da;
522-
color: #721c24;
520+
.impact-no_measurable {
521+
background: #c8e6c9;
522+
color: #2e7d32;
523+
padding: 0.2rem 0.5rem;
524+
border-radius: 3px;
525+
font-size: 0.8rem;
526+
font-weight: 600;
527+
}
528+
529+
.impact-very_low {
530+
background: #26a69a;
531+
color: #ffffff;
532+
padding: 0.2rem 0.5rem;
533+
border-radius: 3px;
534+
font-size: 0.8rem;
535+
font-weight: 600;
536+
}
537+
538+
.impact-low {
539+
background: #d1ecf1;
540+
color: #0c5460;
523541
padding: 0.2rem 0.5rem;
524542
border-radius: 3px;
525543
font-size: 0.8rem;
@@ -535,9 +553,18 @@
535553
font-weight: 600;
536554
}
537555
538-
.impact-low {
539-
background: #d4edda;
540-
color: #155724;
556+
.impact-high {
557+
background: #ffeaa7;
558+
color: #b7550a;
559+
padding: 0.2rem 0.5rem;
560+
border-radius: 3px;
561+
font-size: 0.8rem;
562+
font-weight: 600;
563+
}
564+
565+
.impact-severe {
566+
background: #f8d7da;
567+
color: #721c24;
541568
padding: 0.2rem 0.5rem;
542569
border-radius: 3px;
543570
font-size: 0.8rem;
@@ -615,19 +642,31 @@
615642
<div class="legend-items">
616643
<div class="legend-item">
617644
<div class="legend-color" style="background-color: #F44336;"></div>
618-
<span>High Impact</span>
645+
<span>Severe</span>
646+
</div>
647+
<div class="legend-item">
648+
<div class="legend-color" style="background-color: #FF5722;"></div>
649+
<span>High</span>
619650
</div>
620651
<div class="legend-item">
621652
<div class="legend-color" style="background-color: #FF9800;"></div>
622-
<span>Moderate Impact</span>
653+
<span>Moderate</span>
654+
</div>
655+
<div class="legend-item">
656+
<div class="legend-color" style="background-color: #8BC34A;"></div>
657+
<span>Low</span>
658+
</div>
659+
<div class="legend-item">
660+
<div class="legend-color" style="background-color: #26A69A;"></div>
661+
<span>Very Low</span>
623662
</div>
624663
<div class="legend-item">
625-
<div class="legend-color" style="background-color: #4CAF50;"></div>
626-
<span>Low Impact</span>
664+
<div class="legend-color" style="background-color: #C8E6C9;"></div>
665+
<span>No Measurable Impact</span>
627666
</div>
628667
<div class="legend-item">
629668
<div class="legend-color" style="background-color: #9E9E9E;"></div>
630-
<span>Unknown Impact</span>
669+
<span>Unknown</span>
631670
</div>
632671
</div>
633672
</div>
@@ -736,7 +775,7 @@
736775
<tr id="metric-{{taskName}}-{{name}}">
737776
<td><span class="metric-name">{{name}}</span></td>
738777
<td><span class="metric-score">{{score}}</span></td>
739-
<td><span class="impact-{{impactLevel}}">{{impactLevel}}</span></td>
778+
<td><span class="impact-{{impactLevel}}">{{impactDisplayName}}</span></td>
740779
<td><span class="metric-categories">{{categories}}</span></td>
741780
<td>
742781
{{#relatedGuardrails.length}}

src/llmAnalysisReportPanel.ts

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,41 @@ export class LLMAnalysisReportPanel {
5656
LLMAnalysisReportPanel.currentPanel = new LLMAnalysisReportPanel(column);
5757
}
5858

59-
private getImpactLevel(metric: any): string {
59+
private getImpactLevel(metric: ModelCardResponse['tasks'][0]['metrics'][0]): string {
6060
if (!metric.thresholds || metric.thresholds.length === 0) {
6161
return 'unknown';
6262
}
6363

6464
const score = metric.score;
6565
for (const threshold of metric.thresholds) {
6666
if (score >= threshold.lower && score <= threshold.upper) {
67-
// Map threshold categories to impact levels
68-
if (threshold.category <= 2) {
69-
return 'low';
70-
}
71-
if (threshold.category <= 4) {
72-
return 'moderate';
73-
}
74-
return 'high';
67+
return threshold.impact;
7568
}
7669
}
7770
return 'unknown';
7871
}
7972

8073
private getImpactColor(impactLevel: string): string {
8174
switch (impactLevel) {
82-
case 'low': return '#4CAF50'; // Green
83-
case 'moderate': return '#FF9800'; // Orange
84-
case 'high': return '#F44336'; // Red
85-
default: return '#9E9E9E'; // Gray
75+
case 'no_measurable': return '#C8E6C9'; // Visible light green
76+
case 'very_low': return '#26A69A'; // Blue-green
77+
case 'low': return '#8BC34A'; // Light green
78+
case 'moderate': return '#FF9800'; // Orange
79+
case 'high': return '#FF5722'; // Red-orange
80+
case 'severe': return '#F44336'; // Red
81+
default: return '#9E9E9E'; // Gray
82+
}
83+
}
84+
85+
private getImpactDisplayName(impactLevel: string): string {
86+
switch (impactLevel) {
87+
case 'no_measurable': return 'No Measurable Impact';
88+
case 'very_low': return 'Very Low';
89+
case 'low': return 'Low';
90+
case 'moderate': return 'Moderate';
91+
case 'high': return 'High';
92+
case 'severe': return 'Severe';
93+
default: return 'Unknown';
8694
}
8795
}
8896

@@ -154,7 +162,17 @@ export class LLMAnalysisReportPanel {
154162

155163
// Sort by required metrics first, then by impact level
156164
allMetrics.sort((a, b) => {
157-
const impactOrder: { [key: string]: number } = { 'high': 0, 'moderate': 1, 'low': 2, 'unknown': 3 };
165+
const impactOrder: { [key: string]: number } = {
166+
'severe': 0,
167+
'high': 1,
168+
'moderate': 2,
169+
'low': 3,
170+
// eslint-disable-next-line @typescript-eslint/naming-convention
171+
'very_low': 4,
172+
// eslint-disable-next-line @typescript-eslint/naming-convention
173+
'no_measurable': 5,
174+
'unknown': 6,
175+
};
158176
return impactOrder[a.impactLevel] - impactOrder[b.impactLevel];
159177
});
160178

@@ -199,12 +217,14 @@ export class LLMAnalysisReportPanel {
199217
const metricKey = `${task.name}:${metric.name}`;
200218
const relatedGuardrailIds = metricToGuardrails.get(metricKey) || [];
201219

220+
const impactLevel = this.getImpactLevel(metric);
202221
return {
203222
name: metric.name,
204223
score: metric.score,
205224
categories: metric.categories,
206225
higherIsBetter: metric.higher_is_better,
207-
impactLevel: this.getImpactLevel(metric),
226+
impactLevel: impactLevel,
227+
impactDisplayName: this.getImpactDisplayName(impactLevel),
208228
relatedGuardrails: relatedGuardrailIds
209229
.filter(id => recommendedGuardrails.some(g => g.id === id))
210230
.map(id => {
@@ -222,6 +242,7 @@ export class LLMAnalysisReportPanel {
222242
data: JSON.stringify(allMetrics.map(m => m.metric.score)),
223243
colors: JSON.stringify(allMetrics.map(m => this.getImpactColor(m.impactLevel))),
224244
impactLevels: JSON.stringify(allMetrics.map(m => m.impactLevel)),
245+
impactDisplayNames: JSON.stringify(allMetrics.map(m => this.getImpactDisplayName(m.impactLevel))),
225246
tasks: enrichedTasks,
226247
contextData: {
227248
modelSource: resp.config.model_source,

0 commit comments

Comments
 (0)