Вам просто нужно отсортировать список намерений по их баллам. Вот пример JavaScript, предполагая, что ваш ответ JSON сохранен в result
:
// Convert result to an array of intents
const intentsArray = Object.entries(result.prediction.intents).map(([k, v]) => ({ intent: k, score: v.score }));
// Sort the array, descending
const sorted = intentsArray.sort((a, b) => b.score - a.score);
// Pull out the top two entries
const top2 = sorted.slice(0, 2);
// Show the result
console.log(JSON.stringify(top2, null, 2));
В результате:
[
{
"intent": "NAME_INFO",
"score": 0.0462775342
},
{
"intent": "MONTHLY_HOUSING_INFO",
"score": 0.0363982953
}
]