Skip to content

Commit ba8dbe1

Browse files
[FIX] Stabilization fixes for confidence data (#1689)
Stabilization fixes
1 parent 8e44ffc commit ba8dbe1

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

frontend/src/components/custom-tools/prompt-card/DisplayPromptResult.jsx

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ function DisplayPromptResult({
317317
highlightData={highlightData}
318318
promptId={promptDetails?.prompt_id}
319319
profileId={profileId}
320-
confidenceData={confidenceData}
321320
wordConfidenceData={wordConfidenceData}
322321
selectedHighlight={selectedHighlight}
323322
parsedOutput={parsedOutput}
@@ -333,14 +332,61 @@ const TextResult = ({
333332
highlightData,
334333
promptId,
335334
profileId,
336-
confidenceData,
337335
wordConfidenceData,
338336
selectedHighlight,
339337
parsedOutput,
340338
onSelectHighlight,
341339
}) => {
342-
// Use word confidence if available, otherwise fallback to line confidence
343-
const confidence = wordConfidenceData || confidenceData;
340+
const getConfidenceForText = () => {
341+
// Try word confidence first
342+
if (wordConfidenceData && typeof wordConfidenceData === "object") {
343+
const values = Object.values(wordConfidenceData).filter(
344+
(v) => typeof v === "number"
345+
);
346+
if (values.length > 0) {
347+
const sum = values.reduce((acc, val) => acc + val, 0);
348+
return sum / values.length;
349+
}
350+
}
351+
352+
// Fallback to extracting from highlight data
353+
if (highlightData) {
354+
const confidenceValues = [];
355+
356+
const extractConfidenceFromHighlightData = (data) => {
357+
if (Array.isArray(data)) {
358+
for (const item of data) {
359+
if (Array.isArray(item)) {
360+
if (item.length >= 5 && typeof item[4] === "number") {
361+
confidenceValues.push(item[4]);
362+
} else {
363+
extractConfidenceFromHighlightData(item);
364+
}
365+
} else if (typeof item === "object" && item !== null) {
366+
for (const val of Object.values(item)) {
367+
extractConfidenceFromHighlightData(val);
368+
}
369+
}
370+
}
371+
} else if (typeof data === "object" && data !== null) {
372+
for (const val of Object.values(data)) {
373+
extractConfidenceFromHighlightData(val);
374+
}
375+
}
376+
};
377+
378+
extractConfidenceFromHighlightData(highlightData);
379+
380+
if (confidenceValues.length > 0) {
381+
const sum = confidenceValues.reduce((acc, val) => acc + val, 0);
382+
return sum / confidenceValues.length;
383+
}
384+
}
385+
386+
return undefined;
387+
};
388+
389+
const confidence = getConfidenceForText();
344390

345391
return enableHighlight ? (
346392
<Typography.Text
@@ -364,7 +410,6 @@ TextResult.propTypes = {
364410
highlightData: PropTypes.any,
365411
promptId: PropTypes.string,
366412
profileId: PropTypes.string,
367-
confidenceData: PropTypes.any,
368413
wordConfidenceData: PropTypes.any,
369414
selectedHighlight: PropTypes.object,
370415
parsedOutput: PropTypes.any,

0 commit comments

Comments
 (0)