-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflight_booking_recognizer.py
45 lines (35 loc) · 1.66 KB
/
flight_booking_recognizer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
from botbuilder.ai.luis import LuisApplication, LuisRecognizer, LuisPredictionOptions
from botbuilder.core import (
Recognizer,
RecognizerResult,
TurnContext,
BotTelemetryClient,
NullTelemetryClient)
from bot_config import DefaultConfig
class FlightBookingRecognizer(Recognizer):
def __init__(
self, configuration: DefaultConfig, telemetry_client: BotTelemetryClient = None):
self._recognizer = None
luis_is_configured = (
configuration.LUIS_APP_ID
and configuration.LUIS_API_KEY
and configuration.LUIS_API_HOST_NAME)
if luis_is_configured:
# Set the recognizer options depending on which endpoint version you want to use e.g v2 or v3.
# More details can be found in https://docs.microsoft.com/azure/cognitive-services/luis/luis-migration-api-v3
luis_application = LuisApplication(
configuration.LUIS_APP_ID,
configuration.LUIS_API_KEY,
configuration.LUIS_API_HOST_NAME)
options = LuisPredictionOptions()
options.telemetry_client = telemetry_client or NullTelemetryClient()
self._recognizer = LuisRecognizer(
luis_application, prediction_options=options)
@property
def is_configured(self) -> bool:
# Returns true if luis is configured in the config.py and initialized.
return self._recognizer is not None
async def recognize(self, turn_context: TurnContext) -> RecognizerResult:
return await self._recognizer.recognize(turn_context)