SangramMCP
Posts: 57
Joined: Wed Jul 26, 2017 7:41 pm

Prompt [SOLVED]

Thu Aug 03, 2017 5:22 pm

Hi,

I am not sure how prompt works. But while working on the same, I came across a scenario where I need to Validate user input. The prompt seems to be working for all in-build entities except Sys.Text. I am not sure about the usage.

Thanks,
Sangram

User avatar
Fantom
Help & Support
Posts: 320
Joined: Fri Oct 25, 2013 9:20 pm

Re: Prompt

Thu Aug 03, 2017 6:52 pm

Since you have posted this on Bug reports, could you please provide some sample code to reproduce the issue you are facing? For e.g. some intents or expression sequences.

SangramMCP
Posts: 57
Joined: Wed Jul 26, 2017 7:41 pm

Re: Prompt

Thu Aug 03, 2017 7:27 pm

[Expression("Hi @sys.text")]
[Entity(Sys.Text)]
[Prompt(Sys.Text, "Plz enter details")]

Even if i give 'Hi Sangram', the bot give a response like 'Plz enter details'

User avatar
Leslie
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Prompt

Thu Aug 03, 2017 9:39 pm

I believe it's more of an architectural behaviour than a bug. Prompting for @sys.text means that the engine must know what exactly will follow the word hi which in the above expression is not possible as @sys.text takes any arbitrary value. Only globally recognizable entities are to marked for prompting like @sys.number or @custom.emp.id and so and so forth.

Instead you should split the expression into 2 :

CSharp Code

[Expression("hi @sys.text")]
public void IntentOne(Context context, Result result)
{
	//Do something here
}

[Expression("hi")]
public void IntentTwo(Context context, Result result)
{
	//Do something here
}
Also the extra [Entity(Sys.Text)] in the expression:

]

CSharp Code

[Expression("Hi @sys.text")]
[Entity(Sys.Text)]
is unnecessary as you are not annotating anything with curly brackets { } in the expression. It would however make sense to specify the entity if your expression was something like the following.

]

CSharp Code

[Expression("Hi {Sangram}")]
[Entity(Sys.Text)]
For concrete domain specific bot it is highly recommended that you refrain from using @sys.text. Although it is very tempting, on a long run it would interfere heavily during training and intent scoring.

SangramMCP
Posts: 57
Joined: Wed Jul 26, 2017 7:41 pm

Re: Prompt

Fri Aug 04, 2017 1:14 am

Hi Leslie,
Thanks for the response.

But still I have a scenario like:

A user will key in:

Salary Slip details required for {Emp Name}
Salary Slip required for the {Month YY}

1. Now, in this case, we have two entities, and they are mandatory to be answered. How to go about in this case. I dont know, what is the empoyee id before hand. So i can't bound a value to it.

2. How can a conversation flow can be build for this kind of question? For Eg:
User: I need the salary slip.
Bot: Can you confirm your Emp Name (Reason for response: I have not provided Emp Name)
User: Sangram
Bot: For which month do you require the salary Slip
User: Mar 17
Bot: Thanks Sangram. Here is your salary slip for the month of March 17.
.
.
.
Here we are getting input from user in series of steps. in each steps,Step 1: Emp Name, Step 2: Salary slip for the month of March 17.
We are getting some entities and giving the final output.

How can we acheive this using Oscova.

Thanks,
Sangram

User avatar
Leslie
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Prompt

Fri Aug 04, 2017 2:16 am

Follow-up or slot fillings would make use of Oscova's context procedures. Below is a sample of how one would achieve what you've mentioned:

Just to add, our statistics showed that mostly January and February are shortened to Jan and Feb by most users. So Mar would be rendered invalid. Instead you would expect March as the general response. In case you really intend to add shortened words for months you could do that by provide synonyms for recognizer entries or creating custom filters.

Coming back to the scenario you've provide. Ensure that you add an employee name entity recognizer if possible. You can also avoid loading of all employee names by enumerating over database entries as shown in the NLI to Database sample in our GitHub repository.

CSharp Code

var empNameRecognizer = bot.CreateRecognizer("emp-name");
empNameRecognizer.Entries.Add("Sangram");
empNameRecognizer.Entries.Add("Maneesh");

CSharp Code

internal class Constants
{
	public const string EmpNameInput = "emp-name-input";
	public const string SlipDateProvider = "slip-date-provided";
}
internal class SalarySlipDialog : Dialog
{
	[Expression("I need the {salary slip}")]
	[Expression("Please give me my {salary slip}")]
	[Expression("Can you provide me my {salary slip}")]
	[Entity("slip")]
	public void NeedSalarySlip(Context context, Result result)
	{
		var response = new Response
		{
			Text = "Can you confirm your Emp Name",
			Hint = "Your Full Name" //Provide some hint in any GUI if applicable.
		};

		//Send response.
		result.SendResponse(response);

		//Add new context for follow-up intent.
		context.Add(Constants.EmpNameInput, 1);
	}

	[Expression("@emp-name")]
	[Context(Constants.EmpNameInput)]
	public void EmpNameProvided(Context context, Result result)
	{

		var response = new Response
		{
			Text = "For which month do you require the salary Slip",
			Hint = "Enter Month or Date" //Provide some hint in any GUI if applicable.
		};

		//Send response.
		result.SendResponse(response);

		//Remove this intent's context to avoid recall.
		context.Remove(Constants.EmpNameInput);

		//Collect Employee Name here.
		context.SharedEntities.Add(result.Entities.OfType("emp-name"));

		//Add new context for follow-up intent.
		context.Add(Constants.SlipDateProvider, 1);
	}

	[Expression("@sys.date.month:month")]
	[Context(Constants.SlipDateProvider)]
	public void SlipDate(Context content, Result result)
	{
		var date = result.Entities.OfType("month").ToString();
		var empName = content.SharedEntities.OfType("emp-name").ToString();
		result.SendResponse($"Thanks {empName}. Here is your salary slip for the month of {date}");
	}
}
The above is just my interpretation, your actual code would differ.

SangramMCP
Posts: 57
Joined: Wed Jul 26, 2017 7:41 pm

Re: Prompt

Fri Aug 04, 2017 7:17 pm

Thanks Lessie. Its working.

1 more question. Does Oscova development supports TDD(Test Driven Development). If Yes, Is there any sample application avaliable to demonstrate the same.

Thanks.

User avatar
Leslie
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Prompt

Sat Aug 05, 2017 9:56 am

Good to know it works, I just added that at the top of my head. However, there's one more change I would like to add. Ensure that you provide 1 as the context lifespan, this will make sure that the context doesn't live for more than 1 user request.

CSharp Code

[Context(Constants.EmpNameInput, 1)]

CSharp Code

[Context(Constants.SlipDateProvider, 1)]
TDD is something that has already been planned and is being worked upon. You can see that its already in the Road Map for Oscova. We will be getting this feature out once its been refined and polished enough for deployment.


Edit: Moved from Bug report to General Discussion by FranzZ

SangramMCP
Posts: 57
Joined: Wed Jul 26, 2017 7:41 pm

Re: Prompt

Tue Aug 08, 2017 8:34 pm

Hi Lessi,

I have 1 more query on that. I have created a class library project to initialize the Recognizers.

public class EmployeeModel
{
public void CreateEmployeeRecognizer(OscovaBot oscovaBot)
{
var empNameRecognizer = oscovaBot.CreateRecognizer("emp-name");
empNameRecognizer.Entries.Add("Sangram");
empNameRecognizer.Entries.Add("IbneM");
}
}

and, the same class I am referring while creating the instance of a new bot.

public void SetBotConfiguration(OscovaBot oscovaBot)
{

EmployeeModel employeeEntities = new EmployeeModel();
employeeEntities.CreateEmployeeRecognizer(oscovaBot);
}
There are no compile time errors. But in runtime it throws typeinitializationexception.

Can you help me with that.

Thanks,
Sangram

User avatar
Leslie
Lead Software Architect
Posts: 377
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Prompt

Tue Aug 08, 2017 9:02 pm

I reckon there's nothing wrong with the provided code. Just to be on the safe side I tried compiling the code on a sample project and it is working just fine.

Usually System.TypeInitializationException are caused by unhandled exceptions in constructor calls. Probably looking into related class constructors should help.

Return to “General Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 1 guest