Я пытаюсь разработать этого чат-бота на основе стартового пакета rasa. Я добавил некоторые действия, особенно те, которые используются для бронирования комнаты и сохранения бронирований в базе данных MySQL.
На стороне клиента я начинаю с ним разговаривать, и все кажется в порядке. Тем не менее, когда дело доходит до точки, он должен совершить действие. При срабатывании action.py
он должен попасть в базу данных и сохранить информацию. И при запуске этого у меня появляется следующая ошибка TypeError: Parser must be a string or character stream, not NoneType
. Действительно, в ActionBookRoom я пытаюсь получить информацию из разговора, который выглядит следующим образом:
I want to book a room
2019-04-09 18:49:36 WARNING py.warnings - C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
127.0.0.1 - - [2019-04-09 18:49:36] "POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1" 200 181 0.054772
In what room?
Red
2019-04-09 18:49:39 WARNING py.warnings - C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
What day?127.0.0.1 - - [2019-04-09 18:49:39] "POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1" 200 177 0.061889
Tomorrow
2019-04-09 18:49:42 WARNING py.warnings - C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
What time do you want to start your meeting?127.0.0.1 - - [2019-04-09 18:49:42] "POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1" 200 212 0.034834
1pm
2019-04-09 18:49:46 WARNING py.warnings - C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
How long would you need ?127.0.0.1 - - [2019-04-09 18:49:46] "POST /webhooks/rest/webhook?stream=true&token= HTTP/1.1" 200 193 0.054826
30 min
2019-04-09 18:49:52 WARNING py.warnings - C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\sklearn\preprocessing\label.py:151: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.
if diff:
Я получил None tomorrow None 30 min
. Для получения этой информации я использовал tracker.getslot
:
class ActionBookRoom(Action):
def name(self):
return 'action_room'
def run(self, dispatcher, tracker, domain):
print("inside run")
name_room = tracker.get_slot('name_room')
day = tracker.get_slot('day')
hour_start = tracker.get_slot('hour_start')
duration = tracker.get_slot('duration')
А на стороне сервера действий у меня появляется следующее сообщение об ошибке:
(staenv) C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack>python -m rasa_core_sdk.endpoint --actions actions
2019-04-09 18:48:14 INFO __main__ - Starting action endpoint server...
2019-04-09 18:48:15 INFO rasa_core_sdk.executor - Registered function for 'action_joke'.
2019-04-09 18:48:15 INFO rasa_core_sdk.executor - Registered function for 'action_room'.
2019-04-09 18:48:15 INFO __main__ - Action endpoint is up and running. on ('0.0.0.0', 5055)
inside run
before booking_answer
None tomorrow None 30 min
[2019-04-09 18:49:54,104] ERROR in app: Exception on /webhook [POST]
Traceback (most recent call last):
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
resp = make_response(f(*args, **kwargs))
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_core_sdk\endpoint.py", line 86, in webhook
response = executor.run(action_call)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_core_sdk\executor.py", line 177, in run
events = action(dispatcher, tracker, domain)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\actions.py", line 43, in run
booking_answer = make_a_booking(name_room, day, hour_start, duration)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\booking.py", line 68, in make_a_booking
hour_start_parsed = dateutil.parser.parse(hour_start, fuzzy_with_tokens=True)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 1356, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 645, in parse
res, skipped_tokens = self._parse(timestr, **kwargs)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 721, in _parse
l = _timelex.split(timestr) # Splits the timestr into tokens
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 207, in split
return list(cls(s))
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 76, in __init__
'{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not NoneType
2019-04-09 18:49:54 ERROR flask.app - Exception on /webhook [POST]
Traceback (most recent call last):
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\_compat.py", line 35, in reraise
raise value
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask\app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
resp = make_response(f(*args, **kwargs))
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_core_sdk\endpoint.py", line 86, in webhook
response = executor.run(action_call)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\rasa_core_sdk\executor.py", line 177, in run
events = action(dispatcher, tracker, domain)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\actions.py", line 43, in run
booking_answer = make_a_booking(name_room, day, hour_start, duration)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\booking.py", line 68, in make_a_booking
hour_start_parsed = dateutil.parser.parse(hour_start, fuzzy_with_tokens=True)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 1356, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 645, in parse
res, skipped_tokens = self._parse(timestr, **kwargs)
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 721, in _parse
l = _timelex.split(timestr) # Splits the timestr into tokens
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 207, in split
return list(cls(s))
File "C:\Users\antoi\Documents\Programming\Nathalie\18_2_2019\starter-pack-rasa-stack\staenv\lib\site-packages\dateutil\parser\_parser.py", line 76, in __init__
'{itype}'.format(itype=instream.__class__.__name__))
TypeError: Parser must be a string or character stream, not NoneType
127.0.0.1 - - [2019-04-09 18:49:54] "POST /webhook HTTP/1.1" 500 412 1.047401