Add argument matching
This commit is contained in:
parent
266bdd6a55
commit
2aa81df961
@ -72,28 +72,45 @@ async function classifyIntent(text) {
|
||||
|
||||
const INTENTS = await getIntents();
|
||||
|
||||
let best = {
|
||||
let bestIntent = {
|
||||
name: "unknown",
|
||||
confidence: 0.5,
|
||||
matched: null,
|
||||
argument: null
|
||||
};
|
||||
|
||||
for (const intent of INTENTS) {
|
||||
for (const example of intent.examples) {
|
||||
const exampleEmbedding = await embed(example);
|
||||
const score = cosineSimilarity(inputEmbedding, exampleEmbedding);
|
||||
const intentScore = cosineSimilarity(inputEmbedding, exampleEmbedding);
|
||||
|
||||
if (score > best.confidence) {
|
||||
best = {
|
||||
if (intentScore > best.confidence) {
|
||||
bestIntent = {
|
||||
name: intent.name,
|
||||
confidence: score,
|
||||
confidence: intentScore,
|
||||
matched: example,
|
||||
argument: intent.arguments
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return best;
|
||||
let bestArgumentScore = 0.5
|
||||
|
||||
if (best.arguments) {
|
||||
for (const argument of best.arguments) {
|
||||
const argumentEmbedding = await embed(argument);
|
||||
const argumentScore = cosineSimilarity(inputEmbedding, argumentEmbedding);
|
||||
|
||||
if (argumentScore > bestArgumentScore) {
|
||||
bestArgumentScore = argumentScore;
|
||||
|
||||
bestIntent.argument = argument
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bestIntent;
|
||||
}
|
||||
|
||||
async function handleIntent(streamKey, msg) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user