Conditionally Select Domain file text

Hi @all, Is there any way that i can trigger the desired text from domain file. I 've 2 text for template name service, I want to trigger the text on basis of condition is it possible? Thanks.

Not the way you think of. It wont be possible to select the right template from the domain-file, but you may write a custom actions, that adds the desired text to the dispatcher via ‘utter_message’-function for example. Technically you might get the right template from the domain instance, but you need a way to identify it.

In this case if there is a condition that determines which should be chosen, I’d recommend just giving the templates 2 different names and choosing that one based on the logic. The multiple templates are implemented only for variety’s sake, if the templates aren’t interchangeable then they shouldn’t be the same template.

If the reason you don’t want to go that route is because you don’t want to write more stories for those cases, then I would follow @IgNoRaNt23’s custom action route.

@erohmensing Can you please teach me how to get Rasa to choose a template based on logic? I have read the entire tutorial and I have read through all of the files in the example bots, but I don’t see how I can select a different template based on the value of a slot.

I’m trying to make a chatbot that works as a legal secretary and helps advise you about whether you have a strong lawsuit. I have two templates defined in nlu.md: utter_lawsuit_strong and utter_lawsuit_weak, with a few different suggestions for ways of letting the user know that the lawsuit is strong or weak, e.g., “You should definitely sue,” or “You would win your lawsuit,” or “Your lawsuit is very strong.” Those are all working fine.

I am also able to have the chatbot detect and extract information about entities that would be relevant to the strength of the lawsuit, e.g., if the user chooses the inform intent then maybe the user will pass information about who the defendant is, or how large the user’s damages are, and the chatbot is (usually) storing that information correctly.

If I wanted to, I could have the chatbot regurgitate the value of an entity, e.g., utter_damages that makes statements like “It sounds like your damages are {damages}.” That works fine.

What I can’t figure out how to do is to change whether the chatbot responds with utter_lawsuit_strong or utter_lawsuit_weak based on the value of the entities. I don’t want to just regurgitate a single entity; I want to have the chatbot choose one template over another template based on a logic model using all of the entities. For example, if the defendant is PepsiCo and the damages are high, then the chatbot should pick utter_lawsuit_strong, whereas if the defendant is Enron and the damages are low, then the chatbot should pick utter_lawsuit_weak.

How can I get the chatbot to pick a different template depending on what the value of the slots are?

I don’t want to use a Form or a custom action because I’m having enormous problems with the dependencies – I can’t install docker, I can’t install asyncio, I’m not running Haskell, and it’s all just more trouble than it’s worth to try to get that stuff running on my Windows 10 machine.

Thank you for any advice you can provide!

What I can’t figure out how to do is to change whether the chatbot responds with utter_lawsuit_strong or utter_lawsuit_weak based on the value of the entities. I don’t want to just regurgitate a single entity; I want to have the chatbot choose one template over another template based on a logic model using all of the entities.

Great intuition here :slight_smile:

You can do this with stories and featurized slots, i.e.

entities:
- company
- damage

slots:
  company:
    type: categorical 
    values:
      - PepsiCo
      - Enron
  damages:
    type: categorical 
    values: 
      - low
      - high 
## high damages, should sue
* inform{"damage": "high", "company": "Pepsico"}
  - slot{"damage": "high"}
  - slot{"company": "PepsiCo"}
  - utter_lawsuit_strong

## low damages, don't sue
* inform{"damage": "low", "company": "Enron"}
  - slot{"damage": "low"}
  - slot{"company": "Enron"}
  - utter_lawsuit_weak

I’m not sure what the logic looks like with regards to the combination or how the company one plays into that. I imagine you likely won’t want categorical slots for each one, because that won’t scale if you have a ton. e.g. if it depends on the size of the company, you could use synonyms to map the company to the size and have a company_size entity instead. Note that you then wouldn’t be able to use the value of the company name any more though.