def getSmallTalkResponse(request, inputString): logger.debug('Request reached in smalltalk views') logger.info('User input -->' + inputString) response = smalltalkbot.get_SmallTalk_response(inputString) logger.debug('response -->' + response) return HttpResponse(response)
def get_SmallTalk_bot(): logger.debug('get small talk bot') if TalkConfig.smallTalk_Bot is None: logger.info('smallTalk_Bot not initialised, initialising') TalkConfig.start_SmallTalk_bot() return TalkConfig.smallTalk_Bot
def ready(self): logger.info ('App ready\n') logger.debug ('Parameters.database: '+ Parameters.uri) try: logger.info ('Training smalltalk in app start up') TalkConfig.start_SmallTalk_bot() except (RuntimeError, TypeError, NameError): logger.error ('Exception while training bot') pass
def get_SmallTalk_response(inputString): resp = 'I am sorry, but I do not understand.' logger.info('Smalltalk input : ' + inputString) try: inputString = re.sub(r'[^\w]', ' ', inputString) inputString = re.sub(' +', ' ', inputString) logger.debug('Smalltalk input : ' + inputString) start = time.time() resp = get_chatbot_response(inputString) logger.info('Smalltalk response : ' + resp) end = time.time() logger.info('\nResponse time --->' + str((end - start))) logger.info(resp) except (RuntimeError, TypeError, NameError): logger.error('Exception while getting response') return resp
def train_smalltalk(): logger.info ('Training smalltalk in app start up') chatbot = ChatBot("SmallTalk_ChatBot",storage_adapter="chatterbot.storage.SQLStorageAdapter", database_uri= Parameters.uri) chatbot.storage.drop() chatbot.storage.create() logger.info ('Created chatbot database') chatbot.set_trainer(ListTrainer) smallTalkFile = open(Parameters.trainFile, encoding='utf-8') smallTalks = json.load(smallTalkFile) logger.info ('Training small talk') for key, value in smallTalks.items(): for item in value: logger.debug ('Created chatbot database') chatbot.train(item)