I want to use knowledgebase action.
I got lists from json file but the error occur
which is
Traceback (most recent call last):
File "/home/seo/PycharmProjects/Rasabot/gpt-2/Chatbot/bot.py", line 25, in <module>
run_bot()
File "/home/seo/PycharmProjects/Rasabot/gpt-2/Chatbot/bot.py", line 19, in run_bot
agent.handle_channel(ConsoleInputChannel())
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/agent.py", line 122, in handle_channel
processor.handle_channel(input_channel)
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/processor.py", line 60, in handle_channel
input_channel.start_sync_listening(self.handle_message)
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/channels/console.py", line 52, in start_sync_listening
self._record_messages(message_handler)
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/channels/console.py", line 45, in _record_messages
self.sender_id))
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/processor.py", line 83, in handle_message
self._predict_and_execute_next_action(message, tracker)
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/processor.py", line 261, in _predict_and_execute_next_action
dispatcher)
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/processor.py", line 310, in _run_action
self._log_action_on_tracker(tracker, action.name(), events)
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/processor.py", line 367, in _log_action_on_tracker
tracker.update(e)
File "/home/seo/PycharmProjects/Rasabot/venv/lib/python3.7/site-packages/rasa_core/trackers.py", line 295, in update
raise ValueError("event to log must be an instance "
ValueError: event to log must be an instance of a subclass of Event.
Found the following objects of type 'movie':
1: Insidious
2: Interstella
3: About Time
4: Aladin
5: Frozen
Process finished with exit code 1
class ActionMyKB(ActionQueryKnowledgeBase):
def __init__(self):
# load knowledge base with data from the given file
knowledge_base = InMemoryKnowledgeBase("knowledge_base_data.json")
# overwrite the representation function of the hotel object
# by default the representation function is just the name of the object
# knowledge_base.set_representation_function_of_object(
# "movie", lambda obj: obj["name"] + " (" + obj["city"] + ")"
# )
super().__init__(knowledge_base)
def name(self) -> Text:
return "action_query_knowledge_base"
def run(
self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> List[Dict[Text, Any]]:
"""
Executes this action. If the user ask a question about an attribute,
the knowledge base is queried for that attribute. Otherwise, if no
attribute was detected in the request or the user is talking about a new
object type, multiple objects of the requested type are returned from the
knowledge base.
Args:
dispatcher: the dispatcher
tracker: the tracker
domain: the domain
Returns: list of slots
"""
object_type = tracker.get_slot(SLOT_OBJECT_TYPE)
last_object_type = tracker.get_slot(SLOT_LAST_OBJECT_TYPE)
attribute = tracker.get_slot(SLOT_ATTRIBUTE)
new_request = object_type != last_object_type
if not object_type:
# object type always needs to be set as this is needed to query the
# knowledge base
dispatcher.utter_message(template="utter_ask_rephrase")
return []
if not attribute or new_request:
return self._query_objects(dispatcher, tracker)
elif attribute:
return self._query_attribute(dispatcher, tracker)
dispatcher.utter_message(template="utter_ask_rephrase")
return []
I run rasa with pycharm.
Can you tell me the result of debug mode briefly?
And how can i run action server?
I started to use rasa recently so please understand
Thanks
How do you run your bot in pycharm? Do you use rasa/rasa/__main__.py as script path? If so you can simply add --debug to the parameters to run Rasa in debug mode. Take a look at the Command Line Interface for all available options.
In order to run the knowledge base action you have to start an action server, see Rasa SDK. The knowledge base action is a custom action, Rasa cannot execute it unless you start the action server.
The action itself looks fine. Seems like you did not anything from the default action. Is that correct?
I run rasa using rasa nlu and rasa core seperately . I knew my way was old version.
I saw rasa tutorial and trying to run rasa with terminal. But rasa run action command returns this
OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 5055): address already in use
Anyway I think I have to learn more about how to use rasa commands and action server first.
And then use the knowledge base action. I really appreciate your comments.
I saw rasa tutorial and trying to run rasa with terminal. But rasa run action command returns this OSError: [Errno 98] error while attempting to bind on address ('0.0.0.0', 5055): address already in use
The error tells you that there is already a server running on port 5055. What commands are you executing?
I thought custom action needs def run part, so I defined my action like that(default).
Yes, but your custom actions inherits from ActionQueryKnowledgeBase which already implements the run method. So, if you don’t want to modify it, you don’t have to define it in your custom action.