kpfadnis commited on
Commit
3dffb90
·
1 Parent(s): a810633

fix (RAG): Crash due to missing context in RAG.

Browse files

Signed-off-by: Kshitij Fadnis <[email protected]>

src/types.ts CHANGED
@@ -99,6 +99,7 @@ export interface Metric {
99
  readonly aggregator?: string;
100
  values?: MetricValue[];
101
  range?: number[];
 
102
  minValue?: number | MetricValue;
103
  maxValue?: number | MetricValue;
104
  }
 
99
  readonly aggregator?: string;
100
  values?: MetricValue[];
101
  range?: number[];
102
+ order?: 'ascending' | 'descending';
103
  minValue?: number | MetricValue;
104
  maxValue?: number | MetricValue;
105
  }
src/views/performance-overview/PerformanceOverview.tsx CHANGED
@@ -86,6 +86,7 @@ function calculateRanks(
86
  score: number;
87
  rank: number;
88
  std?: number;
 
89
  levels: { low: number; medium: number; high: number };
90
  }[],
91
  ) {
@@ -97,15 +98,26 @@ function calculateRanks(
97
  std?: number;
98
  }[];
99
  } = {};
 
100
  for (const entry of data) {
101
  if (peformancePerMetric.hasOwnProperty(entry.metric)) {
102
  peformancePerMetric[entry.metric].push(entry);
103
  } else {
104
  peformancePerMetric[entry.metric] = [entry];
105
  }
 
 
 
 
106
  }
107
- for (const performance of Object.values(peformancePerMetric)) {
108
- performance.sort((a, b) => (a.score > b.score ? -1 : 1));
 
 
 
 
 
 
109
  let rank = 0;
110
  performance.forEach((entry, idx) => {
111
  if (idx !== 0 && entry.score === performance[idx - 1].score) {
@@ -417,6 +429,7 @@ export default function PerformanceOverview({
417
  rank: number;
418
  size: number;
419
  levels: { low: number; medium: number; high: number };
 
420
  }[] = [];
421
  let aData: {
422
  model: string;
@@ -426,6 +439,7 @@ export default function PerformanceOverview({
426
  rank: number;
427
  size: number;
428
  levels: { low: number; medium: number; high: number };
 
429
  }[] = [];
430
 
431
  const performancePerModel: {
@@ -592,6 +606,9 @@ export default function PerformanceOverview({
592
  (statistics.std / selectedTasksCount).toFixed(2),
593
  ),
594
  levels: statistics.levels,
 
 
 
595
  });
596
  } else if (eligibleMetrics[metric].author === 'algorithm') {
597
  aData.push({
@@ -606,6 +623,9 @@ export default function PerformanceOverview({
606
  (statistics.std / selectedTasksCount).toFixed(2),
607
  ),
608
  levels: statistics.levels,
 
 
 
609
  });
610
  }
611
  }
 
86
  score: number;
87
  rank: number;
88
  std?: number;
89
+ order?: 'ascending' | 'descending';
90
  levels: { low: number; medium: number; high: number };
91
  }[],
92
  ) {
 
98
  std?: number;
99
  }[];
100
  } = {};
101
+ const order: { [key: string]: 'ascending' | 'descending' } = {};
102
  for (const entry of data) {
103
  if (peformancePerMetric.hasOwnProperty(entry.metric)) {
104
  peformancePerMetric[entry.metric].push(entry);
105
  } else {
106
  peformancePerMetric[entry.metric] = [entry];
107
  }
108
+
109
+ if (!order.hasOwnProperty(entry.metric)) {
110
+ order[entry.metric] = entry.order ? entry.order : 'ascending';
111
+ }
112
  }
113
+ for (const [metric, performance] of Object.entries(peformancePerMetric)) {
114
+ performance.sort((a, b) => {
115
+ if (order[metric] == 'ascending') {
116
+ return a.score > b.score ? -1 : 1;
117
+ } else {
118
+ return a.score > b.score ? 1 : -1;
119
+ }
120
+ });
121
  let rank = 0;
122
  performance.forEach((entry, idx) => {
123
  if (idx !== 0 && entry.score === performance[idx - 1].score) {
 
429
  rank: number;
430
  size: number;
431
  levels: { low: number; medium: number; high: number };
432
+ order?: 'ascending' | 'descending';
433
  }[] = [];
434
  let aData: {
435
  model: string;
 
439
  rank: number;
440
  size: number;
441
  levels: { low: number; medium: number; high: number };
442
+ order?: 'ascending' | 'descending';
443
  }[] = [];
444
 
445
  const performancePerModel: {
 
606
  (statistics.std / selectedTasksCount).toFixed(2),
607
  ),
608
  levels: statistics.levels,
609
+ ...(eligibleMetrics[metric].order && {
610
+ order: eligibleMetrics[metric].order,
611
+ }),
612
  });
613
  } else if (eligibleMetrics[metric].author === 'algorithm') {
614
  aData.push({
 
623
  (statistics.std / selectedTasksCount).toFixed(2),
624
  ),
625
  levels: statistics.levels,
626
+ ...(eligibleMetrics[metric].order && {
627
+ order: eligibleMetrics[metric].order,
628
+ }),
629
  });
630
  }
631
  }
src/views/task/RAGTask.module.scss CHANGED
@@ -132,3 +132,13 @@
132
  .responseContainer {
133
  line-height: 1.4em;
134
  }
 
 
 
 
 
 
 
 
 
 
 
132
  .responseContainer {
133
  line-height: 1.4em;
134
  }
135
+
136
+ .contextUnavailableWarning {
137
+ margin-top: 5%;
138
+ align-self: center;
139
+ display: flex;
140
+ font-size: 24px;
141
+ column-gap: $spacing-03;
142
+ align-items: center;
143
+ color: var(--cds-support-warning);
144
+ }
src/views/task/RAGTask.tsx CHANGED
@@ -32,7 +32,7 @@ import {
32
  ContainedList,
33
  ContainedListItem,
34
  } from '@carbon/react';
35
- import { TextHighlight } from '@carbon/icons-react';
36
 
37
  import {
38
  Model,
@@ -302,39 +302,45 @@ export default function RAGTask({
302
  </div>
303
  )}
304
  </div>
305
- <DocumentPanel
306
- key={`evaluation--${selectedEvaluationIndex}__documents`}
307
- documents={documentsPerEvaluation[
308
- selectedEvaluationIndex
309
- ].map((document, documentIdx) => {
310
- return {
311
- documentId: document.documentId,
312
- text: showOverlap
313
- ? mark(
314
- document.text,
315
- evaluations[selectedEvaluationIndex].overlaps[
316
- documentIdx
317
- ],
318
- 'target',
319
- )
320
- : document.text,
321
- ...(document.title && { title: document.title }),
322
- ...(document.url && { url: document.url }),
323
- ...(document.annotations && {
324
- annotations: document.annotations,
325
- }),
326
- };
327
- })}
328
- onMouseDown={(provenance: string) => {
329
- updateCommentProvenance(provenance);
330
- }}
331
- onMouseUp={(provenance: string) =>
332
- updateCommentProvenance(provenance)
333
- }
334
- notify={(documentIndex: number) => {
335
- setActiveDocumentIndex(documentIndex);
336
- }}
337
- />
 
 
 
 
 
 
338
  </div>
339
  )}
340
  </div>
 
32
  ContainedList,
33
  ContainedListItem,
34
  } from '@carbon/react';
35
+ import { TextHighlight, WarningAlt } from '@carbon/icons-react';
36
 
37
  import {
38
  Model,
 
302
  </div>
303
  )}
304
  </div>
305
+ {isEmpty(documentsPerEvaluation[selectedEvaluationIndex]) ? (
306
+ <div className={classes.contextUnavailableWarning}>
307
+ <WarningAlt size={24} /> No context is available
308
+ </div>
309
+ ) : (
310
+ <DocumentPanel
311
+ key={`evaluation--${selectedEvaluationIndex}__documents`}
312
+ documents={documentsPerEvaluation[
313
+ selectedEvaluationIndex
314
+ ].map((document, documentIdx) => {
315
+ return {
316
+ documentId: document.documentId,
317
+ text: showOverlap
318
+ ? mark(
319
+ document.text,
320
+ evaluations[selectedEvaluationIndex].overlaps[
321
+ documentIdx
322
+ ],
323
+ 'target',
324
+ )
325
+ : document.text,
326
+ ...(document.title && { title: document.title }),
327
+ ...(document.url && { url: document.url }),
328
+ ...(document.annotations && {
329
+ annotations: document.annotations,
330
+ }),
331
+ };
332
+ })}
333
+ onMouseDown={(provenance: string) => {
334
+ updateCommentProvenance(provenance);
335
+ }}
336
+ onMouseUp={(provenance: string) =>
337
+ updateCommentProvenance(provenance)
338
+ }
339
+ notify={(documentIndex: number) => {
340
+ setActiveDocumentIndex(documentIndex);
341
+ }}
342
+ />
343
+ )}
344
  </div>
345
  )}
346
  </div>