当前位置: 首页>>代码示例>>Python>>正文


Python Wit.run_actions方法代码示例

本文整理汇总了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()
开发者ID:marchandivan,项目名称:Room-Monitoring-Rest-Api,代码行数:18,代码来源:views.py

示例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)
开发者ID:SemihY,项目名称:facebookbot,代码行数:16,代码来源:flaskfacebookbot.py

示例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
开发者ID:python-bot,项目名称:python-bot,代码行数:21,代码来源:wit_middleware.py

示例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)
开发者ID:yaalaa,项目名称:juxy,代码行数:26,代码来源:aiwitutils.py

示例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', {})
开发者ID:darkcoordinate,项目名称:pywit,代码行数:32,代码来源:quickstart.py

示例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', {})
开发者ID:Liferenko,项目名称:pywit,代码行数:27,代码来源:template.py

示例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', {})
开发者ID:Liferenko,项目名称:pywit,代码行数:32,代码来源:joke.py

示例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)
'''
开发者ID:xe1gyq,项目名称:GiekIs,代码行数:31,代码来源:main.py

示例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)
开发者ID:stsewd,项目名称:hellopy,代码行数:5,代码来源:bot.py

示例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
开发者ID:crazylab,项目名称:TravelAssistant,代码行数:32,代码来源:travel_assistant.py

示例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, {})
开发者ID:shivanggupta,项目名称:wit-weatherbot-python,代码行数:32,代码来源:wittest.py

示例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)
开发者ID:duythongnguyen211,项目名称:Ubuntu,代码行数:32,代码来源:weather.py


注:本文中的wit.Wit.run_actions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。