fix: correct usage of fuzzy search

This commit is contained in:
Matěj Račinský 2024-05-18 17:05:55 +02:00
parent 0653dad5c5
commit bd1bfee941
1 changed files with 6 additions and 6 deletions

View File

@ -1020,12 +1020,12 @@ function parseLlmResponse(emotionResponse, labels) {
const parsedEmotion = JSON.parse(emotionResponse);
return parsedEmotion?.emotion ?? fallbackExpression;
} catch {
const fuse = new Fuse([emotionResponse]);
for (const label of labels) {
const result = fuse.search(label);
const fuse = new Fuse(labels, {includeScore: true});
console.debug("Using fuzzy search in labels: " + labels.join(', '))
const result = fuse.search(emotionResponse);
if (result.length > 0) {
return label;
}
console.debug("fuzzy search found: " + result[0].item + " as closest for the LLM response: " + emotionResponse)
return result[0].item;
}
}