Last active
November 7, 2017 20:24
-
-
Save anacampesan/bee59184aae331c254e5c27a847bb226 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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