def IdentifyIntent(self): try: TEXT = self.inputQuery CLIENT = LUISClient(self.__APPID__, self.__APPKEY__, True) res = CLIENT.predict(TEXT) while res.get_dialog( ) is not None and not res.get_dialog().is_finished(): TEXT = raw_input(u'%s\n' % res.get_dialog().get_prompt()) res = CLIENT.reply(TEXT, res) #self.process_res(res) return res except Exception, exc: print(exc)
def get_luis_response(text): try: APPID = 'YOUR_LUIS_APP_ID' APPKEY = 'YOUR_LUIS_APP_KEY' CLIENT = LUISClient(APPID, APPKEY, True) res = CLIENT.predict(text) while res.get_dialog( ) is not None and not res.get_dialog().is_finished(): TEXT = raw_input(u'%s\n' % res.get_dialog().get_prompt()) res = CLIENT.reply(TEXT, res) reply = process_res(res) return reply except Exception, exc: print(exc) return "Sorry, something went wrong."
def make_request(self, message): """Send message from user to LUIS for intent analysis""" # Hard coded LUIS APP ID and Authoring Key APPID = self.LUIS_ID APPKEY = self.LUIS_KEY try: CLIENT = LUISClient(APPID, APPKEY, True) res = CLIENT.predict(message) while res.get_dialog() is not None and not res.get_dialog()\ .is_finished(): TEXT = input('%s\n' % res.get_dialog().get_prompt()) res = CLIENT.reply(TEXT, res) return res except Exception as exc: print(exc)
def preprocess(input_text): headers = { # Request headers 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': '{49a3e79bc72f414db090cd8a2eeddc03}', } APPID = "cf321ffa-6919-4306-9ff1-2ec8fc81328c" APPKEY = "49a3e79bc72f414db090cd8a2eeddc03" TEXT = input_text CLIENT = LUISClient(APPID, APPKEY, True) res = CLIENT.predict(TEXT) while res.get_dialog() is not None and not res.get_dialog().is_finished(): TEXT = raw_input(u'%s\n' % res.get_dialog().get_prompt()) res = CLIENT.reply(TEXT, res) return process_res(res)
def __handle_message_activity(self, activity): """ Handle the messages. STATE used to collect APPID and APPKEY up front. All other messsages sent to LUIS for parsing. APPID and APPKEY specify the LUIS service called via REST. For example: https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/((APPID))?subscription-key=((APPKEY)) &verbose=true&timezoneOffset=0&q=((TEXT-FOR-LUIS-TO-PARSE """ BotRequestHandler.STATE+=1 ## POORMAN'S STATE TRACKING self.send_response(200) self.end_headers() credentials = MicrosoftAppCredentials(APPID, APPPASSWORD) connector = ConnectorClient(credentials, base_url=activity.service_url) LUIStext = '' ## FIRST, GET APPID if self.STATE==1: if activity.text: BotRequestHandler.LUISAPPID=activity.text reply = BotRequestHandler.__create_reply_activity(activity, "You entered application ID: %s\nNow, please input your subscription key (default: %s):" % (activity.text,self.LUISAPPKEY)) ## SECOND, GET APPKEY elif self.STATE==2: if activity.text: BotRequestHandler.LUISAPPKEY=activity.text reply = BotRequestHandler.__create_reply_activity(activity, "Great! You entered application key: %s\nNow, enter some text for the LUIS model to render:" % activity.text) ## THIRD AND ONWARDS: SEND TEXT TO LUIS AND REPORT LUIS RESPONSE TO THE USER else: try: CLIENT = LUISClient(self.LUISAPPID, self.LUISAPPKEY, True) res = CLIENT.predict(activity.text) while res.get_dialog() is not None and not res.get_dialog().is_finished(): TEXT = input('%s\n'%res.get_dialog().get_prompt()) res = CLIENT.reply(TEXT, res) LUIStext=self.__handle_LUIS_response(res) reply = BotRequestHandler.__create_reply_activity(activity, 'LUIS says: %s' % LUIStext) except Exception as exc: LUIStext=exc print("Error: %s" % exc) reply = BotRequestHandler.__create_reply_activity(activity, 'About %s, LUIS complains: %s' % (activity.text,LUIStext)) connector.conversations.send_to_conversation(reply.conversation.id, reply)
print('Top Scoring Intent: ' + res.get_top_intent().get_name()) if res.get_dialog() is not None: if res.get_dialog().get_prompt() is None: print('Dialog Prompt: None') else: print('Dialog Prompt: ' + res.get_dialog().get_prompt()) if res.get_dialog().get_parameter_name() is None: print('Dialog Parameter: None') else: print('Dialog Parameter Name: ' + res.get_dialog().get_parameter_name()) print('Dialog Status: ' + res.get_dialog().get_status()) print('Entities:') for entity in res.get_entities(): print('"%s":' % entity.get_name()) print('Type: %s, Score: %s' % (entity.get_type(), entity.get_score())) try: APPID = 'b81195cb-904c-48ef-adaf-7b12c664dc42' APPKEY = '5efceb9fffa84210808ec4f48e3434d1' TEXT = input('Please input the text to predict:\n') CLIENT = LUISClient(APPID, APPKEY, True) res = CLIENT.predict(TEXT) while res.get_dialog() is not None and not res.get_dialog().is_finished(): TEXT = input('%s\n' % res.get_dialog().get_prompt()) res = CLIENT.reply(TEXT, res) process_res(res) except Exception as exc: print(exc)
print('LUIS Response: ') print('Query: ' + res.get_query()) print('Top Scoring Intent: ' + res.get_top_intent().get_name()) if res.get_dialog() is not None: if res.get_dialog().get_prompt() is None: print('Dialog Prompt: None') else: print('Dialog Prompt: ' + res.get_dialog().get_prompt()) if res.get_dialog().get_parameter_name() is None: print('Dialog Parameter: None') else: print('Dialog Parameter Name: ' + res.get_dialog().get_parameter_name()) print('Dialog Status: ' + res.get_dialog().get_status()) print('Entities:') for entity in res.get_entities(): print('"%s":' % entity.get_name()) print('Type: %s, Score: %s' % (entity.get_type(), entity.get_score())) try: APPID = input('Please enter your app Id:\n') APPKEY = input('Please input your subscription key:\n') TEXT = input('Please input the text to predict:\n') CLIENT = LUISClient(APPID, APPKEY, True) res = CLIENT.predict(TEXT) while res.get_dialog() is not None and not res.get_dialog().is_finished(): TEXT = input('%s\n'%res.get_dialog().get_prompt()) res = CLIENT.reply(TEXT, res) process_res(res) except Exception as exc: print(exc)