Skip to content

Commit

Permalink
Merge pull request #4535 from vishnupriyavr/master
Browse files Browse the repository at this point in the history
DucklingHTTPExtractor with defined request timeout
  • Loading branch information
Nikolai committed Sep 30, 2019
2 parents 95d2f35 + 9399efe commit dde5a1d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Fixed
-----
- fixed missing ``tkinter`` dependency for running tests on Ubuntu
- fixed issue with ``conversation`` JSON serialization
- fixed the hanging HTTP call with ``ner_duckling_http`` pipeline

[Unreleased 1.3.7]
^^^^^^^^^^^^^^^^^^
Expand Down
3 changes: 3 additions & 0 deletions docs/nlu/components.rst
Original file line number Diff line number Diff line change
Expand Up @@ -857,3 +857,6 @@ DucklingHTTPExtractor
# if not set the default timezone of Duckling is going to be used
# needed to calculate dates from relative expressions like "tomorrow"
timezone: "Europe/Berlin"
# Timeout for receiving response from http url of the running duckling server
# if not set the default timeout of duckling http url is set to 3 seconds.
timeout : 3
15 changes: 12 additions & 3 deletions rasa/nlu/extractors/duckling_http_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class DucklingHTTPExtractor(EntityExtractor):
# timezone like Europe/Berlin
# if not set the default timezone of Duckling is going to be used
"timezone": None,
# Timeout for receiving response from http url of the running duckling server
# if not set the default timeout of duckling http url is set to 3 seconds.
"timeout": 3,
}

def __init__(
Expand Down Expand Up @@ -113,7 +116,10 @@ def _duckling_parse(self, text, reference_time):
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
}
response = requests.post(
self._url() + "/parse", data=payload, headers=headers
self._url() + "/parse",
data=payload,
headers=headers,
timeout=self.component_config.get("timeout"),
)
if response.status_code == 200:
return response.json()
Expand All @@ -124,10 +130,13 @@ def _duckling_parse(self, text, reference_time):
"".format(response.status_code, response.text)
)
return []
except requests.exceptions.ConnectionError as e:
except (
requests.exceptions.ConnectionError,
requests.exceptions.ReadTimeout,
) as e:
logger.error(
"Failed to connect to duckling http server. Make sure "
"the duckling server is running and the proper host "
"the duckling server is running/healthy/not stale and the proper host "
"and port are set in the configuration. More "
"information on how to run the server can be found on "
"github: "
Expand Down

0 comments on commit dde5a1d

Please sign in to comment.