<commit_before>import json
from socket import gaierror

from apiai import ApiAI

from Norman.errors import HttpError
from Norman.logger import Logger
from Norman.settings import ApiAIConfig
from Norman.utils import generate_session_id

ai = ApiAI(ApiAIConfig.CLIENT_ACCESS_TOKEN)


class AI:
    def __init__(self):
        self.request = ai.text_request()
        self.request.lang = 'de'  # optional, default value equal 'en'
        self.request.session_id = generate_session_id()
        self.match_successful = False
        self.text = None
        self.log = Logger()

    def parse(self, data):
        print('got to apiai parse function')
        self.request.query = data
        try:
            r = self.request.getresponse()  # returns a response object
            response = json.loads(r.read().decode(encoding='UTF-8').replace('\n', ''))
            print(response)
        except HttpError:
            self.log.log_error('HTTP Error: Unable to complete request.')
            return
        except gaierror as e:
            self.log.log_error('Socket Error: {}'.format(e))
            return

        try:
            if response['result']['metadata']['intentName'] != 'Default Fallback Intent':
                self.match_successful = True
                self.text = response['result']['fulfillment']['speech']
        except KeyError:
            try:
                if response['result']['metadata'] == {}:
                    self.match_successful = True
                    self.text = response['result']['fulfillment']['speech']
            except KeyError:
                self.match_successful = False

if __name__ == '__main__':
    test = AI()
    message = 'hi'
    test.parse(message)
    if test.match_successful:
        reply = test.text
        print(reply)
    else:
        pass
<commit_msg>adding api.ai to processor<commit_after>import json
from socket import gaierror

from apiai import ApiAI

from Norman.errors import HttpError
from Norman.logger import Logger
from Norman.settings import ApiAIConfig
from Norman.utils import generate_session_id

ai = ApiAI(ApiAIConfig.CLIENT_ACCESS_TOKEN)


class AI:
    def __init__(self):
        self.request = ai.text_request()
        self.request.lang = 'de'  # optional, default value equal 'en'
        self.request.session_id = generate_session_id()
        self.match_successful = False
        self.text = None
        self.log = Logger()

    def parse(self, data):
        print('got to apiai parse function')
        self.request.query = data
        try:
            r = self.request.getresponse()  # returns a response object
            response = json.loads(r.read().decode(encoding='UTF-8').replace('\n', ''))
            print(response)
        except HttpError:
            self.log.log_error('HTTP Error: Unable to complete request.')
            return
        except gaierror as e:
            self.log.log_error('Socket Error: {}'.format(e))
            return

        try:
            if response['result']['metadata']['intentName'] != 'Default Fallback Intent':
                self.match_successful = True
                self.text = response['result']['fulfillment']['speech']
        except KeyError:
            try:
                if response['result']['metadata'] == {}:
                    self.match_successful = True
                    self.text = response['result']['fulfillment']['speech']
            except KeyError:
                self.match_successful = False

if __name__ == '__main__':
    test = AI()
    message = "i'll like to leave a message"
    test.parse(message)
    if test.match_successful:
        reply = test.text
        print(reply)
    else:
        pass

{'fraction_non_alphanumeric': 0.10651527439848607, 'fraction_numerical': 0.0005406866720735334, 'mean_word_length': 2.178694158075601, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2088463', 'n_tokens_mistral': 997, 'n_tokens_neox': 995, 'n_words': 256}