0

Im trying to check the confidence of my API response within my HTML page. If confidence is 0 {Go to this page} If confidence is 1 {Go to this page} I can check other things but not the intent confidence how would i do this?

fetch(`https://api.wit.ai/message?q=${transcript}`,
{
    headers: {
        Authorization: `Bearer ${token}`,
        'Content-Type': 'application/json',
    },
}).then(res => res.json())
.then(function (data){
    if (data.intents[0].value==[0]) {
        console.log("intent 1")
        //throw "Error";
    }
    else if (data.text==="pay"){
        console.log("works")
    }
    else {
        if(data.intents==="checkout"){
            console.log("intent 2");
        }
    }
})
Henry
  • 1

1 Answers1

0

The intents property is an array of objects.

You can access the confidence score with the following;

data.intents[0].confidence
Bcf Ant
  • 1,639
  • 1
  • 16
  • 26