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


Python wit.Wit方法代码示例

本文整理汇总了Python中wit.Wit方法的典型用法代码示例。如果您正苦于以下问题:Python wit.Wit方法的具体用法?Python wit.Wit怎么用?Python wit.Wit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wit的用法示例。


在下文中一共展示了wit.Wit方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: teach_wit

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def teach_wit(wit_token, entity, values, doc=""):
    import requests
    print('*** TEACHING WIT ***')
    params = {'v':'20160526'}
    print('Inserting values of {}'.format(entity))
    rsp = requests.request(
        'PUT',
        'https://api.wit.ai/entities/'+entity,
        headers={
            'authorization': 'Bearer ' + wit_token,
            'accept': 'application/json'
        },
        params=params,
        json={'doc':doc or entity, 'values':values}
    )
    if rsp.status_code > 200:
        raise ValueError('Wit responded with status: ' + str(rsp.status_code) +
                       ' (' + rsp.reason + '): ' + rsp.text)
    json = rsp.json()
    if 'error' in json:
        raise ValueError('Wit responded with an error: ' + json['error']) 
开发者ID:prihoda,项目名称:golem,代码行数:23,代码来源:message_parser.py

示例2: initialize

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def initialize(self, bot_handler: Any) -> None:
        config = bot_handler.get_config_info('witai')

        token = config.get('token')
        if not token:
            raise KeyError('No `token` was specified')

        # `handler_location` should be the location of a module which contains
        # the function `handle`. See `doc.md` for more details.
        handler_location = config.get('handler_location')
        if not handler_location:
            raise KeyError('No `handler_location` was specified')
        self.handle = get_handle(handler_location)

        help_message = config.get('help_message')
        if not help_message:
            raise KeyError('No `help_message` was specified')
        self.help_message = help_message

        self.client = wit.Wit(token) 
开发者ID:zulip,项目名称:python-zulip-api,代码行数:22,代码来源:witai.py

示例3: get_handle

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def get_handle(location: str) -> Callable[[Dict[str, Any]], Optional[str]]:
    '''Returns a function to be used when generating a response from Wit.ai
    bot. This function is the function named `handle` in the module at the
    given `location`. For an example of a `handle` function, see `doc.md`.

    For example,

        handle = get_handle('/Users/someuser/witai_handler.py')  # Get the handler function.
        res = witai_client.message(message['content'])  # Get the Wit.ai response.
        message_res = self.handle(res)  # Handle the response and find what to show the user.
        bot_handler.send_reply(message, message_res)  # Send it to the user.

    Parameters:
     - location: The absolute path to the module to look for `handle` in.
    '''
    try:
        spec = importlib.util.spec_from_file_location('module.name', location)
        handler = importlib.util.module_from_spec(spec)
        spec.loader.exec_module(handler)
        return handler.handle  # type: ignore
    except Exception as e:
        print(e)
        return None 
开发者ID:zulip,项目名称:python-zulip-api,代码行数:25,代码来源:witai.py

示例4: clear_wit_cache

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def clear_wit_cache():
    cache = settings.GOLEM_CONFIG.get('WIT_CACHE')
    if cache:
        print('Clearing Wit cache...')
        db = get_redis()    
        db.delete('wit_cache') 
开发者ID:prihoda,项目名称:golem,代码行数:8,代码来源:message_parser.py

示例5: init_wit_client

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def init_wit_client(self):
        actions = {
            'send': self.send_message,
            'Welcome': self.send_welcome,
            'GetLocation': self.send_location,
            'GetEventTime': self.send_event_time,
            'GetProgramHelp': self.get_program_help,
            'FindProgramWithRoom': self.find_program_with_room,
            'ShowTransportType': self.show_transport_types,
            'ShowTransport': self.show_transport_result,
            'ShowSponsors': self.show_sponsors,
            'ShowSponsorIntro': self.show_sponsor_intro,
            'ShowBooths': self.show_booths,
            'ShowBoothIntro': self.show_booth_intro,
            'ShowDirty': self.send_dirty,
            'ShowPokemon': self.send_pokemon,
            'ShowNothankyou': self.send_no_thankyou,
        }
        try:
            new_action = self.dao.get_nlp_response('ACTIONMAP', self.lang)
            if len(new_action) > 0:
                new_actions = new_action[0].decode("utf-8").split(";")
                for ac in new_actions:
                    if ac == '':
                        continue
                    self.logger.info('Add dyn action %s' % ac)
                    actions[ac] = self.send_simple_response
        except Exception as ex:
            self.logger.exception(ex)
        return Wit(access_token=self.token, actions=actions) 
开发者ID:ncuoolab,项目名称:coscup-line-bot,代码行数:32,代码来源:modules.py

示例6: process_receive

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def process_receive(self, receive):
        mid = receive['from_mid']
        try:
            message = receive['content']['text']
            self.logger.info('Wit process new message %s' % message)
            session_id = self.get_session_id(mid)
            result = self.client.run_actions(session_id, message, self.get_session_context(mid, receive),
                                             action_confidence=0.3)

            # if 'stop' in result:
            # Action done. Clear cache data.
            # self.clear_session_id(mid)

            if 'processed' not in result:
                self.logger.warning('Message [%s] not run in action.' % message)
                self.clear_session_id(mid)
                response = random_get_result(self.dao.get_nlp_response(NLPActions.Error, self.lang))
                self.bot_api.reply_text(receive, response)
        except wit.WitError as we:
            self.logger.warning('Wit Process error %s' % we)
            self.clear_session(mid)
            response = random_get_result(self.dao.get_nlp_response(NLPActions.Error, self.lang))
            self.bot_api.reply_text(receive, response)
        except Exception as ex:
            self.logger.exception(ex)
            self.clear_session(mid)
            response = random_get_result(self.dao.get_nlp_response(NLPActions.Error, self.lang))
            self.bot_api.reply_text(receive, response) 
开发者ID:ncuoolab,项目名称:coscup-line-bot,代码行数:30,代码来源:modules.py

示例7: send_message

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def send_message(self, request, response):
        mid = request['context']['from_mid']
        msg = utils.to_utf8_str(response['text'])
        logging.info('Wit send message [%s] to [%s]', mid, msg)
        self.bot_api.send_text(to_mid=mid, text=msg) 
开发者ID:ncuoolab,项目名称:coscup-line-bot,代码行数:7,代码来源:modules.py

示例8: __init__

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def __init__(self):
        from wit import Wit

        access_token = config["wit_token"]
        actions = {}
        global client
        client = Wit(access_token, actions) 
开发者ID:AlquistManager,项目名称:alquist,代码行数:9,代码来源:nlp.py

示例9: __init__

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def __init__(self):
        self.client = Wit(access_token= ACCESSTOKEN) 
开发者ID:hanveiga,项目名称:ConsensusBot,代码行数:4,代码来源:MessageParser.py

示例10: create_client

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def create_client(send_function, access_token=tokens.WIT_APP_TOKEN):
    """
    Generates Wit Client. Called from apollobot.py
    """
    print("Generated Wit Client with 'send' function provided: %r" % (send_function))
    actions['send'] = send_function
    return Wit(access_token=access_token, actions=actions) 
开发者ID:ltfschoen,项目名称:Apollo-bot,代码行数:9,代码来源:chat_client.py

示例11: get_client

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def get_client(send=None):
    actions = ACTIONS.copy()
    if send:
        actions['send'] = send
    return Wit(access_token=settings.WIT_TOKEN, actions=actions) 
开发者ID:vied12,项目名称:nsfw,代码行数:7,代码来源:wit.py

示例12: usage

# 需要导入模块: import wit [as 别名]
# 或者: from wit import Wit [as 别名]
def usage(self) -> str:
        return '''
        Wit.ai bot uses pywit API to interact with Wit.ai. In order to use
        Wit.ai bot, `witai.conf` must be set up. See `doc.md` for more details.
        ''' 
开发者ID:zulip,项目名称:python-zulip-api,代码行数:7,代码来源:witai.py


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