Skip to content
This repository was archived by the owner on Jun 24, 2020. It is now read-only.

Commit 9d6f9a3

Browse files
author
Philippe Cote-Boucher
committed
chore: fixed http_logger to forward modelId
1 parent 196b67c commit 9d6f9a3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

rasa_addons/nlu/components/http_logger.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
from rasa.nlu.training_data import Message
55

66
from requests_futures.sessions import FuturesSession
7+
import json
8+
import logging
79

10+
logger = logging.getLogger(__name__)
811

912
class HttpLogger(Component):
1013
name = 'HttpLogger'
@@ -16,19 +19,24 @@ class HttpLogger(Component):
1619
def __init__(self, component_config=None):
1720
super(HttpLogger, self).__init__(component_config)
1821
assert 'url' in component_config, 'You must specify the url to use the HttpLogger component'
22+
assert 'model_id' in component_config, 'You must specify the model_id to use the HttpLogger component'
1923

2024
def process(self, message, **kwargs):
2125
# type: (Message, **Any) -> None
2226

2327
session = FuturesSession()
24-
if not message.params or message.params.get('nolog', 'false') not in ['true', '1']:
28+
if not message.params or message.params.get('nolog', 'false') in ['true', '1']:
2529
return
2630

2731
output = self._message_dict(message)
2832
for k, v in self.component_config.get('params').items():
2933
output[k] = v
34+
output['modelId'] = self.component_config.get('model_id')
3035

31-
session.post(self.component_config.get('url'), json=output)
36+
future = session.post(self.component_config.get('url'), json=output)
37+
response = future.result()
38+
if response.status_code != 200:
39+
logger.error('{} Error from API: {}'.format(str(response.status_code), json.loads(response.content)['error']))
3240

3341
@staticmethod
3442
def _message_dict(message):

0 commit comments

Comments
 (0)