Add argument matching

This commit is contained in:
Apher 2026-07-23 02:54:38 +00:00
parent 266bdd6a55
commit 2aa81df961

View File

@ -72,28 +72,45 @@ async function classifyIntent(text) {
const INTENTS = await getIntents(); const INTENTS = await getIntents();
let best = { let bestIntent = {
name: "unknown", name: "unknown",
confidence: 0.5, confidence: 0.5,
matched: null, matched: null,
argument: null
}; };
for (const intent of INTENTS) { for (const intent of INTENTS) {
for (const example of intent.examples) { for (const example of intent.examples) {
const exampleEmbedding = await embed(example); const exampleEmbedding = await embed(example);
const score = cosineSimilarity(inputEmbedding, exampleEmbedding); const intentScore = cosineSimilarity(inputEmbedding, exampleEmbedding);
if (score > best.confidence) { if (intentScore > best.confidence) {
best = { bestIntent = {
name: intent.name, name: intent.name,
confidence: score, confidence: intentScore,
matched: example, 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) { async function handleIntent(streamKey, msg) {