Skip to content

Instantly share code, notes, and snippets.

@hamletbatista
Created April 2, 2020 05:09
Show Gist options
  • Save hamletbatista/fb7eae2e846ee8c43fff5a433df2c672 to your computer and use it in GitHub Desktop.
Save hamletbatista/fb7eae2e846ee8c43fff5a433df2c672 to your computer and use it in GitHub Desktop.
function fetchPrediction(TEXT = "give me a flight from baltimore to newark"){
TEXT = encodeURI("tokens=BOS "+TEXT+" EOS");
console.log(TEXT);
//You need to replace this temporary URL
var url = "https://e769db6e.ngrok.io/predict";
var options = {
"method" : "POST",
"contentType" : "application/x-www-form-urlencoded",
"payload" : TEXT,
'muteHttpExceptions': true
};
var response = UrlFetchApp.fetch(url, options);
var json = response.getContentText();
console.log(json);
prediction = JSON.parse(json);
//console.log(prediction);
console.log(prediction["intent_predictions"]);
console.log(prediction["slots_predictions"].join("_"));
//return [prediction["intent_predictions"], JSON.stringify(prediction["slots_predictions"])];
return [prediction["intent_predictions"], prediction["slots_predictions"].join("_")];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment