rich kopelow
V.I.P
Posts: 47
Joined: Thu Aug 25, 2016 7:45 am

Load simlpkg into Oscova

Sat Mar 03, 2018 10:52 am

Is there a way to load a simlpkg file into Oscova? And if so would training happen "automatically" as a function of the load?
Otherwise what is the best practice for writing a general program that uses any one of a number of siml packages?

Thanks,
Rich.

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

Re: Load simlpkg into Oscova

Sat Mar 03, 2018 12:00 pm

Oscova's import function can take in SIML Modern Packages as I reckon that SimlPackage class represents IEnumerable<XDocument>. When you load an SIML Modern package Oscova parses the document and internally creates Dialogs and Intent structure. Training method has to be manually called after you are done loading Siml packages and dialogs. There are no limits in the number of SIML packages/documents you can import.

CSharp Code

var bot = new OscovaBot();

var simlPackage = SimlPackage.Load("PATH_TO_FILE");
bot.Import(simlPackage);

bot.Dialogs.Add(new SomeDialog());

bot.Trainer.StartTraining();

rich kopelow
V.I.P
Posts: 47
Joined: Thu Aug 25, 2016 7:45 am

Re: Load simlpkg into Oscova

Sat Mar 03, 2018 2:18 pm

Thanks for the quick and helpful response. That did that trick. I think I now just have one more problem. I get everything set up, but now I just can't get the response.
I'm using
EvaluationResult result = Bot.Evaluate((Request)req);
And have followed that up with a result.Invoke(); but I can't find the response text anywhere in result.

In the console example they just do the invoke() and that's that, which might be fine if you are calling actions, but doesn't help me.

Thanks,
Rich.

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

Re: Load simlpkg into Oscova

Sat Mar 03, 2018 3:31 pm

Response is received as part of the ResponseReceived event on BotUser instance. The reason why EvaluationResult doesn't have a response property is because the developer is left with the choice as to which intent to invoke. However, if you use the default Invoke on evaluation result it will invoke the suggested intent.

CSharp Code

bot.MainUser.ResponseReceived += (sender, eventArgs) =>
{
	var response = eventArgs.Response;
	var responseText = response.Text; //Response Text
	//Do Something with Response Text here.
};

var evaluationResult = bot.Evaluate("Some Message");
evaluationResult.Invoke(); //Invokes the suggested intent.


rich kopelow
V.I.P
Posts: 47
Joined: Thu Aug 25, 2016 7:45 am

Re: Load simlpkg into Oscova

Sat Mar 03, 2018 8:34 pm

Great. I'm working on a program that was originally built on classic SIML and I want to support modern so I'm building Oscova equivalents to my current functions. I have a chat method that processes a single interaction when given a request and "synchronously" returns a result. So I'm now looking at something like this... (not optimal structure, but functional for the moment)
public override string Chat(ChatRequest req)
{
bool responseReceived = false;
string responseText = "";
Request request = (Request)req;
EvaluationResult result = Bot.Evaluate(request);
(request).User.ResponseReceived += (sender, eventArgs) =>
{
var response = eventArgs.Response;
responseText = response.Text; //Response Text
responseReceived = true;
};
result.Invoke();
while (!responseReceived)
{
System.Threading.Thread.Sleep(100);
}
return responseText;
}
Note: the above code requires that I wipe the user out each interaction so as not to build up multiple event handlers.

Is Oscova as multi-threaded as the ResponseReceived event implies? I will probably make the leap and forget classic, but I'm wondering if I should really just throw a bunch of result invokes at it and then simply field the responses as they come in.

Thanks,
Rich.

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

Re: Load simlpkg into Oscova

Sun Mar 04, 2018 9:44 pm

It looks like you are converting SimlBot's ChatRequest to OscovaBot's Request?

Bot.Evaluate method has a string overload so you can directly submit the user message for evaluation. Also, the Chat method seems to be constantly adding an event handler on every chat request.

One should ensure that the ResponseReceived event is handled once for response generation, one way to do this is to use the OscovaBot.Users.UserAdded event.

Additionally, instead of putting the thread to sleep you may also try to lock the responseText variable during evaluation and set its value within the ResponseReceived event handler.

Responses generated by Oscova are directed to respective users that triggered an evaluation. So I assume for the moment Oscova should play nice in multi-threaded environment.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest