Merge pull request #2264 from racinmat/staging

fix: correct usage of fuzzy search in emotion detection by LLM
This commit is contained in:
Cohee 2024-05-18 18:57:34 +03:00 committed by GitHub
commit 4219468e20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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);
if (result.length > 0) {
return 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) {
console.debug("fuzzy search found: " + result[0].item + " as closest for the LLM response: " + emotionResponse)
return result[0].item;
}
}