Custom action - Issue - "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."

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.

There’s probably an error occurring in your actions code. Can you post the log from your actions server?

Thanks Akshay for your response! The output log is this:

Rasa process starting Rasa process starting From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version. Instructions for updating: Use standard file APIs to check for files with this prefix. Restoring parameters from models/nlu/default/faq_bot/component_5_EmbeddingIntentClassifier.ckpt Generating grammar tables from /usr/lib/python3.6/lib2to3/Grammar.txt Generating grammar tables from /usr/lib/python3.6/lib2to3/PatternGrammar.txt Scheduler started From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/keras/backend.py:4010: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead. Rasa Core server is up and running on http://localhost:5005 Failed to run custom action ‘actions.GetAnswer’. 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 Encountered an exception while running action ‘actions.GetAnswer’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.

The core log is this:

Rasa process starting Rasa process starting Rasa process starting From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version. Instructions for updating: Use standard file APIs to check for files with this prefix. Restoring parameters from models/nlu/default/faq_bot/component_5_EmbeddingIntentClassifier.ckpt Generating grammar tables from /usr/lib/python3.6/lib2to3/Grammar.txt Generating grammar tables from /usr/lib/python3.6/lib2to3/PatternGrammar.txt Scheduler started From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/keras/backend.py:4010: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead. Rasa Core server is up and running on http://localhost:5005 Rasa process starting From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version. Instructions for updating: Use standard file APIs to check for files with this prefix. Restoring parameters from models/nlu/default/faq_bot/component_5_EmbeddingIntentClassifier.ckpt Generating grammar tables from /usr/lib/python3.6/lib2to3/Grammar.txt Generating grammar tables from /usr/lib/python3.6/lib2to3/PatternGrammar.txt Scheduler started From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/keras/backend.py:4010: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead. Rasa Core server is up and running on http://localhost:5005 Failed to run custom action ‘actions.GetAnswer’. 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 Encountered an exception while running action ‘actions.GetAnswer’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code. Rasa process starting From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/training/saver.py:1266: checkpoint_exists (from tensorflow.python.training.checkpoint_management) is deprecated and will be removed in a future version. Instructions for updating: Use standard file APIs to check for files with this prefix. Restoring parameters from models/nlu/default/faq_bot/component_5_EmbeddingIntentClassifier.ckpt Generating grammar tables from /usr/lib/python3.6/lib2to3/Grammar.txt Generating grammar tables from /usr/lib/python3.6/lib2to3/PatternGrammar.txt Scheduler started From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating: Colocations handled automatically by placer. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/keras/backend.py:4010: calling dropout (from tensorflow.python.ops.nn_ops) with keep_prob is deprecated and will be removed in a future version. Instructions for updating: Please use rate instead of keep_prob. Rate should be set to rate = 1 - keep_prob. From /home/jovyan/.rsm-msba/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version. Instructions for updating: Use tf.cast instead. Rasa Core server is up and running on http://localhost:5005 Failed to run custom action ‘actions.GetAnswer’. 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 Encountered an exception while running action ‘actions.GetAnswer’. Bot will continue, but the actions events are lost. Make sure to fix the exception in your custom code.

This is still the Rasa log. We need to look at the log of server that is running at localhost:5055. Can you show that please?

Thanks Akshay. This is what is displayed on the command line during the interaction. Is this what you’re asking? It says no registered action found…

@Juste, @akelad can you please help?

Yes, that’s what I was talking about. The error explains it.

No registered Action found for name ‘action_get_answer’.

Can you share the actions code? How are you starting the actions server?

I have pasted both the actions.py content and the command for triggering the server in the first content of this thread. Kindly have a look!

In the new two server model, you’re supposed to import Action class from rasa_core_sdk. That’s probably the reason your action is not registered.

1 Like

Yes you’re right! Thanks Akshay! :slight_smile:

You should be able to mark my answer as a solution by checking a box.

How do I do that? I don’t see a box!

@akshay2000 I have another doubt in my custom actions. Would be really great if you can give your inputs.

In my current custom actions file, I map the question and give out a answer from a csv file. Let’s say I want the bot to ask “Are you in category A or Category B”, and then according to which category it is, the bot should look into only 1-10 lines of CSV file for Category A and 10-20 rows for Category B. How do I implement this? And this should be followed for all questions from that specific user.

Question is not clear, but I am assuming that you want to know how to persist state between different messages throughout the session. Here’s how:

Declare a slot in your domain.yml called category. Also declare an entity with the same name.

slots:
    category:
        type: text

entities:
    - category

In your NLU examples, capture the entity. Slot value will be set since entity name matches the slot name.

## intent: inform_category
- I am in category [A](category)
- My category is [B](category)
- I am in [C](category) category

Now, in your action, you can access the slot value as follows:

category = tracker.get_slot("category")

You should be able to write remaining code from this.

1 Like

Thank you!

@akshay2000 i am facing same issue , but i can’t understand your answer …can u pls explain brief ,

Thanks in advance

The original question was vague to begin with. Please describe what your exact situation is. It will help me more detailed solution that I’ve already given.