Pre-process the intent before sending to LUIS - botframework

I am using LUISDialog to communicate with luis and added business logic for each intent. During actual conversation, LuisDialog sends the utterance directly to luis and returns the result to my method.
For a use case, I need to pre-process the utterance before the dialog sends it to LUIS. Is there a way to interrupt and add pre-processing logic?
Thanks for help.

You could override the GetLuisQueryTextAsync method, that is the method responsible from extracting the utterance out of the message.
The text obtained from that method is then being sent to Luis (as you can see here).

Related

Responsibility of Controller or Service?

I have a question about responsibility of Controller and service about a piece of my code. I have a HTML form to save an article which can submit three image(thumbnail, summary and body) with their text. The body text can contains some images in Base64 format. I get them by a post Action which accept a DTO object to support all inputs.
The Tasks I want to do are:
Get DTO from client
Fetch images from body
Check Summary and body text rules
Check Fetched images rules
Check Thumbnail, summary and body image rules
Save them
I have a service layer here which has some class about checking article texts and images logics.
My question is that how should I act here. Which steps are for Controller and which ones for Service.
Step 2 is most confusing step to me. Should I do it in controller or just pass all DTO to Service to separate things itself?
Or about checking text, should I check for example summary text length in controller or it should be check by Service layer?
Can any one explain these to me?
Possible duplicate.
The responsibility of the controller, is to accept a request, invoke the processing, and respond according to the result of the processing.
Try to look at the SOLID principles and always try to apply them.
So first of all, DTO, it depends on your architectural design, but I would say that the DTO is the abstraction that allows you to decouple you Domain Model from the client model.
The DTO should be seen as the data representation between two layers, if the DTO crosses more than one layer, it probably isn't a DTO but a business or data entity.
) Fetch images from body
this looks like something you designed to be able to receive the desired data, but is not something your domain model cares about.
For example if your form allow you to save "Sale advert", which is made of few images and some text, probably this aggregation of data in your business layer (service), is represented by one or more domain objects, so the fact that you receive a body in whichever format, depends more on technology or transport, and should be transparent to your business layer.
A good example to help you find boundaries, is thinking about re-usability. How would you reuse your service layer if you were to use it from a WCF service for example?
Your service should always receive and expose Domain Objects.
Leave to the consumer component the responsibility to decode/encode.
3) Check Summary and body text rules (and all other checks)
seems to be a validation, but I cannot tell if this validation is only related to the domain.
Some validation is also done in the controller itself to check if the request is valid or not.
So if this check is done on the DTO structure, before you try to convert it, probably that is a controller validation, if instead, this validation is necessary to decide weather or not the input can be saved, well probably in this case it would be considered other's responsibility.
You mentioned:
for example summary text length
if this is a business rule, then I would place it in a validation object, responsible to validate the "summary text" or let's call it again "Sale advert".
The responsibility to save a domain object to a data store, is normally delegated to a Data Access Layer, which is coupled to the database structure and provides the abstraction to the business layer.
This can be done implementing a repository pattern or maybe using an ORM, I normally don't add logic to persist data in the business layer.
Another note, here you are asking about controller responsibility, but pay attention to your service "layer", I have seen often code where a huge service class, was encapsulating all the business logic and validation, that is very bad because again goes against most of the solid principles.
Look at the command query and decorator pattern, I love them because the really help you breaking down your code in smaller pieces with single responsibility.
If interest look at this example project on github (.net core).
I am still working on the documentation but should be clear enough.

Why RecognizerResult doesn't contain the same JSON result from luis.ai

Why RecognizerResult doesn't contain the same json result from luis.ai
Here is the entities from RecognizerResult
and here is the result from luis.ai
This is an known issue right now if you choose to use the LuisRecognizer package. Essentially it "eats" important details of the raw LUIS response.
My professional recommendation would be to eschew LuisRecognizer and just use the full on LuisClient directly. The only real reason to use LuisRecognizer is if you want that extra level of abstraction that allows you to work with other recognizer implementations. If you're "all in" on LUIS, then you probably want access to the full fidelity of LUIS anyway.

LUIS Intent prediction

I'm having trouble with a LUIS Intent prediction. The utterance "consumo" should trigger the intent "1529_CONSULTAR_CONSUMO" but LUIS keeps assigning it to a wrong intent, even though the exact utterance is registered as an example to the right intent. How can I fix this situation?
The solution to this problems depends on your model. Because the intent that LUIS associates to one utterance and the score can be affected by any entity or any utterance added on any intent.
You can try :
- Look at the wrong intent "consumo" was associated to and if some utterances are similar to "consumo" maybe the two intents should be the same
- Create a list entity with "consumo" and other entities in the list

How to hook Luis into a Bot Framework FormDialog

I have a Dialog class which is a FormDialog (say, FormDialog< SandwichOrder>; one which builds an order for a sandwich, as per the bot framework documentation website). The SandwichOrder includes a "Price" property.
I also have a Dialog class which derives from LuisDialog which gets the price (based on, say, the size and/or province).
How can I hook Luis functionality into a Form Dialog?
Currently it is not possible to call a Dialog in a form field step. But you can have your custom implementation of IRecognize for a Field in the form (in this case "Price") and in the IEnumerable<TermMatch> Matches(string input, object defaultValue = null) implementation call into your Luis model and return all the possible TermMatches based on the detected entities by Luis.
This post: Custom fields with FormBuilder in the Microsoft Bot Framework appears to suggest an answer, and a way to implement your own custom field which implements IRecognizer. I haven't gotten it to work yet though.

Should a Model interact with external services?

Example 1:
A Model class "News" stores its text in two different languages (fields: en_text, jp_text). Usually it has text in only one language. Should I translate the text in callback before_save using the Google Translate API, or should I place this code in the Controller?
Example 2
A Model class "Payment". When the payment is going to be settled, the system must notify an external service about the successful settling of the payment. Where should this code be placed, Model or Controller?
The model is usually used to "get" or "set" data, so technically speaking, if your external service provides a service to "get" or "set" data, then yes.
Your Models should be literally the whole business logic of your application. Requirements for your Application mean that you should translate your text or notify some service on payment, don't they? That means that you should write it in your Model.
Controller is an entity that processes request parameters to some business logic actions. Controller should not contain such parts.
As I know, you are using Rails for now, so look at following links (this patterns are also helpful for non-Ruby programmers):
http://api.rubyonrails.org/classes/ActiveResource/Base.html
http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model - classics :)

Resources