Skip to content

Instantly share code, notes, and snippets.

@anacampesan
Last active November 7, 2017 20:24
Show Gist options
  • Save anacampesan/bee59184aae331c254e5c27a847bb226 to your computer and use it in GitHub Desktop.
Save anacampesan/bee59184aae331c254e5c27a847bb226 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import requests
from meya import Component
class WitRequest(Component):
def start(self):
API_KEY = 'XXX'
url = 'https://api.wit.ai/message'
headers = {'Authorization': 'Bearer ' + API_KEY}
params = {'v': '20171031', 'q': self.db.flow.get('intent')}
request = requests.get(url, params=params, headers=headers).json()
try:
intent = request['entities']['intent'][0]
confidence = intent['confidence']
value = intent['value']
except KeyError:
pass
if (confidence > 0.6):
print('[debug] high confidence')
return self.respond(action=value)
return self.respond(action='error')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment