Skip to content

Instantly share code, notes, and snippets.

@matryer
Last active April 18, 2018 12:55
Show Gist options
  • Select an option

  • Save matryer/43b01c4d45ada931d46f752238a2fb8f to your computer and use it in GitHub Desktop.

Select an option

Save matryer/43b01c4d45ada931d46f752238a2fb8f to your computer and use it in GitHub Desktop.
function makePrediction() {
// create a prediction request that includes some facts about
// the user.
var predictRequest = {
"inputs": [
{"key": "user_age", "type": "number", "value": ""+user.age},
{"key": "user_interests", "type": "list", "value": user.interests.join(',')},
{"key": "user_location", "type": "keyword", "value": user.city}
]
}
var url = options.suggestionboxAddr+'/models/'+options.modelID+'/predict'
makeRequest('post', url, predictRequest, function(status, response, xhr) {
if (status !== 200 || !response.success) {
console.warn('Failed', status, response, xhr)
return
}
// order the elements based on the response from
// the Machine Learning model
var choicesEl = document.getElementById('choices')
for (var choice in response.choices) {
var choice = response.choices[choice]
// keep track of this reward ID
rewardIDs[choice.id] = choice.reward_id
var choiceEl = document.getElementById('choice-'+choice.id)
choicesEl.appendChild(choiceEl)
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment