本文整理匯總了Python中wit.Wit.run_actions方法的典型用法代碼示例。如果您正苦於以下問題:Python Wit.run_actions方法的具體用法?Python Wit.run_actions怎麽用?Python Wit.run_actions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wit.Wit
的用法示例。
在下文中一共展示了Wit.run_actions方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: facebookBot
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
def facebookBot(request):
try:
if 'hub.verify_token' in request.GET:
if request.GET['hub.verify_token'] == models.Config.get('FacebookVerifyToken'):
if 'hub.challenge' in request.GET:
return HttpResponse(request.GET['hub.challenge'])
return HttpResponse("KO")
body = json.loads(request.body)
for entry in body['entry']:
for message in entry['messaging']:
if 'is_echo' not in message and 'message' in message:
senderId = message['sender']['id']
client = Wit(access_token=models.Config.get('WitToken'), actions=actions)
client.run_actions("session_%s" % senderId, message['message']['text'], {'senderId': senderId})
except Exception, e:
traceback.print_exc()
示例2: send_message
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
def send_message(recipient, text):
client = Wit(WITAI_TOKEN, actions)
session_id = 'my-user-id-42'
context0 = client.run_actions(session_id, text, {})
print(context0)
data = {
"recipient": {"id": recipient},
"message": {"text": WitAi_returnMessage}
}
resp = requests.post("https://graph.facebook.com/v2.6/me/messages?access_token=" + ACCESS_TOKEN, json=data)
print(resp.content)
示例3: WitMiddleware
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
class WitMiddleware(MiddlewareMixin):
WIT_DATA_KEY = "_wit"
WIT_CONTEXT_KEY = "_context"
def __init__(self, *args, **kwargs):
from wit import Wit
self.access_token = kwargs.pop("access_token", None)
self.actions = kwargs.pop("actions", {})
self.client = Wit(access_token=self.access_token, actions=self.actions)
super().__init__(*args, **kwargs)
def process_request(self, request: BotRequest):
if request.text:
user_data = request.user_storage.get(request.user_id)
wit_data = user_data.get(self.WIT_DATA_KEY, {})
context = wit_data.get(self.WIT_CONTEXT_KEY, {})
result_context = self.client.run_actions(str(request.user_id), request.text, context)
wit_data[self.WIT_CONTEXT_KEY] = result_context
示例4: processText
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
def processText(token, text, sessionId, funcs=None, context=None):
out = []
def say(session_id, context, msg):
out.append(msg)
def error(session_id, context, msg):
print(u"aiwitutils.processText.error: [{msg}]".format(msg=msg))
pass
actions = dict(funcs) if isinstance(funcs, dict) else {}
actions["say"] = say
actions["error"] = error
if "merge" not in actions:
actions["merge"] = _mergeDefault
client = Wit(token, actions)
inCtx = context if context else {}
outerCtx = client.run_actions(sessionId, text, inCtx)
return (out, outerCtx)
示例5: isinstance
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
if not val:
return None
return val['value'] if isinstance(val, dict) else val
def say(session_id, msg):
print(msg)
def merge(session_id, context, entities, msg):
loc = first_entity_value(entities, 'location')
if loc:
context['loc'] = loc
return context
def error(session_id, context, e):
print(str(e))
def fetch_weather(session_id, context):
context['forecast'] = 'sunny'
return context
actions = {
'say': say,
'merge': merge,
'error': error,
'fetch-weather': fetch_weather,
}
client = Wit(access_token, actions)
session_id = 'my-user-id-42'
client.run_actions(session_id, 'weather in London', {})
示例6: say
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
from wit import Wit
access_token = 'YOUR_ACCESS_TOKEN'
def say(session_id, msg):
print(msg)
def merge(context, entities):
return context
def error(session_id, msg):
print('Oops, I don\'t know what to do.')
actions = {
'say': say,
'merge': merge,
'error': error,
}
client = Wit(access_token, actions)
session_id = 'my-user-id-42'
client.run_actions(session_id, 'your message', {})
示例7: first_entity_value
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
new_context['cat'] = category
sentiment = first_entity_value(entities, 'sentiment')
if sentiment:
new_context['ack'] = 'Glad you liked it.' if sentiment == 'positive' else 'Hmm.'
elif 'ack' in new_context:
del new_context['ack']
return new_context
def error(session_id, msg):
print('Oops, I don\'t know what to do.')
def select_joke(context):
new_context = dict(context)
jokes = all_jokes[new_context['cat'] or 'default']
shuffle(jokes)
new_context['joke'] = jokes[0]
return new_context
actions = {
'say': say,
'merge': merge,
'error': error,
'select-joke': select_joke,
}
client = Wit(access_token, actions)
session_id = 'my-user-id-42'
client.run_actions(session_id, 'tell me a joke about tech', {})
示例8: Wit
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
credential = credentials.get("witai", "ServerAccessToken")
client = Wit(credential, actions)
session_id = 'my-user-id-42'
while True:
luxes = light.value()
luxes = int(luxes)
display.setColor(luxes, luxes, luxes)
if button.value() is 1:
isay("english", "Hi! This is GiekIe! How can I help?")
message = recognizeSpeech()
display.clear()
display.setCursor(0,0)
display.write(str(message))
client.run_actions(session_id, message, {})
#updater.idle()
'''
luxes = light.value()
display.setColor(255, 0, 0)
display.setCursor(0,0)
display.write('Light ' + str(luxes))
print 'Light ' + str(luxes)
time.sleep(1)
'''
示例9: converse
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
def converse(msg):
client = Wit(WIT_AI_KEY, actions)
client.run_actions(session_id, msg)
示例10: isinstance
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
return None
val = entities[entity][0]['value']
if not val:
return None
return val['value'] if isinstance(val, dict) else val
def say(session_id, context, msg):
print(msg)
def merge(session_id, context, entities, msg):
# print entities
print entities
dest = first_entity_value(entities, 'dest')
if dest:
context['dest'] = dest
return context
def error(session_id, context, e):
print(str(e))
actions = {
'say': say,
'merge': merge,
'error': error
}
client = Wit(access_token, actions)
response = client.run_actions(session_id="xyz",message="I'm planning to go to usa", max_steps=3, context={})
print response
示例11: say
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
def say(session_id, context, msg):
print(msg)
def merge(session_id, context, entities, msg):
loc = first_entity_value(entities, 'location')
if loc:
context['loc'] = loc
return context
def error(session_id, context, e):
print(str(e))
def fetch_weather(session_id, context):
location = context['loc']
location_id = pywapi.get_loc_id_from_weather_com(location)[0][0]
weather_com_result = pywapi.get_weather_from_weather_com(location_id)
context['forecast'] = weather_com_result["current_conditions"]["text"]
return context
actions = {
'say': say,
'merge': merge,
'error': error,
'fetch-weather': fetch_weather,
}
client = Wit(access_token, actions)
session_id = 'YOUR_WIT_USERNAME_HERE'
place = raw_input("Enter City Name:")
client.run_actions(session_id, 'weather in %s'%place, {})
示例12: weather2string
# 需要導入模塊: from wit import Wit [as 別名]
# 或者: from wit.Wit import run_actions [as 別名]
(loc['value'], (date['from'] + datetime.timedelta(days=d)).date().strftime('%B %d, %Y')
, weather2string(weather[d]))))
if len(weather) < (date['to'].date() - date['from'].date()).days + 1:
if len(weather) > 1:
say('', {}, 'Sorry, I can only get forecast up to %d days now' % len(weather))
else:
say('', {}, 'Sorry, I can only get forecast up to 1 day now')
else:
say('', {}, ('I cannot get forecast for %s' % loc['value']))
context = {}
say(None, None, 'Would you like the forecast for other location?')
return context
actions = {
'say': say,
'merge': merge,
'error': error,
'get_weather_info': get_weather_info,
}
if __name__ == '__main__':
bot = Wit(access_token, actions)
msg = ''
context = {}
print 'Tip: enter \'end\' to exit..ahihi'
while True:
msg = raw_input(">> You: ")
if msg == 'end':
break
context = bot.run_actions(session_id, msg, context)