fix(tts): clamp generated summaries (#1187)
* fix(tts): clamp generated summaries * fix(tts): preserve non-finite summary limits * test(tts): stub fetch without vitest globals --------- Co-authored-by: Isaac Sanchez <isanchez-hawkins@arize.com>
This commit is contained in:
committed by
GitHub
co-authored by
Isaac Sanchez
parent
bb5a6fb83b
commit
222d1b7f51
@@ -115,6 +115,13 @@ function sanitizeByMode(text, mode) {
|
||||
return sanitizeForTTS(text);
|
||||
}
|
||||
|
||||
function clampToMaxLength(text, maxLength) {
|
||||
if (!text) return '';
|
||||
const limit = Number.isFinite(maxLength) ? Math.max(0, Math.floor(maxLength)) : Infinity;
|
||||
if (text.length <= limit) return text;
|
||||
return text.slice(0, limit).trim();
|
||||
}
|
||||
|
||||
function extractZenOutputText(data) {
|
||||
if (!data || typeof data !== 'object') return null;
|
||||
const output = data.output;
|
||||
@@ -252,11 +259,12 @@ export async function summarizeText({ text, threshold = 200, maxLength = 500, ze
|
||||
const finalSummary = mode === 'note'
|
||||
? (sanitized && sanitized !== sanitizeForNote(text) ? sanitized : distillNoteFallback(text, maxLength))
|
||||
: sanitized;
|
||||
const clippedSummary = clampToMaxLength(finalSummary, maxLength);
|
||||
return {
|
||||
summary: finalSummary,
|
||||
summary: clippedSummary,
|
||||
summarized: true,
|
||||
originalLength: text.length,
|
||||
summaryLength: finalSummary.length,
|
||||
summaryLength: clippedSummary.length,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user