Rasa NLG Server

I am making a project in which I want to implement custom NLG for the chatbot. I have found the code on the rasa github for nlg_server.py and have got it to run in command line, receiving post requests from a python script I worked up for testing. How do I get rasa core to communicate with this NLG server to receive user inputs and respond back with a custom generated response. I have found nothing in the documentation indicating the implementation of this besides adding it to the endpoints.yml file of the project.

You would create one or more custom actions (fallback action could be a catchall depending on your use case). The custom actions call the NLG and then utter_message.

1 Like

custom action calling the NLG would just be using the requests library to send a post request to the NLG server? or is in done through specifying the NLG used as a parameter within the run() method of the Action like so

 | async run(output_channel: "OutputChannel", nlg: "NaturalLanguageGenerator", tracker: "DialogueStateTracker", domain: "Domain") -> List[Event]
1 Like

Sorry, I gave you incorrect info on NLG. To point Rasa at your NLG, you configure this in the endpoints.yml as shown here.

nlg:
  url: http://localhost:5055/nlg
1 Like

So beyond that, there should be no further set up? apart from of course, implementing your own response generation, as I have implemented that into my endpoints.yml file, but from what I can tell it yielded no results.

Have you tested your endpoint with curl or postman? Does your endpoint calls from Rasa? What does the debug output from Rasa show both at startup and at points in the conversation when the NLG should be called?

From my testing, when I run the nlg_server.py file, the server is running and sending requests from postman appears to work, currently getting an attribute error with the requests I am sending however.

in running rasa shell --debug the only reference I see to rasa.core.nlg is this…

2022-03-04 09:55:45 DEBUG rasa.core.nlg.generator - Instantiated NLG to ‘TemplatedNaturalLanguageGenerator’.

and there is nothing within debug referring to nlg after inputting a message to the bot

I am confused at the stage of calling NLG, is this something done by the framework from it being tied to an endpoint or something I should be implementing into the custom action calls which I am writing?

Rasa should call your nlg when the dialogue predicts an utterance.

- rule:
  steps:
  - intent: greet
  - action: utter_greet

When the call to utter_greet in this story is predicted, we should see the debug output in rasa shell -debug calling your NLG and you should add log messages or run in a debugger to confirm it’s being called.

Show the debug output when an utterance is run.

Hi,

Apologies for a late reply, I have produced the debug output as you explained and got this below

2022-03-08 10:18:18 DEBUG rasa.core.lock_store - Issuing ticket for conversation ‘148e3342808442118b6eca0aea6234e0’. 2022-03-08 10:18:18 DEBUG rasa.core.lock_store - Acquiring lock for conversation ‘148e3342808442118b6eca0aea6234e0’. 2022-03-08 10:18:18 DEBUG rasa.core.lock_store - Acquired lock for conversation ‘148e3342808442118b6eca0aea6234e0’. 2022-03-08 10:18:18 DEBUG rasa.core.tracker_store - Could not find tracker for conversation ID ‘148e3342808442118b6eca0aea6234e0’. 2022-03-08 10:18:18 DEBUG rasa.core.processor - Starting a new session for conversation ID ‘148e3342808442118b6eca0aea6234e0’. 2022-03-08 10:18:18 DEBUG rasa.core.processor - Policy prediction ended with events ‘[]’. 2022-03-08 10:18:18 DEBUG rasa.core.processor - Action ‘action_session_start’ ended with events ‘[<rasa.shared.core.events.SessionStarted obj ect at 0x00000214E3EA1130>, ActionExecuted(action: action_listen, policy: None, confidence: None)]’. 2022-03-08 10:18:18 DEBUG rasa.core.processor - Current slot values: module: None session_started_metadata: None 2022-03-08 10:18:18 DEBUG rasa.core.processor - Received user message ‘hello’ with intent ‘{‘name’: ‘greet’, ‘confidence’: 0.4546232573913670 5}’ and entities ‘[{‘value’: ‘neu’, ‘confidence’: 1.0, ‘entity’: ‘sentiment’, ‘extractor’: ‘sentiment_extractor’}]’ 2022-03-08 10:18:18 DEBUG rasa.core.processor - Current slot values: module: None session_started_metadata: None 2022-03-08 10:18:18 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 4 events. 2022-03-08 10:18:18 DEBUG rasa.core.policies.memoization - Current tracker state: [state 1] user intent: greet | user entities: (‘sentiment’,) | previous action name: action_listen 2022-03-08 10:18:18 DEBUG rasa.core.policies.memoization - There is no memorised next action 2022-03-08 10:18:18 DEBUG rasa.core.policies.rule_policy - Current tracker state: [state 1] user text: hello | previous action name: action_listen 2022-03-08 10:18:18 DEBUG rasa.core.policies.rule_policy - There is no applicable rule. 2022-03-08 10:18:18 DEBUG rasa.core.policies.rule_policy - Current tracker state: [state 1] user intent: greet | user entities: (‘sentiment’,) | previous action name: action_listen 2022-03-08 10:18:18 DEBUG rasa.core.policies.rule_policy - There is no applicable rule. 2022-03-08 10:18:19 DEBUG rasa.core.policies.unexpected_intent_policy - Querying for intent greet. 2022-03-08 10:18:19 DEBUG rasa.core.policies.unexpected_intent_policy - Score for intent greet is 1.8118122816085815, while threshold is -1.3990422487258911. 2022-03-08 10:18:19 DEBUG rasa.core.policies.unexpected_intent_policy - Top 5 intents (in ascending order) that are likely here are: [('expl ain_feeling', -1.48593), ('give_time', 1.3062135), ('ask_help', 1.3728172), ('greet', 1.8118123), ('mood_unhappy', 2.0791276)]. 2022-03-08 10:18:19 DEBUG rasa.core.policies.ted_policy - TED predicted ‘utter_greet’ based on user intent. 2022-03-08 10:18:19 DEBUG rasa.core.policies.ensemble - Made prediction using user intent. 2022-03-08 10:18:19 DEBUG rasa.core.policies.ensemble - Added DefinePrevUserUtteredFeaturization(False) event. 2022-03-08 10:18:19 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_3_TEDPolicy. 2022-03-08 10:18:19 DEBUG rasa.core.processor - Predicted next action ‘utter_greet’ with confidence 0.99. 2022-03-08 10:18:19 DEBUG rasa.core.processor - Policy prediction ended with events ‘[<rasa.shared.core.events.DefinePrevUserUtteredFeaturiza tion object at 0x00000214E3EA4C40>]’. 2022-03-08 10:18:19 DEBUG rasa.core.processor - Action ‘utter_greet’ ended with events ‘[BotUttered(‘Hey!’, {“elements”: null, "quick_replies ": null, “buttons”: null, “attachment”: null, “image”: null, “custom”: null}, {“utter_action”: “utter_greet”}, 1646734699.2455828)]’. 2022-03-08 10:18:19 DEBUG rasa.core.policies.memoization - Current tracker state: [state 1] user intent: greet | user entities: (‘sentiment’,) | previous action name: action_listen [state 2] user intent: greet | user entities: (‘sentiment’,) | previous action name: utter_greet 2022-03-08 10:18:19 DEBUG rasa.core.policies.memoization - There is no memorised next action 2022-03-08 10:18:19 DEBUG rasa.core.policies.rule_policy - Current tracker state: [state 1] user intent: greet | user entities: (‘sentiment’,) | previous action name: action_listen [state 2] user intent: greet | user entities: (‘sentiment’,) | previous action name: utter_greet 2022-03-08 10:18:19 DEBUG rasa.core.policies.rule_policy - There is no applicable rule. 2022-03-08 10:18:19 DEBUG rasa.core.policies.unexpected_intent_policy - Skipping predictions for UnexpecTEDIntentPolicy as either there is no event of type UserUttered or there is an event of type ActionExecuted after the last UserUttered. 2022-03-08 10:18:19 DEBUG rasa.core.policies.ted_policy - TED predicted ‘action_listen’ based on user intent. 2022-03-08 10:18:19 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_3_TEDPolicy. 2022-03-08 10:18:19 DEBUG rasa.core.processor - Predicted next action ‘action_listen’ with confidence 1.00. 2022-03-08 10:18:19 DEBUG rasa.core.processor - Policy prediction ended with events ‘[]’. 2022-03-08 10:18:19 DEBUG rasa.core.processor - Action ‘action_listen’ ended with events ‘[]’. 2022-03-08 10:18:19 DEBUG rasa.core.lock_store - Deleted lock for conversation ‘148e3342808442118b6eca0aea6234e0’.

For nlg server on which route should it be listening for that post request?

localhost:5055/ or localhost:5055/nlg ?