10000 Merge pull request #192 from microsoft/tiens · zigri2612/botbuilder-python@bcc85a4 · GitHub
[go: up one dir, main page]

Skip to content

Commit bcc85a4

Browse files
authored
Merge pull request microsoft#192 from microsoft/tiens
Fixed up luis_helper in core-bot sample
2 parents 00c3a62 + 4013475 commit bcc85a4

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

samples/Core-Bot/config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
Settings:
55
Port: 3978
66
LuisAppId: ""
7-
LuisAPIKey: ""
8-
LuisAPIHostName: ""
7+
# LUIS authoring key from LUIS portal or LUIS Cognitive Service subscription key
8+
LuisAPIKey: ""
9+
# LUIS endpoint host name, ie "westus.api.cognitive.microsoft.com"
10+
LuisAPIHostName: ""
911
AppId: ""
1012
AppPassword: ""

samples/Core-Bot/helpers/luis_helper.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,31 @@ async def excecute_luis_query(configuration: dict, turn_context: TurnContext) ->
1414

1515
try:
1616
luis_application = LuisApplication(
17-
configuration['LuisApplication'],
17+
configuration['LuisAppId'],
1818
configuration['LuisAPIKey'],
1919
'https://'+configuration['LuisAPIHostName']
2020
)
2121

2222
recognizer = LuisRecognizer(luis_application)
2323
recognizer_result = await recognizer.recognize(turn_context)
2424

25-
intent = sorted(recognizer_result.intents, key=recognizer_result.intents.get, reverse=True)[:1] if recognizer_result.intents else None
25+
intent = sorted(recognizer_result.intents, key=recognizer_result.intents.get, reverse=True)[:1][0] if recognizer_result.intents else None
2626

2727
if intent == 'Book_flight':
2828
# We need to get the result from the LUIS JSON which at every level returns an array.
29-
booking_details.destination = recognizer_result.entities.get("To", {}).get("Airport", [])[:1][:1]
30-
booking_details.origin = recognizer_result.entities.get("From", {}).get("Airport", [])[:1][:1]
29+
to_entities = recognizer_result.entities.get("$instance", {}).get("To", [])
30+
if len(to_entities) > 0:
31+
booking_details.destination = to_entities[0]['text']
3132

32-
# This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
33+
from_entities = recognizer_result.entities.get("$instance", {}).get("From", [])
34+
if len(from_entities) > 0:
35+
booking_details.origin = from_entities[0]['text']
36+
37+
# TODO: This value will be a TIMEX. And we are only interested in a Date so grab the first result and drop the Time part.
3338
# TIMEX is a format that represents DateTime expressions that include some ambiguity. e.g. missing a Year.
34-
booking_details.travel_date = recognizer_result.entities.get("datetime", {}).get("timex", [])[:1].split('T')[0]
39+
date_entities = recognizer_result.entities.get("$instance", {}).get("datetime", [])
40+
if len(date_entities) > 0:
41+
booking_details.travel_date = None # TODO: Set when we get a timex format
3542
except Exception as e:
3643
print(e)
3744

0 commit comments

Comments
 (0)
0