I have an error when I try to run with actions. Please let me know what I’m missing. Here’s my code:
Configuration file:
configs = “”" language: en pipeline: tensorflow_embedding
“”"%store configs > config.yml
Domain file:
intents:
- greet
- goodbye
- need_help
- inform
templates: utter_greet: - ‘Hello! How can I help?’ utter_goodbye: - ‘Glad to help you! bye!’
actions:
- utter_greet
- utter_goodbye
- action_get_answer
Endpoints file:
action_endpoint: url: “http://localhost:5055/webhook” core_endpoint: url: “http://localhost:5005/”
Stories:
sample story
- greet
- utter_greet
- goodbye
- utter_goodbye
story_001
- greet
- utter_greet
- inform
- action_get_answer
NLU Train:
training_data = load_data(’./data/data.json’) trainer = Trainer(config.load(‘config.yml’)) trainer.train(training_data) model_directory = trainer.persist(’./models/nlu’, fixed_model_name = ‘faq_bot’)
actions.py:
from future import absolute_import from future import division from future import unicode_literals
from rasa_core.actions.action import Action from rasa_core.events import SlotSet
import pandas as pd from fuzzywuzzy import fuzz # visit GitHub - seatgeek/fuzzywuzzy: Fuzzy String Matching in Python for more details from fuzzywuzzy import process
class action_get_answer(Action): def init(self): self.faq_data = pd.read_csv(’./data/faq.csv’)
def name(self): return ‘action_get_answer’
def run(self, dispatcher, tracker, domain): query = tracker.latest_message questions = self.faq_data[‘question’].values.tolist()
mathed_question, score = process.extractOne(query['text'], questions, scorer=fuzz.token_set_ratio) # use process.extract(.. limits = 3) to get multiple close matches if score > 50: # arbitrarily chosen 50 to exclude matches not relevant to the query matched_row = self.faq_data.loc[self.faq_data['question'] == mathed_question,] answer = matched_row['answers'].values[0] response = "Here's something I found, \n\n Answer: {} \n".format(answer) else: response = "Sorry I couldn't find anything relevant to your query!" dispatcher.utter_message(response)
When I run this in one terminal:
python3 -m rasa_core_sdk.endpoint --actions actions
Output:
/home/jovyan/.rsm-msba/lib/python3.6/site-packages/fuzzywuzzy/fuzz.py:11: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning warnings.warn(‘Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning’) 2019-05-11 23:30:45 INFO main - Action endpoint is up and running. on (‘0.0.0.0’, 5055)
Dialogue Management code:
from future import absolute_import from future import division from future import unicode_literals
import logging
from rasa_core.agent import Agent from rasa_core.policies.keras_policy import KerasPolicy from rasa_core.policies.memoization import MemoizationPolicy
from rasa_core.featurizers import (MaxHistoryTrackerFeaturizer, BinarySingleStateFeaturizer)
if name == ‘main’: logging.basicConfig(level=‘INFO’)
training_data_file = './data/sample_stories.md' model_path = './models/dialogue' featurizer = MaxHistoryTrackerFeaturizer(BinarySingleStateFeaturizer(), max_history=2) agent = Agent('faq_domain.yml', policies = [MemoizationPolicy(max_history=2), KerasPolicy(featurizer)]) training_data = agent.load_data(training_data_file) agent.train(training_data) agent.persist(model_path)
When I run this:
python3 -m rasa_core.run -d models/dialogue -u models/nlu/default/faq_bot --endpoints endpoints.yml
Output:
Failed to run custom action ‘action_get_answer’. Action server responded with a non 200 status code of 500. Make sure your action server properly runs actions and returns a 200 once the action is executed. Error: 500 Server Error: INTERNAL SERVER ERROR for url: http://localhost:5055/webhook 2019-05-11 23:35:52 ERROR rasa_core.processor - Encountered an exception while running action ‘action_get_answer’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.