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

View File

@ -1020,12 +1020,12 @@ function parseLlmResponse(emotionResponse, labels) {
const parsedEmotion = JSON.parse(emotionResponse); const parsedEmotion = JSON.parse(emotionResponse);
return parsedEmotion?.emotion ?? fallbackExpression; return parsedEmotion?.emotion ?? fallbackExpression;
} catch { } catch {
const fuse = new Fuse([emotionResponse]); const fuse = new Fuse(labels, {includeScore: true});
for (const label of labels) { console.debug("Using fuzzy search in labels: " + labels.join(', '))
const result = fuse.search(label); const result = fuse.search(emotionResponse);
if (result.length > 0) { 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;
} }
} }